Re: [PATCH] mm: page_alloc: Assume huge tail pages are valid when allocating contiguous pages

From: Matthew Wilcox
Date: Fri Apr 14 2023 - 08:22:37 EST


On Fri, Apr 14, 2023 at 09:22:22AM +0100, Mel Gorman wrote:
> + /*
> + * Do not migrate huge pages that span the size of the region
> + * being allocated contiguous. e.g. Do not migrate a 1G page
> + * for a 1G allocation request. CMA is an exception as the
> + * region may be reserved for hardware that requires physical
> + * memory without a MMU or scatter/gather capability.
> + *
> + * Note that the compound check is race-prone versus
> + * free/split/collapse but it should be safe and result in
> + * a premature skip or a useless migration attempt.
> + */
> + if (PageHuge(page) && compound_nr(page) >= nr_pages &&

This confuses me. PageHuge() can be called on tail pages, but if
compound_nr() is called on a tail page, it returns 1. So I'm not
sure why this works. Also, do you really want PageHuge (ie only
hugetlbfs pages), or do you really just want to check PageCompound(),
which would also be true for THP?