[PATCH 07/49] mm/mm_init: use pageblock_migratetype_init_range() in deferred_free_pages()

Muchun Song
2026-04-05T12:54:09Z

Simplify deferred_free_pages by replacing the duplicate loops for
initializing pageblock migratetype with a call to
pageblock_migratetype_init_range to simplify the code.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/mm_init.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 4936ca78966c..a92c5053f63d 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1974,13 +1974,12 @@ static void __init deferred_free_pages(unsigned long pfn,
if (!nr_pages)
return;

+ pageblock_migratetype_init_range(pfn, nr_pages, MIGRATE_MOVABLE);
+
page = pfn_to_page(pfn);

/* Free a large naturally-aligned chunk if possible */
if (nr_pages == MAX_ORDER_NR_PAGES && IS_MAX_ORDER_ALIGNED(pfn)) {
- for (i = 0; i < nr_pages; i += pageblock_nr_pages)
- init_pageblock_migratetype(page + i, MIGRATE_MOVABLE,
- false);
__free_pages_core(page, MAX_PAGE_ORDER, MEMINIT_EARLY);
return;
}
@@ -1988,12 +1987,8 @@ static void __init deferred_free_pages(unsigned long pfn,
/* Accept chunks smaller than MAX_PAGE_ORDER upfront */
accept_memory(PFN_PHYS(pfn), nr_pages * PAGE_SIZE);

- for (i = 0; i < nr_pages; i++, page++, pfn++) {
- if (pageblock_aligned(pfn))
- init_pageblock_migratetype(page, MIGRATE_MOVABLE,
- false);
- __free_pages_core(page, 0, MEMINIT_EARLY);
- }
+ for (i = 0; i < nr_pages; i++)
+ __free_pages_core(page + i, 0, MEMINIT_EARLY);
}

/* Completion tracking for deferred_init_memmap() threads */
--
2.20.1