Re: [PATCH v6 1/2] mm/memory_hotplug: optimize zone contiguous check when changing pfn range

From: David Hildenbrand (Arm)

Date: Wed Aug 19 2026 - 11:58:03 EST


On 8/15/26 03:55, Wei Yang wrote:
> On Tue, Aug 11, 2026 at 02:23:18PM +0200, David Hildenbrand (Arm) wrote:
>> On 8/10/26 16:04, David Hildenbrand (Arm) wrote:
>>>
>>> Thanks for reminding me. I think the right direction is to finally clean up the
>>> pfn_valid() handling.
>>>
>>> Let me take a stab at just having pfn_valid() / for_each_valid_pfn() respecting
>>> the subsection map.
>>
>> ... and that turns complicated very quickly. The problem is that we have some users,
>> in particular the buddy, that just assumes that MAX_PAGE_ORDER regions are fully
>> accessible.
>>
>> The fun begins once we have MAX_PAGE_ORDER span multiple subsections. So we'd actually
>> want to initialize the memmap.
>>
>> The pfn_valid() vs. pfn_to_online_page() inconsistency is really nasty :(
>>
>
> One thing I'd like to confirm.
>
> pfn_to_online_page() is expected to return an "online page", which is in
> buddy, right?
>
>> I mean, in init_unavailable_range() we could actually figure out fairly easily
>> whether we are dealing with holes where pfn_to_online_page() would succeed.
>>
>> diff --git a/mm/mm_init.c b/mm/mm_init.c
>> index e9c4204b73adb..54e71e17f2c3c 100644
>> --- a/mm/mm_init.c
>> +++ b/mm/mm_init.c
>> @@ -843,11 +843,13 @@ static void __init init_unavailable_range(unsigned long spfn,
>> int zone, int node)
>> {
>> unsigned long pfn;
>> - u64 pgcnt = 0;
>> + u64 pgcnt = 0, online_pgcnt = 0;
>>
>> for_each_valid_pfn(pfn, spfn, epfn) {
>> __init_single_page(pfn_to_page(pfn), pfn, zone, node);
>> __SetPageReserved(pfn_to_page(pfn));
>> + if (pfn_to_online_page(pfn))
>> + online_pgcnt++;
>
> But a hole in early section could still return a valid page if the hole
> is less than a subsection.
>
> Is this an expected behavior?

Essentially, pfn_valid() is always true for early sections.

pfn_to_online_page() is only true in only section only for parts marked in the
subsection map.

So if you have a hole that covers a subsection, it is not marked in the
subsection map, pfn_valid() would be true and for_each_valid_pfn() would iterate
it, whereby pfn_to_online_page() will reject it.

Zone shrinking will later simply skip that hole, because !pfn_to_online_page().

--
Cheers,

David