RE: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range
From: Liu, Yuan1
Date: Thu Aug 06 2026 - 05:53:54 EST
> -----Original Message-----
> From: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Sent: Thursday, August 6, 2026 4:46 PM
> To: Liu, Yuan1 <yuan1.liu@xxxxxxxxx>; Oscar Salvador <osalvador@xxxxxxx>;
> Mike Rapoport <rppt@xxxxxxxxxx>; Wei Yang <richard.weiyang@xxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx; Zou, Nanhai <nanhai.zou@xxxxxxxxx>; Deng, Pan
> <pan.deng@xxxxxxxxx>; Li, Tianyou <tianyou.li@xxxxxxxxx>; Chen Zhang
> <zhangchen.kidd@xxxxxx>; Zeng, Jason <jason.zeng@xxxxxxxxx>; linux-
> kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous
> check when changing pfn range
>
>
> >>> +static void __init update_zone_online_memmap_pages(struct zone *zone,
> >>> + unsigned long start_pfn,
> >>> + unsigned long end_pfn,
> >>> + unsigned long *hole_pfn)
> >>> +{
> >>> +#ifdef CONFIG_SPARSEMEM_VMEMMAP
> >>> + unsigned long zone_start_pfn = zone->zone_start_pfn;
> >>> + unsigned long zone_end_pfn = zone_start_pfn + zone->spanned_pages;
> >>
> >> These two can be const.
> >
> > Will do.
> >
> >>> + unsigned long sub_start, sub_end;
> >>> +
> >>> + sub_start = max(ALIGN_DOWN(start_pfn, PAGES_PER_SUBSECTION),
> >>> + zone_start_pfn);
> >>> + sub_end = min(ALIGN(end_pfn, PAGES_PER_SUBSECTION), zone_end_pfn);
> >>
> >> Hm, I don't immediately understand why we do the PAGES_PER_SUBSECTION
> >> thing
> >> here. Why is that required?
> >
> > pages_with_online_memmap counts all PFNs where pfn_to_online_page() is
> > valid. With CONFIG_SPARSEMEM_VMEMMAP, pfn_section_valid() operates at
> > PAGES_PER_SUBSECTION granularity — when any page in a subsection has
> > memory, the entire subsection is valid/online. So we align to subsection
> > boundaries to include hole pages within partially-populated subsections.
>
> But we must never account exceeding the zone range. So I don't understand
> why we
> would have to care about PAGES_PER_SUBSECTION here at all?
We never account beyond the zone range, because `sub_start` and
`sub_end` are still clamped to the zone boundaries after the
alignment.
The subsection alignment is needed for hole PFNs between memblocks
within the zone. These hole PFNs are valid for
`pfn_to_online_page()`, because they sit in a subsection that has
memory, so the whole subsection's memmap is online.
|----------- zone range -----------|
+-----------+---------+------------+
+ memblock 1| hole | memblock 2 |
+-----------+---------+------------+
^
|
|
subsection boundary
Best Regards,
Liu, Yuan
> --
> Cheers,
>
> David