Skip to contentSkip to conversation

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

RFC PATCH In review Rik van Riel 5 participants 20 messages Oct 7 – Oct 15

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover 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

#1 lore raw

RFC PATCH 1/5 mm/page_alloc: count guard pages as free again when their buddy merges

With debug_guardpage_minorder set, expand() turns the unused halves of a split into guard pages, which page_del_and_expand() leaves out of the free counts. Freeing the allocated half credits only that half, and __free_one_page() then merges the guard buddy with clear_page_guard(), which no longer touches the counters.

The merged block goes on a free list with the guard pages never counted, so NR_FREE_PAGES falls behind the free lists by every guard that merges. Before commit e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting"), __set_page_guard() and __clear_page_guard() adjusted the counts themselves; that commit dropped both adjustments but kept the subtraction implicit in expand().

Count the guard pages under the merged block's migratetype when the buddy is cleared. account_freepages() skips an isolated block as it does for every other free page, and moving the block off the isolated list counts it then.

Booting a 16GB VM with debug_pagealloc=on debug_guardpage_minorder=1, check the difference in free pages reported between /proc/vmstat and /proc/buddyinfo.

At three points (idle, after a read and file-creation load, after a second load), check the difference between nr_free_pages and the buddyinfo numbers in the normal zone, as a number of pages:

idle after load after second load
unpatched -130 79205 99121
patched -16 45 0

The small remaining difference seems to be due to the numbers not being read at exactly the same time, and is also seen without guard pages.

Fixes e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting")
Assisted-by LLM
---
 mm/page_alloc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +4 -2
index 12fac9084c483..4658af97be010 100644
@@ -988,10 +988,12 @@ static inline void __free_one_page(struct page *page,
 		 * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page,
 		 * merge with it and move up one order.
 		 */
-		if (page_is_guard(buddy))
+		if (page_is_guard(buddy)) {
 			clear_page_guard(zone, buddy, order);
-		else
+			account_freepages(zone, 1 << order, migratetype);
+		} else {
 			__del_page_from_free_list(buddy, zone, order, buddy_mt);
+		}
 
 		if (unlikely(buddy_mt != migratetype)) {
 			/*
Signature · 1 line
2.53.0-Meta
Reviewed-by on v1 1/5
#2 lore raw

Re: [RFC PATCH 1/5] mm/page_alloc: count guard pages as free again when their buddy merges

Quoted 34 lines · Rik van Riel

With debug_guardpage_minorder set, expand() turns the unused halves of a split into guard pages, which page_del_and_expand() leaves out of the free counts. Freeing the allocated half credits only that half, and __free_one_page() then merges the guard buddy with clear_page_guard(), which no longer touches the counters.

The merged block goes on a free list with the guard pages never counted, so NR_FREE_PAGES falls behind the free lists by every guard that merges. Before commit e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting"), __set_page_guard() and __clear_page_guard() adjusted the counts themselves; that commit dropped both adjustments but kept the subtraction implicit in expand().

Count the guard pages under the merged block's migratetype when the buddy is cleared. account_freepages() skips an isolated block as it does for every other free page, and moving the block off the isolated list counts it then.

Booting a 16GB VM with debug_pagealloc=on debug_guardpage_minorder=1, check the difference in free pages reported between /proc/vmstat and /proc/buddyinfo.

At three points (idle, after a read and file-creation load, after a second load), check the difference between nr_free_pages and the buddyinfo numbers in the normal zone, as a number of pages:

idle after load after second load
unpatched -130 79205 99121
patched -16 45 0

The small remaining difference seems to be due to the numbers not being read at exactly the same time, and is also seen without guard pages.

Quoted 5 lines
Fixes e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting")
Assisted-by LLM

---

LGTM

Probably send this separately? RFC on a fix will delay the patch.

Quoted 22 lines
 mm/page_alloc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +4 -2
index 12fac9084c483..4658af97be010 100644
@@ -988,10 +988,12 @@ static inline void __free_one_page(struct page *page,
 		 * Our buddy is free or it is CONFIG_DEBUG_PAGEALLOC guard page,
 		 * merge with it and move up one order.
 		 */
-		if (page_is_guard(buddy))
+		if (page_is_guard(buddy)) {
 			clear_page_guard(zone, buddy, order);
-		else
+			account_freepages(zone, 1 << order, migratetype);
+		} else {
 			__del_page_from_free_list(buddy, zone, order, buddy_mt);
+		}
 
 		if (unlikely(buddy_mt != migratetype)) {
 			/*
reviewer Reviewed-by on v1 1/5
#3 lore raw

Re: [RFC PATCH 1/5] mm/page_alloc: count guard pages as free again when their buddy merges

In reply to Rik van Riel
Quoted 30 lines · Rik van Riel

With debug_guardpage_minorder set, expand() turns the unused halves of a split into guard pages, which page_del_and_expand() leaves out of the free counts. Freeing the allocated half credits only that half, and __free_one_page() then merges the guard buddy with clear_page_guard(), which no longer touches the counters.

The merged block goes on a free list with the guard pages never counted, so NR_FREE_PAGES falls behind the free lists by every guard that merges. Before commit e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting"), __set_page_guard() and __clear_page_guard() adjusted the counts themselves; that commit dropped both adjustments but kept the subtraction implicit in expand().

Count the guard pages under the merged block's migratetype when the buddy is cleared. account_freepages() skips an isolated block as it does for every other free page, and moving the block off the isolated list counts it then.

Booting a 16GB VM with debug_pagealloc=on debug_guardpage_minorder=1, check the difference in free pages reported between /proc/vmstat and /proc/buddyinfo.

At three points (idle, after a read and file-creation load, after a second load), check the difference between nr_free_pages and the buddyinfo numbers in the normal zone, as a number of pages:

idle after load after second load
unpatched -130 79205 99121
patched -16 45 0

Quoted 8 lines

The small remaining difference seems to be due to the numbers not being read at exactly the same time, and is also seen without guard pages.

Fixes e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting")
Assisted-by LLM

This should probably be not RFC?

reviewer Reviewed-by on v1 1/5
#4 lore raw

Re: [RFC PATCH 1/5] mm/page_alloc: count guard pages as free again when their buddy merges

In reply to Rik van Riel
Quoted 34 lines · Rik van Riel

With debug_guardpage_minorder set, expand() turns the unused halves of a split into guard pages, which page_del_and_expand() leaves out of the free counts. Freeing the allocated half credits only that half, and __free_one_page() then merges the guard buddy with clear_page_guard(), which no longer touches the counters.

The merged block goes on a free list with the guard pages never counted, so NR_FREE_PAGES falls behind the free lists by every guard that merges. Before commit e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting"), __set_page_guard() and __clear_page_guard() adjusted the counts themselves; that commit dropped both adjustments but kept the subtraction implicit in expand().

Count the guard pages under the merged block's migratetype when the buddy is cleared. account_freepages() skips an isolated block as it does for every other free page, and moving the block off the isolated list counts it then.

Booting a 16GB VM with debug_pagealloc=on debug_guardpage_minorder=1, check the difference in free pages reported between /proc/vmstat and /proc/buddyinfo.

At three points (idle, after a read and file-creation load, after a second load), check the difference between nr_free_pages and the buddyinfo numbers in the normal zone, as a number of pages:

idle after load after second load
unpatched -130 79205 99121
patched -16 45 0

The small remaining difference seems to be due to the numbers not being read at exactly the same time, and is also seen without guard pages.

Quoted 8 lines
Fixes e0932b6c1f94 ("mm: page_alloc: consolidate free page accounting")
Assisted-by LLM
---
 mm/page_alloc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Good catch.

Best Regards,
Yan, Zi

#5 lore raw

RFC PATCH 2/5 mm/page_alloc: count a merged buddy's pages under the merged type

In reply to Rik van Riel

__free_one_page() merges a freed page with a free buddy of another mergeable type at pageblock order and above, and retypes the buddy to match. The buddy's pages stay counted under the old type: nothing moves them to the merged type in the free counts.

That is unobservable today. NR_FREE_PAGES does not separate types, so the missing move nets to zero there. Any future per-type free count would undercount on a merge from the other side, and allocating the merged run later could wrap it.

Move the buddy's pages to the merged type in the count too.

Assisted-by LLM
---
 mm/page_alloc.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/page_alloc.c +5 -0
index 4658af97be010..ae38e25971559 100644
@@ -993,6 +993,11 @@ static inline void __free_one_page(struct page *page,
 			account_freepages(zone, 1 << order, migratetype);
 		} else {
 			__del_page_from_free_list(buddy, zone, order, buddy_mt);
+			/* The buddy's free pages join the merged block's type. */
+			if (unlikely(buddy_mt != migratetype)) {
+				account_freepages(zone, -(1 << order), buddy_mt);
+				account_freepages(zone, 1 << order, migratetype);
+			}
 		}
 
 		if (unlikely(buddy_mt != migratetype)) {
Signature · 1 line
2.53.0-Meta
#6 lore raw

Re: [RFC PATCH 2/5] mm/page_alloc: count a merged buddy's pages under the merged type

Quoted 23 lines · Rik van Riel

__free_one_page() merges a freed page with a free buddy of another mergeable type at pageblock order and above, and retypes the buddy to match. The buddy's pages stay counted under the old type: nothing moves them to the merged type in the free counts.

That is unobservable today. NR_FREE_PAGES does not separate types, so the missing move nets to zero there. Any future per-type free count would undercount on a merge from the other side, and allocating the merged run later could wrap it.

Move the buddy's pages to the merged type in the count too.

Assisted-by LLM
---
 mm/page_alloc.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/page_alloc.c +0 -0
index 4658af97be010..ae38e25971559 100644

mm/page_alloc.c static inline void __free_one_page(struct page *page, · line 1002

Quoted 10 lines
mm/page_alloc.c +5 -0
@@ -993,6 +993,11 @@ static inline void __free_one_page(struct page *page,
 			account_freepages(zone, 1 << order, migratetype);
 		} else {
 			__del_page_from_free_list(buddy, zone, order, buddy_mt);
+			/* The buddy's free pages join the merged block's type. */
+			if (unlikely(buddy_mt != migratetype)) {
+				account_freepages(zone, -(1 << order), buddy_mt);
+				account_freepages(zone, 1 << order, migratetype);
+			}
 		}
 

MAX_PAGE_ORDER > pageblock_order confuses things so much : (

Sashiko raises something:
https://sashiko.dev/#/patchset/20261007021250.1665929-1-riel%40surriel.com

Although feels like it is exaggerating.

My concern is for systems with a high diff between MAX_PAGE_ORDER and pageblock_order. So on arm64 systems with 64K pagesize but pageblock size as 2M (and PMD size 512M), the pageblock order is 5. We use this configuration to reliably get TLB optimization from contpte size mappings.

Will we then repeatedly overflow the pcpu counter into the zone counter, regressing stuff?

Perhaps I am overthinking. Your approach is clean, but perhaps we could also do:

void account_freepages_move(zone, order, buddy_mt, mt)

	/* PCP-types do not have per-migratetype free counts. */
	if (likely (buddy_mt < MIGRATE_PCPTYPES && mt < MIGRATE_PCPTYPES))
		return;

account_freepages(zone, -(1 << order), buddy_mt);
account_freepages(zone, 1 << order, migratetype);

Quoted 1 line
mm/page_alloc.c +0 -0
 		if (unlikely(buddy_mt != migratetype)) {
#7 lore raw

Re: [RFC PATCH 2/5] mm/page_alloc: count a merged buddy's pages under the merged type

Quoted 14 lines · Dev Jain
Quoted 14 lines

+++ b/mm/page_alloc.c

(quoted diff) +1 -0
@@ -993,6 +993,11 @@ static inline void __free_one_page(struct page
 *page,
  			account_freepages(zone, 1 << order,
 migratetype);
  		} else {
  			__del_page_from_free_list(buddy, zone,
 order, buddy_mt);
+			/* The buddy's free pages join the merged

block's type. */

(quoted diff) +2 -0
+			if (unlikely(buddy_mt != migratetype)) {
+				account_freepages(zone, -(1 <<
Quoted 8 lines
Quoted 6 lines

order), buddy_mt);

(quoted diff) +1 -0
+				account_freepages(zone, 1 <<

order, migratetype);

mm/page_alloc.c +1 -0
+			}

  }

MAX_PAGE_ORDER > pageblock_order confuses things so much : (

I'm not a fan, either. It trips me up every time.

Quoted 5 lines

Sashiko raises something:
https://sashiko.dev/#/patchset/20261007021250.1665929-1-riel%40surriel.com

Although feels like it is exaggerating.

I suppose if we switch the two lines around, doing the increment on migratetype before decrementing buddy_mt we could avoid that transient underflow?

Quoted 10 lines

My concern is for systems with a high diff between MAX_PAGE_ORDER and pageblock_order. So on arm64 systems with 64K pagesize but pageblock size as 2M (and PMD size 512M), the pageblock order is 5. We use this configuration to reliably get TLB optimization from contpte size mappings.

Will we then repeatedly overflow the pcpu counter into the zone counter,
regressing stuff?

The per_cpu_pages struct does not seem to keep counts on a per migratetype basis at all. It has per migratetype lists, but only one pcp->count.

Also doesn't the pcp only carry order zero pages currently?

I don't really understand your worry.

Quoted 11 lines

Perhaps I am overthinking. Your approach is clean, but perhaps we could
also do:

void account_freepages_move(zone, order, buddy_mt, mt)

	/* PCP-types do not have per-migratetype free counts. */
	if (likely (buddy_mt < MIGRATE_PCPTYPES && mt <
MIGRATE_PCPTYPES))
		return;

Wouldn't that throw off the counts when we merge e.g. a MIGRATE_UNMOVABLE page with a MIGRATE_MOVABLE buddy?

With your test we would only ever do the free count adjustment for mismatched types if one of the pages was HIGHATOMIC or CMA. That leaves the common case without coverage.

Signature · 1 line
All Rights Reversed.
#8 lore raw

Re: [RFC PATCH 2/5] mm/page_alloc: count a merged buddy's pages under the merged type

Quoted 27 lines · Rik van Riel
Quoted 14 lines · Dev Jain
Quoted 14 lines

+++ b/mm/page_alloc.c

(quoted diff) +1 -0
@@ -993,6 +993,11 @@ static inline void __free_one_page(struct page
 *page,
  			account_freepages(zone, 1 << order,
 migratetype);
  		} else {
  			__del_page_from_free_list(buddy, zone,
 order, buddy_mt);
+			/* The buddy's free pages join the merged

block's type. */

(quoted diff) +2 -0
+			if (unlikely(buddy_mt != migratetype)) {
+				account_freepages(zone, -(1 <<
Quoted 8 lines
Quoted 6 lines

order), buddy_mt);

(quoted diff) +1 -0
+				account_freepages(zone, 1 <<

order, migratetype);

mm/page_alloc.c +1 -0
+			}

  }

MAX_PAGE_ORDER > pageblock_order confuses things so much : (

I'm not a fan, either. It trips me up every time.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Sashiko raises something:
https://sashiko.dev/#/patchset/20261007021250.1665929-1-riel%40surriel.com

Although feels like it is exaggerating.

I suppose if we switch the two lines around, doing the increment on migratetype before decrementing buddy_mt we could avoid that transient underflow?

That would become a transient overflow. See below.

Quoted 17 lines
Quoted 11 lines

My concern is for systems with a high diff between MAX_PAGE_ORDER and pageblock_order. So on arm64 systems with 64K pagesize but pageblock size as 2M (and PMD size 512M), the pageblock order is 5. We use this configuration to reliably get TLB optimization from contpte size mappings.

Will we then repeatedly overflow the pcpu counter into the zone counter,
regressing stuff?

The per_cpu_pages struct does not seem to keep counts on a per migratetype basis at all. It has per migratetype lists, but only one pcp->count.

Quoted 4 lines

Also doesn't the pcp only carry order zero pages currently?

I don't really understand your worry.

Sorry I was not talking about the pcp list (also, pcp carries order 0 till 3?)

In __mod_zone_page_state, we use the per-cpu variable pcp->vm_stat_diff, and when it overflows or underflows past a pcp->stat_threshold, we push the diff to the global (zone) state.

The reason we do so is to optimize by batching zone operations into per-cpu local operations.

My concern is that for large delta, we will always overflow or underflow, defeating the purpose of the per-cpu caching.

So on said arm64 systems, we may frequently enter your

if (unlikely(buddy_mt != migratetype)

branch, and if pcp->stat_threshold is not enough, we may repeatedly overflow and underflow, defeating this per-cpu optimization.

Quoted 8 lines
Quoted 8 lines

Perhaps I am overthinking. Your approach is clean, but perhaps we could
also do:

void account_freepages_move(zone, order, buddy_mt, mt)

Quoted 9 lines
Quoted 4 lines
	/* PCP-types do not have per-migratetype free counts. */
	if (likely (buddy_mt < MIGRATE_PCPTYPES && mt <
MIGRATE_PCPTYPES))
		return;

Wouldn't that throw off the counts when we merge e.g. a MIGRATE_UNMOVABLE page with a MIGRATE_MOVABLE buddy?

As you said, in account_freepages(), there is currently no conditional based on MOVABLE and UNMOVABLE. So we are essentially doing -x and +x, netting to zero.

So we could write my function, make it clear that currently this is not needed for the MIGRATE_PCPTYPES, as opposed to MIGRATE_CMA and MIGRATE_HIGHATOMIC which have separate accounting.

Quoted 5 lines

With your test we would only ever do the free count adjustment for mismatched types if one of the pages was HIGHATOMIC or CMA. That leaves the common case without coverage.

#9 lore raw

Re: [RFC PATCH 2/5] mm/page_alloc: count a merged buddy's pages under the merged type

Quoted 4 lines · Dev Jain

As you said, in account_freepages(), there is currently no conditional based on MOVABLE and UNMOVABLE. So we are essentially doing -x and +x, netting to zero.

Lets defer this change until later.

During a later stage of the gigablock code, I
do need to track each zone's free pages by
migratetype, but it's not needed yet.

Signature · 1 line
All Rights Reversed.
#10 lore raw

Re: [RFC PATCH 2/5] mm/page_alloc: count a merged buddy's pages under the merged type

In reply to Rik van Riel
Quoted 23 lines · Rik van Riel

__free_one_page() merges a freed page with a free buddy of another mergeable type at pageblock order and above, and retypes the buddy to match. The buddy's pages stay counted under the old type: nothing moves them to the merged type in the free counts.

That is unobservable today. NR_FREE_PAGES does not separate types, so the missing move nets to zero there. Any future per-type free count would undercount on a merge from the other side, and allocating the merged run later could wrap it.

Move the buddy's pages to the merged type in the count too.

Assisted-by LLM
---
 mm/page_alloc.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/page_alloc.c +0 -0
index 4658af97be010..ae38e25971559 100644

mm/page_alloc.c static inline void __free_one_page(struct page *page, · line 999

Quoted 7 lines
mm/page_alloc.c +4 -0
@@ -993,6 +993,11 @@ static inline void __free_one_page(struct page *page,
 			account_freepages(zone, 1 << order, migratetype);
 		} else {
 			__del_page_from_free_list(buddy, zone, order, buddy_mt);
+			/* The buddy's free pages join the merged block's type. */
+			if (unlikely(buddy_mt != migratetype)) {
+				account_freepages(zone, -(1 << order), buddy_mt);
+				account_freepages(zone, 1 << order, migratetype);

Reasonable on one hand, but I think at that point it would be simpler and more robust to drop that 'single account_freepages() + __add/__del operations' optimization, and just use the accounting add/del variants directly instead.

#11 lore raw

RFC PATCH 3/5 mm/page_alloc: convert any movable pageblock on a non-movable allocation

In reply to Rik van Riel

try_to_claim_block() converts a movable pageblock for a non-movable allocation only when half its pages are free or compatible. Otherwise the steal path takes pages without converting, and non-movable content sits in a block still typed movable.

Convert a movable block on any non-movable claim, however few of its pages are free, so the block's type matches the allocation it serves.

When other pages in the block are freed later, they end up on the non-movable free lists, directing more non-movable allocations to the already non-movable page blocks.

Converting a non-movable pageblock to movable is made stricter:
a movable claim takes a non-movable block only when every page is free or movable.

Blocks straddling a zone edge are never claimed; zone_spans_pageblock() tests for a block wholly inside its zone.

Assisted-by LLM
---
 include/linux/mmzone.h | 13 ++++++++
 mm/page_alloc.c        | 71 ++++++++++++++++++++----------------------
 2 files changed, 46 insertions(+), 38 deletions(-)
include/linux/mmzone.h +13 -0
index 94f9c3ff54160..81ad83ff69073 100644
@@ -1227,6 +1227,19 @@ static inline bool zone_spans_pfn(const struct zone *zone, unsigned long pfn)
 	return zone->zone_start_pfn <= pfn && pfn < zone_end_pfn(zone);
 }
 
+/*
+ * Whether the pageblock holding @pfn lies wholly inside @zone. Zone
+ * spans are not pageblock-aligned, so the edge pageblocks of a zone
+ * can straddle into the next zone; those never change type.
+ */
+static inline bool zone_spans_pageblock(const struct zone *zone, unsigned long pfn)
+{
+	unsigned long start = pageblock_start_pfn(pfn);
+
+	return zone->zone_start_pfn <= start &&
+	       start + pageblock_nr_pages <= zone_end_pfn(zone);
+}
+
 static inline bool zone_is_initialized(const struct zone *zone)
 {
 	return zone->initialized;
mm/page_alloc.c +33 -38

90 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
#12 lore raw

Re: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation

kernel test robot noticed the following build errors:

Hi Rik,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on 67f0943b394d920b6c142aad8c6af94340342ae7]

url:    https://github.com/intel-lab-lkp/linux/commits/Rik-van-Riel/mm-page_alloc-count-guard-pages-as-free-again-when-their-buddy-merges/20261006-221246
base:   67f0943b394d920b6c142aad8c6af94340342ae7
patch link:    https://lore.kernel.org/r/20261007021250.1665929-4-riel%40surriel.com
patch subject: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation
config: riscv-allyesconfig (https://download.01.org/0day-ci/archive/20261010/[email protected]/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 51b433b4f56c531c0d95ba15e1a15e06c399d552)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261010/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from arch/riscv/kernel/asm-offsets.c:9:
In file included from include/linux/mm.h:8:
In file included from include/linux/gfp.h:7:

>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'PMD_SHIFT'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'PMD_SHIFT'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'PMD_SHIFT'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'PMD_SHIFT'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'PMD_SHIFT'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'PMD_SHIFT'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
   include/linux/mmzone.h:1240:17: error: use of undeclared identifier 'PMD_SHIFT'
    1240 |                start + pageblock_nr_pages <= zone_end_pfn(zone);
         |                        ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:8:
   In file included from include/linux/gfp.h:7:
   include/linux/mmzone.h:1240:17: error: use of undeclared identifier 'PMD_SHIFT'
    1240 |                start + pageblock_nr_pages <= zone_end_pfn(zone);
         |                        ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:60:46: note: expanded from macro 'pageblock_order'
      60 | #define pageblock_order         MIN_T(unsigned int, HUGETLB_PAGE_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~~~~
   arch/riscv/include/asm/page.h:20:34: note: expanded from macro 'HUGETLB_PAGE_ORDER'
      20 | #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
         |                                  ^~~~~~~~~~~
   arch/riscv/include/asm/page.h:17:22: note: expanded from macro 'HPAGE_SHIFT'
      17 | #define HPAGE_SHIFT             PMD_SHIFT
         |                                 ^~~~~~~~~
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:36:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:98:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
      98 |                 return (set->sig[3] | set->sig[2] |
         |                         ^        ~
   include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
      62 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:36:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:98:25: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
      98 |                 return (set->sig[3] | set->sig[2] |
         |                                       ^        ~
   include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
      62 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:36:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:99:4: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
      99 |                         set->sig[1] | set->sig[0]) == 0;
         |                         ^        ~
   include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
      62 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/riscv/kernel/asm-offsets.c:9:
   In file included from include/linux/mm.h:36:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:101:11: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
     101 |                 return (set->sig[1] | set->sig[0]) == 0;
         |                         ^        ~
   include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
      62 |         unsigned long sig[_NSIG_WORDS];
         |         ^

In file included from arch/riscv/kernel/asm-offsets.c:9:
In file included from include/linux/mm.h:36:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:114:11: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
114 | return (set1->sig[3] == set2->sig[3]) &&
| ^ ~

vim +/PMD_SHIFT +1237 include/linux/mmzone.h

1229
1230 /*
1231 * Whether the pageblock holding @pfn lies wholly inside @zone. Zone
1232 * spans are not pageblock-aligned, so the edge pageblocks of a zone
1233 * can straddle into the next zone; those never change type.
1234 */
1235 static inline bool zone_spans_pageblock(const struct zone *zone, unsigned long pfn)
1236 {

> 1237		unsigned long start = pageblock_start_pfn(pfn);

1238
1239 return zone->zone_start_pfn <= start &&
1240 start + pageblock_nr_pages <= zone_end_pfn(zone);
1241 }
1242

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#13 lore raw

Re: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation

In reply to Rik van Riel
kernel test robot noticed the following build errors:

Hi Rik,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on 67f0943b394d920b6c142aad8c6af94340342ae7]

url:    https://github.com/intel-lab-lkp/linux/commits/Rik-van-Riel/mm-page_alloc-count-guard-pages-as-free-again-when-their-buddy-merges/20261006-221246
base:   67f0943b394d920b6c142aad8c6af94340342ae7
patch link:    https://lore.kernel.org/r/20261007021250.1665929-4-riel%40surriel.com
patch subject: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation
config: x86_64-randconfig-1006-20261010 (https://download.01.org/0day-ci/archive/20261011/[email protected]/config)
compiler: clang version 22.1.3 (https://github.com/llvm/llvm-project e9846648fd6183ee6d8cbdb4502213fcf902a211)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261011/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from arch/x86/kernel/asm-offsets.c:9:
In file included from include/linux/crypto.h:18:
In file included from include/linux/slab.h:17:
In file included from include/linux/gfp.h:7:

>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
>> include/linux/mmzone.h:1237:24: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1237 |         unsigned long start = pageblock_start_pfn(pfn);
         |                               ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:78:52: note: expanded from macro 'pageblock_start_pfn'
      78 | #define pageblock_start_pfn(pfn)        ALIGN_DOWN((pfn), pageblock_nr_pages)
         |                                                           ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
   include/linux/mmzone.h:1240:17: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1240 |                start + pageblock_nr_pages <= zone_end_pfn(zone);
         |                        ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:9:
   In file included from include/linux/crypto.h:18:
   In file included from include/linux/slab.h:17:
   In file included from include/linux/gfp.h:7:
   include/linux/mmzone.h:1240:17: error: use of undeclared identifier 'HPAGE_PMD_ORDER'
    1240 |                start + pageblock_nr_pages <= zone_end_pfn(zone);
         |                        ^~~~~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:75:36: note: expanded from macro 'pageblock_nr_pages'
      75 | #define pageblock_nr_pages      (1UL << pageblock_order)
         |                                         ^~~~~~~~~~~~~~~
   include/linux/pageblock-flags.h:66:46: note: expanded from macro 'pageblock_order'
      66 | #define pageblock_order         MIN_T(unsigned int, HPAGE_PMD_ORDER, PAGE_BLOCK_MAX_ORDER)
         |                                                     ^~~~~~~~~~~~~~~
   In file included from arch/x86/kernel/asm-offsets.c:10:
   In file included from include/crypto/aria.h:22:
   In file included from include/linux/module.h:20:
   In file included from include/linux/elf.h:6:
   In file included from arch/x86/include/asm/elf.h:10:
   In file included from arch/x86/include/asm/ia32.h:7:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:5:
   In file included from include/linux/fs/super.h:5:
   In file included from include/linux/fs/super_types.h:13:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:98:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
      98 |                 return (set->sig[3] | set->sig[2] |
         |                         ^        ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/x86/kernel/asm-offsets.c:10:
   In file included from include/crypto/aria.h:22:
   In file included from include/linux/module.h:20:
   In file included from include/linux/elf.h:6:
   In file included from arch/x86/include/asm/elf.h:10:
   In file included from arch/x86/include/asm/ia32.h:7:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:5:
   In file included from include/linux/fs/super.h:5:
   In file included from include/linux/fs/super_types.h:13:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:98:25: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
      98 |                 return (set->sig[3] | set->sig[2] |
         |                                       ^        ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   In file included from arch/x86/kernel/asm-offsets.c:10:
   In file included from include/crypto/aria.h:22:
   In file included from include/linux/module.h:20:
   In file included from include/linux/elf.h:6:
   In file included from arch/x86/include/asm/elf.h:10:
   In file included from arch/x86/include/asm/ia32.h:7:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:5:
   In file included from include/linux/fs/super.h:5:
   In file included from include/linux/fs/super_types.h:13:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:99:4: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
      99 |                         set->sig[1] | set->sig[0]) == 0;
         |                         ^        ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^

In file included from arch/x86/kernel/asm-offsets.c:10:
In file included from include/crypto/aria.h:22:
In file included from include/linux/module.h:20:
In file included from include/linux/elf.h:6:
In file included from arch/x86/include/asm/elf.h:10:
In file included from arch/x86/include/asm/ia32.h:7:

vim +/HPAGE_PMD_ORDER +1237 include/linux/mmzone.h

1229
1230 /*
1231 * Whether the pageblock holding @pfn lies wholly inside @zone. Zone
1232 * spans are not pageblock-aligned, so the edge pageblocks of a zone
1233 * can straddle into the next zone; those never change type.
1234 */
1235 static inline bool zone_spans_pageblock(const struct zone *zone, unsigned long pfn)
1236 {

> 1237		unsigned long start = pageblock_start_pfn(pfn);

1238
1239 return zone->zone_start_pfn <= start &&
1240 start + pageblock_nr_pages <= zone_end_pfn(zone);
1241 }
1242

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#14 lore raw

Re: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation

In reply to Rik van Riel
Quoted 17 lines · Rik van Riel

try_to_claim_block() converts a movable pageblock for a non-movable allocation only when half its pages are free or compatible. Otherwise the steal path takes pages without converting, and non-movable content sits in a block still typed movable.

Convert a movable block on any non-movable claim, however few of its pages are free, so the block's type matches the allocation it serves.

When other pages in the block are freed later, they end up on the non-movable free lists, directing more non-movable allocations to the already non-movable page blocks.

Converting a non-movable pageblock to movable is made stricter:
a movable claim takes a non-movable block only when every page is free or movable.

Quoted 5 lines

Blocks straddling a zone edge are never claimed; zone_spans_pageblock() tests for a block wholly inside its zone.

Assisted-by LLM

I like this in theory, but wonder how this behaves in practice.

The block is claimed, but the movable constituents aren't proactively kicked out. The next unmovable request might well claim another mostly movable block, and so forth. With a flurry of short-lived unmovable allocations, this might explode the unmovable blocks, which will be hard to recover especially when you raise the bar on *that* direction.

#15 lore raw

Re: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation

Quoted 21 lines · Johannes Weiner
Quoted 20 lines · Rik van Riel

try_to_claim_block() converts a movable pageblock for a non-movable allocation only when half its pages are free or compatible. Otherwise the steal path takes pages without converting, and non-movable content sits in a block still typed movable.

Convert a movable block on any non-movable claim, however few of its pages are free, so the block's type matches the allocation it serves.

When other pages in the block are freed later, they end up on the non-movable free lists, directing more non-movable allocations to the already non-movable page blocks.

Converting a non-movable pageblock to movable is made stricter:
a movable claim takes a non-movable block only when every page is free or movable.

Blocks straddling a zone edge are never claimed; zone_spans_pageblock() tests for a block wholly inside its zone.

Quoted 7 lines
Quoted 2 lines
Assisted-by LLM

I like this in theory, but wonder how this behaves in practice.

The block is claimed, but the movable constituents aren't proactively kicked out.

I have code for that, too, but it seems like
it's a lot easier to get things reviewed in
small portions.

If you want I can resend this as a larger
series, with:
1) the pageblock claiming
2) per migrate type free lists
3) evacuation of movable pages from unmovable
pageblocks, when the kernel free lists fall
below a watermark

That would be the full extent of the 2MB granularity fragmentation avoidance stuff I have here.

Just let me know your preference.

Signature · 1 line
All Rights Reversed.
#16 lore raw

Re: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation

Quoted 42 lines · Rik van Riel
Quoted 21 lines · Johannes Weiner
Quoted 20 lines · Rik van Riel

try_to_claim_block() converts a movable pageblock for a non-movable allocation only when half its pages are free or compatible. Otherwise the steal path takes pages without converting, and non-movable content sits in a block still typed movable.

Convert a movable block on any non-movable claim, however few of its pages are free, so the block's type matches the allocation it serves.

When other pages in the block are freed later, they end up on the non-movable free lists, directing more non-movable allocations to the already non-movable page blocks.

Converting a non-movable pageblock to movable is made stricter:
a movable claim takes a non-movable block only when every page is free or movable.

Blocks straddling a zone edge are never claimed; zone_spans_pageblock() tests for a block wholly inside its zone.

Quoted 7 lines
Quoted 2 lines
Assisted-by LLM

I like this in theory, but wonder how this behaves in practice.

The block is claimed, but the movable constituents aren't proactively kicked out.

I have code for that, too, but it seems like
it's a lot easier to get things reviewed in
small portions.

If you want I can resend this as a larger
series, with:
1) the pageblock claiming
2) per migrate type free lists
3) evacuation of movable pages from unmovable
pageblocks, when the kernel free lists fall
below a watermark

Quoted 2 lines

That would be the full extent of the 2MB granularity fragmentation avoidance stuff I have here.

I think your patch series applied as-is would regress stuff:
we may have lots of UNMOVABLE pageblocks with lots of movable allocations, unable to be rescued, hurting mTHP allocations.

Quoted 3 lines

Just let me know your preference.

#17 lore raw

Re: [RFC PATCH 3/5] mm/page_alloc: convert any movable pageblock on a non-movable allocation

Quoted 14 lines · Dev Jain
Quoted 14 lines

I have code for that, too, but it seems like
it's a lot easier to get things reviewed in
small portions.

If you want I can resend this as a larger
series, with:
1) the pageblock claiming
2) per migrate type free lists
3) evacuation of movable pages from unmovable
   pageblocks, when the kernel free lists fall
   below a watermark

Quoted 7 lines
Quoted 2 lines

That would be the full extent of the 2MB granularity fragmentation avoidance stuff I have here.

I think your patch series applied as-is would regress stuff:
we may have lots of UNMOVABLE pageblocks with lots of movable allocations, unable to be rescued, hurting mTHP allocations.

How should we move forward with this?

Do do guys want to review this series first, and then I post an update with the other stuff, before any gets merged?

Or do you want me to post a larger series all at once?

Before I move on, do the combined policy changes from patches 3, 4, and 5 make sense to you (with or without evacuation) ?

Patch 1 from this series can be merged all by itself as a separate thing.

Signature · 1 line
All Rights Reversed.
#18 lore raw

RFC PATCH 4/5 mm/page_alloc: skip movable blocks during non-movable steals

In reply to Rik van Riel

__rmqueue_steal() hands a non-movable allocation pages from a movable pageblock and leaves the block's type alone. Those pages can never migrate, so the block reads movable to compaction while holding content compaction cannot move. On a 3 GB guest running ls -lR / and a 2.4 GB block device read against a fragmenter, a temporary counter found 2654, 5341 and 5272 such allocations in three boots.

__rmqueue_claim() runs first and would convert the block, but rmqueue_bulk() remembers the mode across its batch. Prevent those allocations from placing non-movable pages inside movable pageblocks by refusing __rmqueue_steal() for non-movable allocations in movable pageblocks.

Movable is last in fallbacks[] for both non-movable types, so only a larger order is left to try; failing that, the steal returns NULL and the allocation will loop around to a claim, another zone, or reclaim.

Keep the steal where mobility grouping is disabled, or where the block straddles a zone edge. A block that straddles zones cannot be claimed, because the allocator only holds the lock for one zone, which leaves stealing as the alloc path there.

Movable allocations can steal, because kcompactd can always move those pages out of non-movable blocks later.

Over three boots allocstall_normal runs 48 to 129 against 32 to 134 on the base, and compact_stall 324 to 415 against 288 to 387. Neither direct reclaim nor compaction stalls rise beyond run-to-run spread.

Assisted-by LLM
---
 mm/page_alloc.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
mm/page_alloc.c +17 -2
index 9f1520506ae1d..16d3594d913a0 100644
@@ -2423,8 +2423,10 @@ __rmqueue_claim(struct zone *zone, int order, int start_migratetype,
 }
 
 /*
- * Try to steal a single page from some fallback migratetype. Leave the rest of
- * the block as its current migratetype, potentially causing fragmentation.
+ * Try to steal one page from a fallback type, leaving the rest of the block
+ * unchanged and possibly fragmented. A non-movable allocation must not steal
+ * from a movable block: without converting its type, the steal would leave
+ * non-movable content under a movable type.
  */
 static __always_inline struct page *
 __rmqueue_steal(struct zone *zone, int order, int start_migratetype)
@@ -2444,6 +2446,19 @@ __rmqueue_steal(struct zone *zone, int order, int start_migratetype)
 			continue;
 
 		page = get_page_from_free_area(area, fallback_mt);
+
+		/*
+		 * Do not allow non-movable allocations in movable
+		 * pageblocks; that could break compaction.
+		 * Non-movable allocations should claim pageblocks, instead.
+		 */
+		if (!is_migrate_movable(start_migratetype) &&
+		    is_migrate_movable(fallback_mt) &&
+		    !page_group_by_mobility_disabled &&
+		    zone_spans_pageblock(zone, page_to_pfn(page))) {
+			continue;
+		}
+
 		page_del_and_expand(zone, page, order, current_order, fallback_mt);
 		trace_mm_page_alloc_extfrag(page, order, current_order,
 					    start_migratetype, fallback_mt);
Signature · 1 line
2.53.0-Meta
#19 lore raw

RFC PATCH 5/5 mm/page_alloc: claim blocks captured for non-movable use

In reply to Rik van Riel

compaction_capture() hands any merged block to the compacting task with no type change, except it refuses a movable block to a non-movable request below pageblock order. A non-movable request capturing a whole movable block leaves non-movable content in a movable-typed block.

Make a non-movable capture claim a movable block: convert it to the request. A partial block cannot be retyped, so the refusal below pageblock order stays; reaching the conversion means a whole block. A movable capture steals: it takes the pages and leaves the type alone.

Assisted-by LLM
---
 mm/page_alloc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
mm/page_alloc.c +16 -0
index 16d3594d913a0..edb69d8a74c73 100644
@@ -728,6 +728,9 @@ static inline struct capture_control *task_capc(struct zone *zone)
 		capc->zone == zone ? capc : NULL;
 }
 
+static void change_pageblock_range(struct page *pageblock_page,
+				   int start_order, int migratetype);
+
 static inline bool
 compaction_capture(struct capture_control *capc, struct page *page,
 		   int order, int migratetype)
@@ -751,6 +754,19 @@ compaction_capture(struct capture_control *capc, struct page *page,
 	    capc->migratetype != MIGRATE_MOVABLE)
 		return false;
 
+	/*
+	 * A non-movable capture claims a movable block: convert it to
+	 * the request. A movable capture steals: take the pages and
+	 * leave the type alone. Partial movable blocks returned above,
+	 * so reaching here means a whole block.
+	 */
+	if (capc->migratetype != MIGRATE_MOVABLE &&
+	    migratetype == MIGRATE_MOVABLE) {
+		change_pageblock_range(page, order, capc->migratetype);
+		/* Converted whole, so no fragmentation to report below. */
+		migratetype = capc->migratetype;
+	}
+
 	if (migratetype != capc->migratetype)
 		trace_mm_page_alloc_extfrag(page, capc->order, order,
 					    capc->migratetype, migratetype);
Signature · 1 line
2.53.0-Meta