From: "Kiryl Shutsemau (Meta)" <kas@kernel.org>
To: Zi Yan <ziy@nvidia.com>
Cc: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
Dev Jain <dev.jain@arm.com>,
Qi Wu <shijing.wuqi@linux.alibaba.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Mel Gorman <mgorman@techsingularity.net>,
linux-mm@kvack.org
Subject: Re: [PATCH] mm: page_alloc: do not capture HIGHATOMIC pages
Date: Thu, 3 Dec 2026 18:00:28 -0800 [thread overview]
Message-ID: <axIeWvZRPpIrmbJY@shutemov.name> (raw)
In-Reply-To: <DNB9FFSLL159.2Z1UJ6BMHJ5DB@nvidia.com>
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
prev parent reply other threads:[~2026-12-04 2:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axIeWvZRPpIrmbJY@shutemov.name \
--to=kas@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=dev.jain@arm.com \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=shijing.wuqi@linux.alibaba.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox