Re: [PATCH v6] page_alloc: allow migration of smaller hugepages during contig_alloc

From: Gregory Price

Date: Fri Dec 19 2025 - 15:57:04 EST


On Fri, Dec 19, 2025 at 03:46:25PM -0500, Zi Yan wrote:
> On 19 Dec 2025, at 9:26, Gregory Price wrote:
>
> > Will think about this for a bit.
>
> The sole caller of pfn_range_valid_contig(), alloc_contig_pages_noprof(),
> scans from the beginning of a zone to the end. pfn_range_valid_contig()
> should see head pages all the time, except it scans in the middle of
> a 1GB hugetlb when alloc_contig_pages_noprof() is asking for a smaller
> nr_pages, like 2MB. But in that case, the if above i += (1 << order) - 1
> would return false without reaching it. Basically, to get to
> i += ..., pfn_range_valid_contig() needs to search for nr_pages larger
> than PageHuge(page) and nr_pages is always power of two based on
> alloc_contig_pages_noprof() requirement, but that means
> pfn_range_valid_contig() always sees such PageHuge pages as a whole
> within nr_pages range, thus cannot see a tail PageHuge page at the
> point of i += ....
>

right, and we hold the zone lock here, so we shouldn't see a page
suddenly become a tail page mid-iteration.

I hadn't mentally worked through whether it was a good idea to encode
this behavior now with only one user - but i suppose there's no point in
optimizing for code that doesn't exist, so i agree. This does seem
fine.

Thanks!
Gregory