mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm: free HIGHATOMIC and CMA frozen pages via buddy
@ 2026-05-25  7:10 zhaoyang.huang
  2026-05-25 20:15 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: zhaoyang.huang @ 2026-05-25  7:10 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka, Johannes Weiner, Michal Hocko,
	Suren Baghdasaryan, Brendan Jackman, Zi Yan, linux-mm,
	linux-kernel, Zhaoyang Huang, steve.kang

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Pages in pageblocks above MIGRATE_PCPTYPES were remapped to
MIGRATE_MOVABLE on the per-CPU lists, so order-9 GFP_ATOMIC
allocations could consume CMA physical blocks which may lead to
cma_alloc failed.
This commit would like to free them through free_one_page() simply.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 mm/page_alloc.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 65e205111553..94b79db8da2f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2945,19 +2945,15 @@ static void __free_frozen_pages(struct page *page, unsigned int order,
 
 	/*
 	 * We only track unmovable, reclaimable and movable on pcp lists.
-	 * Place ISOLATE pages on the isolated list because they are being
-	 * offlined but treat HIGHATOMIC and CMA as movable pages so we can
-	 * get those areas back if necessary. Otherwise, we may have to free
-	 * excessively into the page allocator
+	 * ISOLATE, HIGHATOMIC and CMA pageblocks are freed directly to the
+	 * buddy allocator so their migratetype is not misrouted on PCP lists
+	 * (e.g. order-9 pages must not share the MIGRATE_MOVABLE THP list).
 	 */
 	zone = page_zone(page);
 	migratetype = get_pfnblock_migratetype(page, pfn);
 	if (unlikely(migratetype >= MIGRATE_PCPTYPES)) {
-		if (unlikely(is_migrate_isolate(migratetype))) {
-			free_one_page(zone, page, pfn, order, fpi_flags);
-			return;
-		}
-		migratetype = MIGRATE_MOVABLE;
+		free_one_page(zone, page, pfn, order, fpi_flags);
+		return;
 	}
 
 	if (unlikely((fpi_flags & FPI_TRYLOCK) && IS_ENABLED(CONFIG_PREEMPT_RT)
@@ -3029,6 +3025,17 @@ void free_unref_folios(struct folio_batch *folios)
 		folio->private = NULL;
 		migratetype = get_pfnblock_migratetype(&folio->page, pfn);
 
+		if (unlikely(!is_migrate_isolate(migratetype) &&
+			     migratetype >= MIGRATE_PCPTYPES)) {
+			if (pcp) {
+				pcp_spin_unlock(pcp);
+				locked_zone = NULL;
+				pcp = NULL;
+			}
+			free_one_page(zone, &folio->page, pfn, order, FPI_NONE);
+			continue;
+		}
+
 		/* Different zone requires a different pcp lock */
 		if (zone != locked_zone ||
 		    is_migrate_isolate(migratetype)) {
@@ -3061,13 +3068,6 @@ void free_unref_folios(struct folio_batch *folios)
 			locked_zone = zone;
 		}
 
-		/*
-		 * Non-isolated types over MIGRATE_PCPTYPES get added
-		 * to the MIGRATE_MOVABLE pcp list.
-		 */
-		if (unlikely(migratetype >= MIGRATE_PCPTYPES))
-			migratetype = MIGRATE_MOVABLE;
-
 		trace_mm_page_free_batched(&folio->page);
 		if (!free_frozen_page_commit(zone, pcp, &folio->page,
 				migratetype, order, FPI_NONE)) {
-- 
2.25.1


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

end of thread, other threads:[~2026-05-26  1:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-25  7:10 [PATCH] mm: free HIGHATOMIC and CMA frozen pages via buddy zhaoyang.huang
2026-05-25 20:15 ` Andrew Morton
2026-05-26  1:02   ` Zhaoyang Huang

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

all inboxes | Powered by JetHome®