[PATCH v3 4/4] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE compound pages

Muchun Song muchun.song at linux.dev
Tue Apr 21 19:31:36 AEST 2026



> On Apr 21, 2026, at 10:20, Muchun Song <songmuchun at bytedance.com> wrote:
> 
> The memmap_init_zone_device() function only initializes the migratetype
> of the first pageblock of a compound page. If the compound page size
> exceeds pageblock_nr_pages (e.g., 1GB hugepages with 2MB pageblocks),
> subsequent pageblocks in the compound page remain uninitialized.
> 
> Move the migratetype initialization out of __init_zone_device_page()
> and into a separate pageblock_migratetype_init_range() function. This
> iterates over the entire PFN range of the memory, ensuring that all
> pageblocks are correctly initialized.
> 
> Fixes: c4386bd8ee3a ("mm/memremap: add ZONE_DEVICE support for compound pages")
> Signed-off-by: Muchun Song <songmuchun at bytedance.com>
> Reviewed-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
> ---
> mm/mm_init.c | 43 ++++++++++++++++++++++++++++---------------
> 1 file changed, 28 insertions(+), 15 deletions(-)
> 
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index f9f8e1af921c..e2d8eae23aa3 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -674,6 +674,19 @@ static inline void fixup_hashdist(void)
> static inline void fixup_hashdist(void) {}
> #endif /* CONFIG_NUMA */
> 
> +static __meminit void pageblock_migratetype_init_range(unsigned long pfn,
> +       unsigned long nr_pages,
> +       int migratetype)
> +{
> + 	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))
> + 			cond_resched();
> + 	}
> +}

I found a positive comment from AI review:

This trigger a -Wunused-function warning when CONFIG_ZONE_DEVICE is
disabled.

I'll fix it in the next version.

Thanks.



More information about the Linuxppc-dev mailing list