On Fri, Apr 14, 2023 at 01:22:06PM +0100, Matthew Wilcox wrote: > 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. Given the calling context is a linear scan, the head page will be scanned first so the value for compound_nr() called on a tail page shouldn't occur. > 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? > For now I only want hugetlbfs pages as the fix is for a regression when allocating 1G hugetlbfs pages and previous behaviour avoided existing hugetlbfs pages. THP pages can be split+migrated of course but the cost of the 1G allocation attempt may be excessive relative to any benefit. -- Mel Gorman SUSE Labs