This LWN article about memory compaction indicates that memory compaction can be invoked in the linux kernel by

Writing a node number to /proc/sys/vm/compact_node, causing compaction to happen on the indicated NUMA node.

When should I write the node number to the sys entry? I mean what should I detect or read and then write the node to the sys entry? What should be my criteria and how should I measure that criteria before writing to the sys entry?

(…) The other is for the system to fail in an attempt to allocate a higher-order page; in this case, compaction will run as a preferable alternative to freeing pages through direct reclaim. In the absence of an explicit trigger, the compaction algorithm will stay idle; there is a cost to moving pages around which is best avoided if it is not needed.

What is meant by allowing the system to fail? Fail in what way? How can I detect that failure ? By failure does it mean simple request for allocating a higher order page, which was denied ? In this case is the compaction algorithm run automatically, by itself?

My requirement: I'd like to trigger memory compaction by getting an idea of system state and memory fragmentation on the system. And I'd like to know for sure that compaction will help before actually running it.

1 Answer 1


Most of the time the kernel internal memory allocations are less than a page in size, or can happily be contiguous only in virtual memory, not in real memory. What the paper says is that in case a higher order page allocation fails (i.e., the kernel asks for several pages contiguous in real memory) the compaction is triggered automatically. This is rather unusual, so it shouldn't happen often.

Unless you have a need for the kernel having contiguous pages available, and measurements show that this is performance critical (or at least relevant) for yout workload, better leave the fingers off.

  • please check my questions in bold in the original post. Thanks. Mar 6, 2013 at 19:09
  • 1
    Unless you know for a fact that kernel internal memory fragmentation is a performance problem (very unlikely), and find out a way of knowing if there is fragmentation (I know of none), triggering compaction willy-nilly will be a performance drain.
    – vonbrand
    Mar 6, 2013 at 19:37
  • 2
    you can check /proc/buddyinfo to find the current level of fragmentation. Mar 6, 2013 at 20:12
  • 1
    in fact, comparing performance at high memory fragmentation to performance after triggering memory compaction can give you a hint on whether memory fragmentation affects your performance or not Aug 20, 2014 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .