Dig down memory compaction subsystem
Figure 1: Imagine a very small memory zone which looks like this
Figure 2: This code runs as two separate algorithms; the first of them starts at the bottom of the zone and builds a list of allocated pages which could be move
Figure 3: at the top of the zone, the other half of the algorithm is creating a list of free pages which could be used as the target of page migration
Figure 4: Eventually the two algorithms will meet somewhere toward the middle of the zone.
At that point, it’s mostly just a matter of invoking the “page migration code” (which is not just for NUMA systems anymore)
to shift the used pages to the free space at the top of the zone, yielding a pretty picture like this