All of 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
  0 siblings, 1 reply; 3+ 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] 3+ 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
  0 siblings, 1 reply; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2026-12-02  6:08 UTC | newest]

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.