Move MIGRATE_MOVABLE pageblock initialization into the memmap init
helpers in mm/mm_init.c.

Let init_single_page_frozen() initialize the pageblock migratetype for
single-page folios, and let memmap_init_compound_page_frozen() handle
the whole range for compound pages. With pageblock initialization
centralized there, drop the duplicate hugetlb bootmem-specific
initialization in mm/hugetlb.c.

The old hugetlb_bootmem_init_migratetype() skipped CMA folios (via
folio_test_hugetlb_cma()), but the new helpers always set
MIGRATE_MOVABLE. This is safe because cma_activate_area() will later
override the migratetype for CMA pageblocks, so the initial
MIGRATE_MOVABLE setting does not matter for CMA pages.

Signed-off-by: Muchun Song <[email protected]>
---
 mm/hugetlb.c | 25 -------------------------
 mm/mm_init.c | 20 ++++++++++++--------
 2 files changed, 12 insertions(+), 33 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index df798f9386d6..fa269560f657 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3118,30 +3118,6 @@ static bool __init alloc_bootmem_huge_page(struct hstate 
*h, int nid)
        return true;
 }
 
-/*
- * memblock-allocated pageblocks might not have the migrate type set
- * if marked with the 'noinit' flag. Set it to the default (MIGRATE_MOVABLE)
- * here, or MIGRATE_CMA if this was a page allocated through an early CMA
- * reservation.
- *
- * In case of vmemmap optimized folios, the tail vmemmap pages are mapped
- * read-only, but that's ok - for sparse vmemmap this does not write to
- * the page structure.
- */
-static void __init hugetlb_bootmem_init_migratetype(struct folio *folio,
-                                                         struct hstate *h)
-{
-       unsigned long nr_pages = pages_per_huge_page(h), i;
-
-       WARN_ON_ONCE(!pageblock_aligned(folio_pfn(folio)));
-
-       for (i = 0; i < nr_pages; i += pageblock_nr_pages) {
-               if (!folio_test_hugetlb_cma(folio))
-                       init_pageblock_migratetype(folio_page(folio, i),
-                                         MIGRATE_MOVABLE, false);
-       }
-}
-
 static void __init prep_and_add_bootmem_folios(struct hstate *h,
                                        struct list_head *folio_list)
 {
@@ -3149,7 +3125,6 @@ static void __init prep_and_add_bootmem_folios(struct 
hstate *h,
        struct folio *folio, *tmp_f;
 
        list_for_each_entry_safe(folio, tmp_f, folio_list, lru) {
-               hugetlb_bootmem_init_migratetype(folio, h);
                /* Subdivide locks to achieve better parallel performance */
                spin_lock_irqsave(&hugetlb_lock, flags);
                account_new_hugetlb_folio(h, folio);
diff --git a/mm/mm_init.c b/mm/mm_init.c
index ff6e9fb468bd..17ae0eb1ccfb 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1018,7 +1018,7 @@ static void __init memmap_init(void)
                init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
 }
 
-static void __meminit init_single_page_frozen(struct page *page, unsigned long 
pfn,
+static void __meminit __init_single_page_frozen(struct page *page, unsigned 
long pfn,
                enum zone_type zone, int nid)
 {
        __init_single_page(page, pfn, zone, nid);
@@ -1042,19 +1042,28 @@ static void __meminit init_single_page_frozen(struct 
page *page, unsigned long p
        set_page_count(page, 0);
 }
 
+static void __meminit init_single_page_frozen(struct page *page, unsigned long 
pfn,
+               enum zone_type zone, int nid)
+{
+       __init_single_page_frozen(page, pfn, zone, nid);
+       pageblock_migratetype_init_range(pfn, 1, MIGRATE_MOVABLE, false, false);
+}
+
 void __meminit memmap_init_compound_page_frozen(struct page *head, unsigned 
long pfn,
                enum zone_type zone, int nid, unsigned int order)
 {
        int nr_pages = vmemmap_nr_struct_pages(pfn, 1UL << order);
 
-       init_single_page_frozen(head, pfn, zone, nid);
+       __init_single_page_frozen(head, pfn, zone, nid);
 
        __SetPageHead(head);
        for (int i = 1; i < nr_pages; i++) {
-               init_single_page_frozen(head + i, pfn + i, zone, nid);
+               __init_single_page_frozen(head + i, pfn + i, zone, nid);
                prep_compound_tail(head + i, head, order);
        }
        prep_compound_head(head, order);
+
+       pageblock_migratetype_init_range(pfn, 1UL << order, MIGRATE_MOVABLE, 
false, false);
 }
 
 #ifdef CONFIG_ZONE_DEVICE
@@ -1087,9 +1096,6 @@ void __ref memmap_init_zone_device(struct zone *zone,
        for (pfn = start_pfn; pfn < end_pfn; pfn += pfns_per_compound) {
                struct page *head = pfn_to_page(pfn);
 
-               if (IS_ALIGNED(pfn, PAGES_PER_SECTION))
-                       cond_resched();
-
                if (pgmap->vmemmap_shift)
                        memmap_init_compound_page_frozen(head, pfn, zone_idx, 
nid,
                                                         pgmap->vmemmap_shift);
@@ -1105,8 +1111,6 @@ void __ref memmap_init_zone_device(struct zone *zone,
                ((struct folio *)head)->pgmap = pgmap;
        }
 
-       pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE, 
false, false);
-
        pr_debug("%s initialised %lu pages in %ums\n", __func__,
                nr_pages, jiffies_to_msecs(jiffies - start));
 }
-- 
2.54.0


Reply via email to