Re: [PATCH v5 1/3] mm/page_alloc: Optimize free_contig_range()
From: Vlastimil Babka (SUSE)
Date: Wed Apr 01 2026 - 06:13:40 EST
On 4/1/26 11:59, David Hildenbrand (Arm) wrote:
>>> +
>>> + for (i = 0; i < nr_pages; i++) {
>>> + bool can_free = true;
>>> +
>>> + /*
>>> + * Contiguous PFNs might not have contiguous "struct pages"
>>> + * in some kernel configs: page++ across a section boundary
>>> + * is undefined. Use pfn_to_page() for each PFN.
>>> + */
>>> + page = pfn_to_page(pfn + i);
>>
>> Hm ideally we'd have some pfn+page iterator thingy that would just do a
>> page++ on configs where it's contiguous and this more expensive operation
>> otherwise. Wonder why we don't have it yet. But that's for a possible
>> followup, not required now.
>
> pfn_to_page() is on relevant configs close to just a "page + i". Not
> entirely, but I am not sure if the micro-gain would really be worth it.
>
> E.g., on CONFIG_SPARSEMEM_VMEMMAP
>
> #define __pfn_to_page(pfn) vmemmap + (pfn)
Oh I see. Yeah agree not worth it. The compiler can probably turn it to
page++ already then.
>
> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>