$linuxjunkies
>

compaction

also: memory compaction, page compaction

A memory management process that reduces fragmentation by moving allocated memory pages together, freeing up contiguous free space for large allocations.

Compaction is a kernel memory management technique that addresses external fragmentation—the problem where free memory is scattered across the system in small, non-contiguous chunks, making it impossible to allocate large contiguous blocks even when total free memory is sufficient.

The kernel's compaction mechanism works by migrating allocated pages to create larger contiguous regions of free memory. This is particularly important for systems using hugetlbfs (huge pages) or when the kernel needs to allocate large contiguous buffers for hardware DMA operations.

You can observe and trigger compaction through /proc/sys/vm/compact_memory. Writing 1 to this file triggers a compaction pass across all zones:

echo 1 > /proc/sys/vm/compact_memory

Unlike garbage collection in user-space programs, kernel compaction happens transparently during page allocation failures or can be manually invoked, making it essential for system stability on long-running machines with fragmented memory.

Related terms