RE: [PATCH v9 2/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range

From: Liu, Yuan1

Date: Tue Sep 15 2026 - 06:56:07 EST


> -----Original Message-----
> From: Mike Rapoport <rppt@xxxxxxxxxx>
> Sent: Tuesday, September 15, 2026 2:04 PM
> To: Liu, Yuan1 <yuan1.liu@xxxxxxxxx>
> Cc: David Hildenbrand <david@xxxxxxxxxx>; Oscar Salvador
> <osalvador@xxxxxxx>; Wei Yang <richard.weiyang@xxxxxxxxx>; linux-
> mm@xxxxxxxxx; Zou, Nanhai <nanhai.zou@xxxxxxxxx>; Chen Zhang
> <zhangchen.kidd@xxxxxx>; Zeng, Jason <jason.zeng@xxxxxxxxx>; Chen, Yu C
> <yu.c.chen@xxxxxxxxx>; Deng, Pan <pan.deng@xxxxxxxxx>; Li, Tianyou
> <tianyou.li@xxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH v9 2/2] mm/memory_hotplug: optimize zone contiguous
> check when changing pfn range
>
> Hi,
>
> On Mon, Sep 14, 2026 at 03:29:29AM -0400, Yuan Liu wrote:
> > When move_pfn_range_to_zone() or remove_pfn_range_from_zone() updates a
> > zone, set_zone_contiguous() rescans the entire zone pageblock-by-
> pageblock
> > to rebuild zone->contiguous. For large zones this is a significant cost
> > during memory hotplug and hot-unplug.
> >
> > diff --git a/mm/mm_init.c b/mm/mm_init.c
> > index 1533aebafb68..d40a8ff23370 100644
> > --- a/mm/mm_init.c
> > +++ b/mm/mm_init.c
> > @@ -817,22 +817,39 @@ void __meminit init_deferred_page(unsigned long
> pfn, int nid)
> > * zone/node above the hole except for the trailing pages in the last
> > * section that will be appended to the zone/node below.
> > */
> > -static void __init init_unavailable_range(unsigned long spfn,
> > - unsigned long epfn,
> > - int zone, int node)
> > +static unsigned long __init init_unavailable_range(unsigned long spfn,
> > + unsigned long epfn,
> > + int zone, int node)
> > {
> > + unsigned long next_chunk_pfn __maybe_unused = spfn;
> > unsigned long pfn;
> > - u64 pgcnt = 0;
> > + u64 online_pgcnt = 0, pgcnt = 0;
> > + bool is_online = true;
> >
> > for_each_valid_pfn(pfn, spfn, epfn) {
> > __init_single_page(pfn_to_page(pfn), pfn, zone, node);
> > __SetPageReserved(pfn_to_page(pfn));
> > pgcnt++;
> > +
> > + /*
> > + * With vmemmap, at this stage all pages in an early section
> > + * have a valid memmap and are marked as online. However, only
> > + * subsections in the subsection map are actually online.
> > + */
>
> I'm having trouble parsing this comment. Shouldn't is say that some
> subsections in a section can be offline because of holes?
>
> Other than that
>
> Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>

Maybe we could add some more comments here
/*
* With vmemmap, at this stage all pages in an early section
* have a valid memmap and are marked as online. However,
* subsection-sized holes within a section are offline, only
* subsections in the subsection map are actually online.
*/

> > +#ifdef CONFIG_SPARSEMEM_VMEMMAP
> > + if (pfn >= next_chunk_pfn) {
> > + is_online = pfn_section_valid(__pfn_to_section(pfn),
> pfn);
> > + next_chunk_pfn = min(SUBSECTION_ALIGN_UP(pfn + 1),
> epfn);
> > + }
> > +#endif
> > + if (is_online)
> > + online_pgcnt++;
> > }
> >
> > if (pgcnt)
> > pr_info("On node %d, zone %s: %lld pages in unavailable
> ranges\n",
> > node, zone_names[zone], pgcnt);
> > + return online_pgcnt;
> > }
> >
> > /*
>
> --
> Sincerely yours,
> Mike.