deferred_free_pages() open-codes two loops to initialize the pageblock
migratetype for a range of pages.

Replace them with pageblock_migratetype_init_range() to remove the
duplication and make the code clearer (Note that deferred_free_pages()
may be called from atomic context).

Signed-off-by: Muchun Song <[email protected]>
Acked-by: Mike Rapoport (Microsoft) <[email protected]>
---
v1->v2:
- Add Acked-by from Mike Rapoport
---
 mm/mm_init.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 5a910cc5534c..96e0f2d8c3ea 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -674,15 +674,15 @@ static inline void fixup_hashdist(void)
 static inline void fixup_hashdist(void) {}
 #endif /* CONFIG_NUMA */
 
-#ifdef CONFIG_ZONE_DEVICE
+#if defined(CONFIG_ZONE_DEVICE) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT)
 static __meminit void pageblock_migratetype_init_range(unsigned long pfn,
-               unsigned long nr_pages, int migratetype)
+               unsigned long nr_pages, int migratetype, bool atomic)
 {
        const unsigned long end = pfn + nr_pages;
 
        for (pfn = pageblock_align(pfn); pfn < end; pfn += pageblock_nr_pages) {
                init_pageblock_migratetype(pfn_to_page(pfn), migratetype, 
false);
-               if (IS_ALIGNED(pfn, PAGES_PER_SECTION))
+               if (!atomic && IS_ALIGNED(pfn, PAGES_PER_SECTION))
                        cond_resched();
        }
 }
@@ -1142,7 +1142,7 @@ void __ref memmap_init_zone_device(struct zone *zone,
                                     compound_nr_pages(pfn, altmap, pgmap));
        }
 
-       pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE);
+       pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE, 
false);
 
        pr_debug("%s initialised %lu pages in %ums\n", __func__,
                nr_pages, jiffies_to_msecs(jiffies - start));
@@ -1993,12 +1993,12 @@ static void __init deferred_free_pages(unsigned long 
pfn,
        if (!nr_pages)
                return;
 
+       pageblock_migratetype_init_range(pfn, nr_pages, mt, true);
+
        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, mt, false);
                __free_pages_core(page, MAX_PAGE_ORDER, MEMINIT_EARLY);
                return;
        }
@@ -2006,11 +2006,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, mt, 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.54.0


Reply via email to