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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ 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
  0 siblings, 0 replies; 6+ 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] 6+ messages in thread

end of thread, other threads:[~2026-12-03 17:06 UTC | newest]

Thread overview: 6+ 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

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