Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
@ 2026-11-29 14:23 Qi Wu
  2026-11-30 15:56 ` Harry Yoo
  2026-12-03  8:34 ` Dev Jain
  0 siblings, 2 replies; 9+ messages in thread
From: Qi Wu @ 2026-11-29 14:23 UTC (permalink / raw)
  To: Vlastimil Babka, Johannes Weiner, Andrew Morton
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
	Mel Gorman, linux-mm

compaction_capture() filters CMA and isolated pages but not
MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
nr_free_highatomic watermark accounting: a plain blocking allocation
can consume a page reserved for atomic allocations. HIGHATOMIC pages
reach the hook through PCP drains, which re-read the pageblock type
before calling __free_one_page().

The gap has existed since capture was introduced; commit 7e8756d7ad22
("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
widened it by sending non-movable order-0 allocations through direct
compaction when defrag_mode is enabled.

Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
and the allocation falls back to get_page_from_freelist(), where the
reserve checks apply.

Found and drafted with AI assistance (Qoder); build-tested only.

Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
Cc: stable@vger.kernel.org
Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
---
 mm/page_alloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2fef4092c913..4443d715df2d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -735,6 +735,10 @@ compaction_capture(struct capture_control *capc, struct page *page,
 	    is_migrate_isolate(migratetype))
 		return false;
 
+	/* HIGHATOMIC pages are reserved for atomic allocations. */
+	if (migratetype == MIGRATE_HIGHATOMIC)
+		return false;
+
 	/*
 	 * Do not let lower order allocations pollute a movable pageblock
 	 * unless compaction is also requesting movable pages.

base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8

Notes (not part of the commit log):
- Checked against akpm mm-unstable (890dc639d8a3): compaction_capture()
  is identical there. The in-flight freetype_t rework and the
  "claim blocks captured for non-movable use" RFC touch this function
  but are not queued yet, so this applies cleanly to both trees.
- The hit rate of this path can be observed with the
  mm_page_alloc_extfrag tracepoint (fallbackmt=HIGHATOMIC).
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-11-29 14:23 [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages Qi Wu
@ 2026-11-30 15:56 ` Harry Yoo
  2026-12-02  6:08   ` Qi Wu
  2026-12-03  8:34 ` Dev Jain
  1 sibling, 1 reply; 9+ messages in thread
From: Harry Yoo @ 2026-11-30 15:56 UTC (permalink / raw)
  To: Qi Wu
  Cc: Vlastimil Babka, Johannes Weiner, Andrew Morton,
	Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
	Mel Gorman, linux-mm

On Sun, Nov 29, 2026 at 10:23:50PM +0800, Qi Wu wrote:
> compaction_capture() filters CMA and isolated pages but not
> MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
> escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
> nr_free_highatomic watermark accounting: a plain blocking allocation
> can consume a page reserved for atomic allocations. HIGHATOMIC pages
> reach the hook through PCP drains, which re-read the pageblock type
> before calling __free_one_page().
> 
> The gap has existed since capture was introduced; commit 7e8756d7ad22
> ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
> widened it by sending non-movable order-0 allocations through direct
> compaction when defrag_mode is enabled.
> 
> Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
> and the allocation falls back to get_page_from_freelist(), where the
> reserve checks apply.
> 
> Found and drafted with AI assistance (Qoder); build-tested only.

The idea of this patch makes sense to me, but would you please at least
try to reproduce the problem before claiming it _fixes_ the problem :)

> Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
> Cc: stable@vger.kernel.org

... especially when backporting a patch to -stable.

> Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
> ---
>  mm/page_alloc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 2fef4092c913..4443d715df2d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -735,6 +735,10 @@ compaction_capture(struct capture_control *capc, struct page *page,
>  	    is_migrate_isolate(migratetype))
>  		return false;
>
> +	/* HIGHATOMIC pages are reserved for atomic allocations. */
> +	if (migratetype == MIGRATE_HIGHATOMIC)
> +		return false;
> +
>  	/*
>  	 * Do not let lower order allocations pollute a movable pageblock
>  	 * unless compaction is also requesting movable pages.
> 
> base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8
> 
> Notes (not part of the commit log):
> - Checked against akpm mm-unstable (890dc639d8a3): compaction_capture()
>   is identical there. The in-flight freetype_t rework and the
>   "claim blocks captured for non-movable use" RFC touch this function
>   but are not queued yet, so this applies cleanly to both trees.
> - The hit rate of this path can be observed with the
>   mm_page_alloc_extfrag tracepoint (fallbackmt=HIGHATOMIC).
> -- 
> 2.47.3

-- 
Cheers,
Harry / Hyeonggon


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-11-30 15:56 ` Harry Yoo
@ 2026-12-02  6:08   ` Qi Wu
  0 siblings, 0 replies; 9+ messages in thread
From: Qi Wu @ 2026-12-02  6:08 UTC (permalink / raw)
  To: Harry Yoo
  Cc: Vlastimil Babka, Johannes Weiner, Andrew Morton,
	Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
	Mel Gorman, linux-mm

Hi Harry,

On Mon, Nov 30, 2026 at 03:56:39PM +0000, Harry Yoo wrote:
> The idea of this patch makes sense to me, but would you please at least
> try to reproduce the problem before claiming it _fixes_ the problem :)
> ... especially when backporting a patch to -stable.

Fair point. I reproduced it on the official linux-7.3.y stable tree, which
carries defrag_mode natively and the order-0 promotion (7e8756d7ad22)
backported, but not this fix.

Test kernel
-----------
Official linux-7.3.y stable (7.3.7), unpatched, booted with mem=32G.
compaction_capture() there still has no MIGRATE_HIGHATOMIC filter.

Reproducer
----------
A deterministic module-assisted reproducer. The trigger is constructed,
but every step goes through the normal allocator paths:

  - Page Alloc Hogger (Juan Yescas, RFC v2) holds UNMOVABLE order-0 pages
    via debugfs until the UNMOVABLE freelists are empty. It allocates
    with gfp=0 (no reclaim), so it only takes free pages and cannot OOM
    the system.
  - A small driver pinned to CPU0 keeps allocating and holding order-0
    GFP_KERNEL (UNMOVABLE) pages. With UNMOVABLE empty and defrag_mode=1,
    each allocation takes the slowpath: reclaim frees movable/reclaimable
    pages that ALLOC_NOFRAGMENT cannot use, so it enters direct compaction
    promoted to pageblock_order and arms capture_control with order=0.
  - A helper module fires a hrtimer pinned to CPU0 in hardirq context.
    Each callback does alloc_pages(GFP_ATOMIC|__GFP_HIGH, 4) -- order>3
    bypasses PCP, so it reaches rmqueue_buddy() and creates a HIGHATOMIC
    reserve -- then split_page() and frees the pages as order-0. When
    this interrupts the driver inside compaction, the HIGHATOMIC order-0
    free is captured by the driver's capture_control.

Detection
---------
I enabled the mm_page_alloc_extfrag tracepoint with the filter
"fallback_migratetype == 3" (MIGRATE_HIGHATOMIC). The regular fallback
arrays never contain MIGRATE_HIGHATOMIC:

  [MIGRATE_UNMOVABLE]   = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE   },
  [MIGRATE_MOVABLE]     = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE },
  [MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE,   MIGRATE_MOVABLE   },

so such an event can only be emitted by compaction_capture(), where the
tracepoint fires immediately before "capc->page = page". Each event is
therefore an actual capture of a HIGHATOMIC page, not a regular fallback.

Result
------
Without the fix (unpatched stable 7.3.7) the reproducer captures HIGHATOMIC
pages, all with the identical signature alloc_order=0, alloc_migratetype=0
(UNMOVABLE), fallback_migratetype=3 (HIGHATOMIC), captured by the driver
task on CPU0, e.g.:

  ha_driver-6747 [000] mm_page_alloc_extfrag: pfn=0x209710 alloc_order=0
    fallback_order=0 pageblock_order=9 alloc_migratetype=0
    fallback_migratetype=3 fragmenting=1

This is exactly the path widened by 7e8756d7ad22: an order-0 non-movable
request capturing an order-0 HIGHATOMIC page.

A/B on the same tree with the identical reproducer (300s each):

                     HIGHATOMIC   other-type   compact_stall   OOM
                     captures     captures     delta
  without the fix    18           -            +282            1
  with the fix       0            2293         +28             0

The 2293 other-type captures with the fix (2252 RECLAIMABLE + 41 MOVABLE)
show the capture path stays active, so the zero is the filter working, not
the path going quiet. No regression: allocations still succeed, no OOM.

Caveats
-------
The trigger is constructed with a module, so the hit rate says nothing
about the natural frequency on a production system.

Thanks,
Qi Wu


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-11-29 14:23 [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages Qi Wu
  2026-11-30 15:56 ` Harry Yoo
@ 2026-12-03  8:34 ` Dev Jain
  2026-12-03 11:03   ` Vlastimil Babka (SUSE)
  1 sibling, 1 reply; 9+ messages in thread
From: Dev Jain @ 2026-12-03  8:34 UTC (permalink / raw)
  To: Qi Wu, Vlastimil Babka, Johannes Weiner, Andrew Morton
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
	Mel Gorman, linux-mm



On 29/11/26 7:53 pm, Qi Wu wrote:
> compaction_capture() filters CMA and isolated pages but not
> MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
> escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
> nr_free_highatomic watermark accounting: a plain blocking allocation
> can consume a page reserved for atomic allocations. HIGHATOMIC pages
> reach the hook through PCP drains, which re-read the pageblock type
> before calling __free_one_page().
> 
> The gap has existed since capture was introduced; commit 7e8756d7ad22
> ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
> widened it by sending non-movable order-0 allocations through direct
> compaction when defrag_mode is enabled.
> 
> Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
> and the allocation falls back to get_page_from_freelist(), where the
> reserve checks apply.
> 
> Found and drafted with AI assistance (Qoder); build-tested only.
> 
> Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
> ---

I think the main bug is about policy: IIUC a non-highatomic request currently
is able to take a highatomic page only via the PCP. Once we are in the
zone a highatomic page can be taken only by highatomic request.

So with that in mind I think this patch is correct for its scope:

Reviewed-by: Dev Jain <dev.jain@arm.com>

But the bigger question is, compaction_capture() captures a page for an allocation,
with no context as to who will consume that page. So for example with an
ALLOC_NOFRAGMENT request, we could mix allocations in pageblocks.

So perhaps there should be a check after looking up capc->page, whether
this is suitable for our allocation.


>  mm/page_alloc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 2fef4092c913..4443d715df2d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -735,6 +735,10 @@ compaction_capture(struct capture_control *capc, struct page *page,
>  	    is_migrate_isolate(migratetype))
>  		return false;
>  
> +	/* HIGHATOMIC pages are reserved for atomic allocations. */
> +	if (migratetype == MIGRATE_HIGHATOMIC)
> +		return false;
> +
>  	/*
>  	 * Do not let lower order allocations pollute a movable pageblock
>  	 * unless compaction is also requesting movable pages.
> 
> base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8
> 
> Notes (not part of the commit log):
> - Checked against akpm mm-unstable (890dc639d8a3): compaction_capture()
>   is identical there. The in-flight freetype_t rework and the
>   "claim blocks captured for non-movable use" RFC touch this function
>   but are not queued yet, so this applies cleanly to both trees.
> - The hit rate of this path can be observed with the
>   mm_page_alloc_extfrag tracepoint (fallbackmt=HIGHATOMIC).



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-12-03  8:34 ` Dev Jain
@ 2026-12-03 11:03   ` Vlastimil Babka (SUSE)
  2026-12-03 17:05     ` Zi Yan
  0 siblings, 1 reply; 9+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-12-03 11:03 UTC (permalink / raw)
  To: Dev Jain, Qi Wu, Johannes Weiner, Andrew Morton, Kiryl Shutsemau
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan,
	Mel Gorman, linux-mm

On 12/3/26 09:34, Dev Jain wrote:
> 
> 
> On 29/11/26 7:53 pm, Qi Wu wrote:
>> compaction_capture() filters CMA and isolated pages but not
>> MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
>> escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
>> nr_free_highatomic watermark accounting: a plain blocking allocation
>> can consume a page reserved for atomic allocations. HIGHATOMIC pages
>> reach the hook through PCP drains, which re-read the pageblock type
>> before calling __free_one_page().
>> 
>> The gap has existed since capture was introduced; commit 7e8756d7ad22
>> ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
>> widened it by sending non-movable order-0 allocations through direct
>> compaction when defrag_mode is enabled.
>> 
>> Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
>> and the allocation falls back to get_page_from_freelist(), where the
>> reserve checks apply.
>> 
>> Found and drafted with AI assistance (Qoder); build-tested only.
>> 
>> Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
>> ---
> 
> I think the main bug is about policy: IIUC a non-highatomic request currently
> is able to take a highatomic page only via the PCP. Once we are in the
> zone a highatomic page can be taken only by highatomic request.
> 
> So with that in mind I think this patch is correct for its scope:
> 
> Reviewed-by: Dev Jain <dev.jain@arm.com>
> 
> But the bigger question is, compaction_capture() captures a page for an allocation,
> with no context as to who will consume that page. So for example with an
> ALLOC_NOFRAGMENT request, we could mix allocations in pageblocks.
> 
> So perhaps there should be a check after looking up capc->page, whether
> this is suitable for our allocation.

Let's CC Kiryl then...

> 
>>  mm/page_alloc.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>> 
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 2fef4092c913..4443d715df2d 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -735,6 +735,10 @@ compaction_capture(struct capture_control *capc, struct page *page,
>>  	    is_migrate_isolate(migratetype))
>>  		return false;
>>  
>> +	/* HIGHATOMIC pages are reserved for atomic allocations. */
>> +	if (migratetype == MIGRATE_HIGHATOMIC)
>> +		return false;
>> +
>>  	/*
>>  	 * Do not let lower order allocations pollute a movable pageblock
>>  	 * unless compaction is also requesting movable pages.
>> 
>> base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8
>> 
>> Notes (not part of the commit log):
>> - Checked against akpm mm-unstable (890dc639d8a3): compaction_capture()
>>   is identical there. The in-flight freetype_t rework and the
>>   "claim blocks captured for non-movable use" RFC touch this function
>>   but are not queued yet, so this applies cleanly to both trees.
>> - The hit rate of this path can be observed with the
>>   mm_page_alloc_extfrag tracepoint (fallbackmt=HIGHATOMIC).
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-12-03 11:03   ` Vlastimil Babka (SUSE)
@ 2026-12-03 17:05     ` Zi Yan
  2026-12-04  2:00       ` Kiryl Shutsemau (Meta)
  0 siblings, 1 reply; 9+ messages in thread
From: Zi Yan @ 2026-12-03 17:05 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE), Dev Jain, Qi Wu, Johannes Weiner,
	Andrew Morton, Kiryl Shutsemau
  Cc: Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Mel Gorman,
	linux-mm

On Thu Dec 3, 2026 at 6:03 AM EST, Vlastimil Babka (SUSE) wrote:
> On 12/3/26 09:34, Dev Jain wrote:
>> 
>> 
>> On 29/11/26 7:53 pm, Qi Wu wrote:
>>> compaction_capture() filters CMA and isolated pages but not
>>> MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
>>> escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
>>> nr_free_highatomic watermark accounting: a plain blocking allocation
>>> can consume a page reserved for atomic allocations. HIGHATOMIC pages
>>> reach the hook through PCP drains, which re-read the pageblock type
>>> before calling __free_one_page().
>>> 
>>> The gap has existed since capture was introduced; commit 7e8756d7ad22
>>> ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
>>> widened it by sending non-movable order-0 allocations through direct
>>> compaction when defrag_mode is enabled.
>>> 
>>> Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
>>> and the allocation falls back to get_page_from_freelist(), where the
>>> reserve checks apply.
>>> 
>>> Found and drafted with AI assistance (Qoder); build-tested only.
>>> 
>>> Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
>>> ---
>> 
>> I think the main bug is about policy: IIUC a non-highatomic request currently
>> is able to take a highatomic page only via the PCP. Once we are in the
>> zone a highatomic page can be taken only by highatomic request.
>> 
>> So with that in mind I think this patch is correct for its scope:
>> 
>> Reviewed-by: Dev Jain <dev.jain@arm.com>
>> 
>> But the bigger question is, compaction_capture() captures a page for an allocation,
>> with no context as to who will consume that page. So for example with an
>> ALLOC_NOFRAGMENT request, we could mix allocations in pageblocks.
>> 
>> So perhaps there should be a check after looking up capc->page, whether
>> this is suitable for our allocation.

If the page is not suitable,  capc->page is freed? Or we hold the page
until a suitable allocation comes up.

Probably we should put more info in capture_control, so
compaction_capture() can make right decisions.

>
> Let's CC Kiryl then...
>
>> 
>>>  mm/page_alloc.c | 4 ++++
>>>  1 file changed, 4 insertions(+)
>>> 
>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>>> index 2fef4092c913..4443d715df2d 100644
>>> --- a/mm/page_alloc.c
>>> +++ b/mm/page_alloc.c
>>> @@ -735,6 +735,10 @@ compaction_capture(struct capture_control *capc, struct page *page,
>>>  	    is_migrate_isolate(migratetype))
>>>  		return false;
>>>  
>>> +	/* HIGHATOMIC pages are reserved for atomic allocations. */
>>> +	if (migratetype == MIGRATE_HIGHATOMIC)
>>> +		return false;
>>> +
>>>  	/*
>>>  	 * Do not let lower order allocations pollute a movable pageblock
>>>  	 * unless compaction is also requesting movable pages.
>>> 
>>> base-commit: 4f069ab1ec243e6b60dc438772905855c60774e8
>>> 
>>> Notes (not part of the commit log):
>>> - Checked against akpm mm-unstable (890dc639d8a3): compaction_capture()
>>>   is identical there. The in-flight freetype_t rework and the
>>>   "claim blocks captured for non-movable use" RFC touch this function
>>>   but are not queued yet, so this applies cleanly to both trees.
>>> - The hit rate of this path can be observed with the
>>>   mm_page_alloc_extfrag tracepoint (fallbackmt=HIGHATOMIC).
>> 




-- 
Best Regards,
Yan, Zi



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-12-03 17:05     ` Zi Yan
@ 2026-12-04  2:00       ` Kiryl Shutsemau (Meta)
  2026-12-04  5:01         ` Dev Jain
  0 siblings, 1 reply; 9+ messages in thread
From: Kiryl Shutsemau (Meta) @ 2026-12-04  2:00 UTC (permalink / raw)
  To: Zi Yan
  Cc: Vlastimil Babka (SUSE), Dev Jain, Qi Wu, Johannes Weiner,
	Andrew Morton, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Mel Gorman, linux-mm

On Thu, Dec 03, 2026 at 12:05:53PM -0500, Zi Yan wrote:
> On Thu Dec 3, 2026 at 6:03 AM EST, Vlastimil Babka (SUSE) wrote:
> > On 12/3/26 09:34, Dev Jain wrote:
> >> 
> >> 
> >> On 29/11/26 7:53 pm, Qi Wu wrote:
> >>> compaction_capture() filters CMA and isolated pages but not
> >>> MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
> >>> escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
> >>> nr_free_highatomic watermark accounting: a plain blocking allocation
> >>> can consume a page reserved for atomic allocations. HIGHATOMIC pages
> >>> reach the hook through PCP drains, which re-read the pageblock type
> >>> before calling __free_one_page().
> >>> 
> >>> The gap has existed since capture was introduced; commit 7e8756d7ad22
> >>> ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
> >>> widened it by sending non-movable order-0 allocations through direct
> >>> compaction when defrag_mode is enabled.
> >>> 
> >>> Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
> >>> and the allocation falls back to get_page_from_freelist(), where the
> >>> reserve checks apply.
> >>> 
> >>> Found and drafted with AI assistance (Qoder); build-tested only.
> >>> 
> >>> Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
> >>> Cc: stable@vger.kernel.org
> >>> Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
> >>> ---
> >> 
> >> I think the main bug is about policy: IIUC a non-highatomic request currently
> >> is able to take a highatomic page only via the PCP. Once we are in the
> >> zone a highatomic page can be taken only by highatomic request.
> >> 
> >> So with that in mind I think this patch is correct for its scope:
> >> 
> >> Reviewed-by: Dev Jain <dev.jain@arm.com>
> >> 
> >> But the bigger question is, compaction_capture() captures a page for an allocation,
> >> with no context as to who will consume that page. So for example with an
> >> ALLOC_NOFRAGMENT request, we could mix allocations in pageblocks.
> >> 
> >> So perhaps there should be a check after looking up capc->page, whether
> >> this is suitable for our allocation.
> 
> If the page is not suitable,  capc->page is freed? Or we hold the page
> until a suitable allocation comes up.
> 
> Probably we should put more info in capture_control, so
> compaction_capture() can make right decisions.

Right. With defrag_mode, unmovable and reclaimable requests capture each
other's pages, which the freelists would not give them under
ALLOC_NOFRAGMENT. Plain slab churn is enough to hit it.

The obvious fix is to pass alloc_flags in capture_control and reject such
pages in compaction_capture(). A rejected page just goes to the freelist.

See the patch below.

If it looks good, I can submit a proper patch.

diff --git a/mm/internal.h b/mm/internal.h
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -903,6 +903,7 @@ struct capture_control {
 	 * original allocation order so prep_new_page() is consistent.
 	 */
 	int order;
+	unsigned int alloc_flags;
 	struct page *page;
 };

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -735,6 +735,15 @@ compaction_capture(struct capture_control *capc, struct page *page,
 	    is_migrate_isolate(migratetype))
 		return false;

+	/*
+	 * Under ALLOC_NOFRAGMENT the freelists give a request below
+	 * pageblock_order only its own migratetype, or a whole block to
+	 * claim. Do not hand out what they would refuse.
+	 */
+	if ((capc->alloc_flags & ALLOC_NOFRAGMENT) &&
+	    order < pageblock_order && migratetype != capc->migratetype)
+		return false;
+
 	/*
 	 * Do not let lower order allocations pollute a movable pageblock
 	 * unless compaction is also requesting movable pages.
@@ -4203,6 +4212,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 		.zone = NULL,
 		.migratetype = ac->migratetype,
 		.order = order,
+		.alloc_flags = alloc_flags,
 		.page = NULL,
 	};
 	int compact_order = ac->reclaim_compact_order;

-- 
  Kiryl Shutsemau / Kirill A. Shutemov


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-12-04  2:00       ` Kiryl Shutsemau (Meta)
@ 2026-12-04  5:01         ` Dev Jain
  2026-12-04 22:32           ` Kiryl Shutsemau (Meta)
  0 siblings, 1 reply; 9+ messages in thread
From: Dev Jain @ 2026-12-04  5:01 UTC (permalink / raw)
  To: Kiryl Shutsemau (Meta), Zi Yan
  Cc: Vlastimil Babka (SUSE), Qi Wu, Johannes Weiner, Andrew Morton,
	Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Mel Gorman,
	linux-mm



On 04/12/26 7:30 am, Kiryl Shutsemau (Meta) wrote:
> On Thu, Dec 03, 2026 at 12:05:53PM -0500, Zi Yan wrote:
>> On Thu Dec 3, 2026 at 6:03 AM EST, Vlastimil Babka (SUSE) wrote:
>>> On 12/3/26 09:34, Dev Jain wrote:
>>>>
>>>>
>>>> On 29/11/26 7:53 pm, Qi Wu wrote:
>>>>> compaction_capture() filters CMA and isolated pages but not
>>>>> MIGRATE_HIGHATOMIC. A captured page bypasses the buddy freelists, so it
>>>>> escapes the ALLOC_HIGHATOMIC check in rmqueue_buddy() and the
>>>>> nr_free_highatomic watermark accounting: a plain blocking allocation
>>>>> can consume a page reserved for atomic allocations. HIGHATOMIC pages
>>>>> reach the hook through PCP drains, which re-read the pageblock type
>>>>> before calling __free_one_page().
>>>>>
>>>>> The gap has existed since capture was introduced; commit 7e8756d7ad22
>>>>> ("mm: page_alloc: fix non-movable reclaim storm in defrag_mode")
>>>>> widened it by sending non-movable order-0 allocations through direct
>>>>> compaction when defrag_mode is enabled.
>>>>>
>>>>> Refuse HIGHATOMIC pages like CMA. The page then enters the freelists
>>>>> and the allocation falls back to get_page_from_freelist(), where the
>>>>> reserve checks apply.
>>>>>
>>>>> Found and drafted with AI assistance (Qoder); build-tested only.
>>>>>
>>>>> Fixes: 5e1f0f098b46 ("mm, compaction: capture a page under direct compaction")
>>>>> Cc: stable@vger.kernel.org
>>>>> Signed-off-by: Qi Wu <shijing.wuqi@linux.alibaba.com>
>>>>> ---
>>>>
>>>> I think the main bug is about policy: IIUC a non-highatomic request currently
>>>> is able to take a highatomic page only via the PCP. Once we are in the
>>>> zone a highatomic page can be taken only by highatomic request.
>>>>
>>>> So with that in mind I think this patch is correct for its scope:
>>>>
>>>> Reviewed-by: Dev Jain <dev.jain@arm.com>
>>>>
>>>> But the bigger question is, compaction_capture() captures a page for an allocation,
>>>> with no context as to who will consume that page. So for example with an
>>>> ALLOC_NOFRAGMENT request, we could mix allocations in pageblocks.
>>>>
>>>> So perhaps there should be a check after looking up capc->page, whether
>>>> this is suitable for our allocation.
>>
>> If the page is not suitable,  capc->page is freed? Or we hold the page
>> until a suitable allocation comes up.
>>
>> Probably we should put more info in capture_control, so
>> compaction_capture() can make right decisions.
> 
> Right. With defrag_mode, unmovable and reclaimable requests capture each
> other's pages, which the freelists would not give them under
> ALLOC_NOFRAGMENT. Plain slab churn is enough to hit it.

"Plain slab churn is enough to hit it" hmm because freeing of pages is
very frequent, there is a high chance that someone will satisfy the
conditions of compaction_capture(), makes sense.


> 
> The obvious fix is to pass alloc_flags in capture_control and reject such
> pages in compaction_capture(). A rejected page just goes to the freelist.
> 
> See the patch below.
> 
> If it looks good, I can submit a proper patch.
> 
> diff --git a/mm/internal.h b/mm/internal.h
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -903,6 +903,7 @@ struct capture_control {
>  	 * original allocation order so prep_new_page() is consistent.
>  	 */
>  	int order;
> +	unsigned int alloc_flags;
>  	struct page *page;
>  };
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -735,6 +735,15 @@ compaction_capture(struct capture_control *capc, struct page *page,
>  	    is_migrate_isolate(migratetype))
>  		return false;
> 
> +	/*
> +	 * Under ALLOC_NOFRAGMENT the freelists give a request below
> +	 * pageblock_order only its own migratetype, or a whole block to
> +	 * claim. Do not hand out what they would refuse.
> +	 */
> +	if ((capc->alloc_flags & ALLOC_NOFRAGMENT) &&
> +	    order < pageblock_order && migratetype != capc->migratetype)
> +		return false;
> +
>  	/*
>  	 * Do not let lower order allocations pollute a movable pageblock
>  	 * unless compaction is also requesting movable pages.
> @@ -4203,6 +4212,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
>  		.zone = NULL,
>  		.migratetype = ac->migratetype,
>  		.order = order,
> +		.alloc_flags = alloc_flags,
>  		.page = NULL,
>  	};
>  	int compact_order = ac->reclaim_compact_order;
> 

Looks good at cursory glance. You may want to audit all cases, for example,
perhaps we hand out a page which was not supposed to be handed out due to
watermark restrictions etc. Essentially, if capc->page == NULL but compaction
was indeed able to create the free space, we need to consider the cases where
get_page_from_freelist() would definitely fail to get that page due to "restrictions".




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
  2026-12-04  5:01         ` Dev Jain
@ 2026-12-04 22:32           ` Kiryl Shutsemau (Meta)
  0 siblings, 0 replies; 9+ messages in thread
From: Kiryl Shutsemau (Meta) @ 2026-12-04 22:32 UTC (permalink / raw)
  To: Dev Jain, Rik van Riel
  Cc: Zi Yan, Vlastimil Babka (SUSE), Qi Wu, Johannes Weiner,
	Andrew Morton, Suren Baghdasaryan, Michal Hocko, Brendan Jackman,
	Mel Gorman, linux-mm

On Fri, Dec 04, 2026 at 10:31:49AM +0530, Dev Jain wrote:
> Looks good at cursory glance. You may want to audit all cases, for example,
> perhaps we hand out a page which was not supposed to be handed out due to
> watermark restrictions etc. Essentially, if capc->page == NULL but compaction
> was indeed able to create the free space, we need to consider the cases where
> get_page_from_freelist() would definitely fail to get that page due to "restrictions".

I went through get_page_from_freelist(). With Qi's patch and mine,
capture does not hand out a page the freelists would refuse.

Watermarks seem to be fine: the captured page was just freed by
compaction, and the page compaction consumes is the migration target,
which __isolate_free_page() takes only above min. compaction_suitable()
already checked the request's watermark and lowmem reserve before
compaction started. try_to_compact_pages() applies the same cpuset check
as the freelists.

The difference is the pageblock type.

When the freelists give a whole block to another migratetype,
try_to_claim_block() converts it; capture does not. Harmless if the
allocation is freed whole, but a partial free puts pages on the old
type's freelist: a THP captures a whole unmovable block, a partial
munmap() splits it, and unmovable allocations fill the freed pages next
to the remaining movable ones.

Rik, your RFC [1] converts only a movable block taken by a non-movable
request. The diff below converts in every direction. It needs Qi's
patch, or it would convert a highatomic block.

The compaction_capture() fixes could go as one series:

  1. Qi's patch, as posted;
  2. the ALLOC_NOFRAGMENT check from my previous mail;
  3. move change_pageblock_range() up, no functional change;
  4. convert a whole captured block.

The diff below is 3 and 4. Rik, are you OK with 4 replacing your 5/5?

Vlastimil, Dev, if it looks good I can submit it. Or Qi's patch can go
in on its own, ahead of the rest.

[1] https://lore.kernel.org/all/20261007021250.1665929-6-riel@surriel.com/

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -545,6 +545,17 @@ static void set_pageblock_migratetype(struct page *page,
 				  PAGEBLOCK_MIGRATETYPE_MASK | PAGEBLOCK_ISO_MASK);
 }
 
+static void change_pageblock_range(struct page *pageblock_page,
+				   int start_order, int migratetype)
+{
+	int nr_pageblocks = 1 << (start_order - pageblock_order);
+
+	while (nr_pageblocks--) {
+		set_pageblock_migratetype(pageblock_page, migratetype);
+		pageblock_page += pageblock_nr_pages;
+	}
+}
+
 void __meminit init_pageblock_migratetype(struct page *page,
 					  enum migratetype migratetype,
 					  bool isolate)
@@ -759,6 +770,14 @@ compaction_capture(struct capture_control *capc, struct page *page,
 		trace_mm_page_alloc_extfrag(page, capc->order, order,
 					    capc->migratetype, migratetype);
 
+	/*
+	 * The freelists convert a whole block they hand to another
+	 * migratetype, see try_to_claim_block(). Do the same, so that
+	 * pages freed from it later go to the right freelist.
+	 */
+	if (order >= pageblock_order && migratetype != capc->migratetype)
+		change_pageblock_range(page, order, capc->migratetype);
+
 	capc->page = page;
 	return true;
 }
@@ -906,17 +925,6 @@ buddy_merge_likely(unsigned long pfn, unsigned long buddy_pfn,
 			NULL) != NULL;
 }
 
-static void change_pageblock_range(struct page *pageblock_page,
-				   int start_order, int migratetype)
-{
-	int nr_pageblocks = 1 << (start_order - pageblock_order);
-
-	while (nr_pageblocks--) {
-		set_pageblock_migratetype(pageblock_page, migratetype);
-		pageblock_page += pageblock_nr_pages;
-	}
-}
-
 /*
  * Freeing function for a buddy system allocator.
  *
-- 
  Kiryl Shutsemau / Kirill A. Shutemov


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-04 22:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 14:23 [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages Qi Wu
2026-11-30 15:56 ` Harry Yoo
2026-12-02  6:08   ` Qi Wu
2026-12-03  8:34 ` Dev Jain
2026-12-03 11:03   ` Vlastimil Babka (SUSE)
2026-12-03 17:05     ` Zi Yan
2026-12-04  2:00       ` Kiryl Shutsemau (Meta)
2026-12-04  5:01         ` Dev Jain
2026-12-04 22:32           ` Kiryl Shutsemau (Meta)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox