Skip to content

RFC mm/page_alloc: keep non-movable pages out of movable pageblocks for THP

Rik van Riel linux-mm lkml llvm oe-kbuild-all stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest5 patches 12 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5mm/page_alloc: count guard pages as free again when their buddy mergesmm/page_alloc.c+4 -23 replies
2/5mm/page_alloc: count a merged buddy's pages under the merged typemm/page_alloc.c+5 -05 replies
3/5mm/page_alloc: convert any movable pageblock on a non-movable allocationinclude/linux/mmzone.h mm/page_alloc.c+46 -384 replies
4/5mm/page_alloc: skip movable blocks during non-movable stealsmm/page_alloc.c+17 -20 replies
5/5mm/page_alloc: claim blocks captured for non-movable usemm/page_alloc.c+16 -00 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchDev JainJohannes WeinerZi Yan
1/5R-b R-b R-b
2/5
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [RFC PATCH 0/5] mm/page_alloc: keep non-movable pages out of movable pageblocks for THP

Last week I posted the first prototype of the reworked gigablock page allocation code, which uses the per-migrate_type free lists in the zone as its fast path:

https://lore.kernel.org/lkml/20261004013657.03a63c4c@fangorn/

Zi Yan took a look, and pointed out that the first patches in the series might help with THP allocation. Testing showed he is right.

Having this code be useful by itself changes the gigablock merge plan. It can now be done in stages:
1) Pageblock claiming fixes & improvements, which show a modest improvement in THP allocation. This is the only code in the fast path.
2) Page compaction, evacuation, and free list threshold changes, which can really help concentrate non-movable allocations in non-movable typed pageblocks, hopefully making compaction and THP allocation noticeably more reliable.
3) The actual gigablock targeting. This is also a slow path, like compaction and evacuation.

This first series addresses pageblock claiming and stealing policies. Current page allocation policies cause the THP allocation success rate to collapse under sustained non-movable demand.

A single non-movable page in a movable-type page block prevents that page block from being used for a THP, but it does not prevent kcompactd from spending time on that block.

Three paths mix unmovable pages into movable-typed blocks. try_to_claim_block() converts a movable block for a non-movable allocation only when half its pages are free or compatible. __rmqueue_steal() takes pages without converting at all, and a bulk batch that steals once never reaches the claim path again.

compaction_capture() hands a merged movable block to a non-movable request with no type change.

Patches 1-2 are standalone accounting fixes: guard pages return to the counts when their buddy merges, and a merged buddy's pages move to the merged type in the free page accounting.

Patches 3-5 make the pageblock migrate type follow the content:
convert any movable block on a non-movable claim, skip movable blocks on non-movable steals, and claim movable blocks fully taken by non-movable compaction capture.

Pageblocks that straddle zones cannot safely change type, since the allocator may have locked the "wrong" zone. Those blocks are left alone.

The series is preventive: it keeps new placements to their own type and stops polluting movable block. The next step, for another series, will be to evacuate movable content from pageblocks stolen by non-movable allocations, in order to concentrate kernel allocations in fewer pageblocks.

Measured on 64GB 8-vCPU KVM guests, THP=always, defrag=always, khugepaged collapse off, 8GB virtio swap. The guest boots into a fragmented base: a 10GB mlocked block flood, 36GB of aged anonymous memory, and background unmovable allocations.

Then 8 rounds of type-pressure buildup. Each round drains high-order free memory with a large NOHUGEPAGE touch, adds 550 pagetable-heavy processes plus 200000 slab files as unmovable demand, and ends with a fixed 2GB 8-thread THP probe that stays mapped while success is measured. The bursts persist across rounds while the drain shrinks by ~2.75GB each round, so each round's demand faces less free memory.

Measured is the thp_fault_alloc success rate, across 4 runs of 8 rounds each.

patched base
rounds with <50% success 7/31 16/31
THP alloc success rate @r4 74% (47-98) 42% (25-67)
blocks with unmovable pages @r8 43-154 1674-2131

Two rounds died due to swap exhaustion, and are not counted.

Pageblocks with unmovable pages were counted by checking /proc/kpageflags after each round. The total amount of unmovable pages is similar with and without the series, they just get packed into fewer pageblocks.

Converting taken blocks and refusing fallback steals packs unmovable pages into converted blocks, leaving clean movable victims for the scanners: a round-2 probe on the series kernel compacts 690 of 697 attempts at 92.6% THP where the base compacts 47 of 376 at 4.7%.

This series is broken out of the 1GB gigablock prototype work:

 include/linux/mmzone.h |  13 +++++
 mm/page_alloc.c        | 117 +++++++++++++++++++++++++++++++------------------
 2 files changed, 88 insertions(+), 42 deletions(-)

base-commit: 67f0943b394d9