All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kiryl Shutsemau (Meta)" <kas@kernel.org>
To: Dev Jain <dev.jain@arm.com>, Rik van Riel <riel@surriel.com>
Cc: Zi Yan <ziy@nvidia.com>,
	"Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	 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: Fri, 4 Dec 2026 14:32:51 -0800	[thread overview]
Message-ID: <axM7NP2_6idNMxQ1@shutemov.name> (raw)
In-Reply-To: <f5355d9d-5d23-4b38-9380-f1a3e20496f5@arm.com>

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


  reply	other threads:[~2026-12-04 22:33 UTC|newest]

Thread overview: 10+ 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)
2026-12-04  5:01         ` Dev Jain
2026-12-04 22:32           ` Kiryl Shutsemau (Meta) [this message]
2026-12-05 18:25             ` Dev Jain

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=axM7NP2_6idNMxQ1@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=riel@surriel.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 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.