Re: [PATCH 06/11] mm/hugetlb: Remove fake head pages

Kiryl Shutsemau
2025-12-08T10:40:43Z

On Sat, Dec 06, 2025 at 05:03:25PM +0000, Usama Arif wrote:
> > @@ -518,7 +519,24 @@ static bool vmemmap_should_optimize_folio(const struct hstate *h, struct folio *
> > return true;
> > }
> >
> > -static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,
> > +static void hugetlb_vmemmap_tail_alloc(struct hstate *h)
> > +{
> > + struct page *p;
> > +
> > + if (h->vmemmap_tail)
> > + return;
> > +
>
> The above check is unnecessary as we already check for
> !h->vmemmap_tail in __hugetlb_vmemmap_optimize_folio?

Right. I will streamline this codepath.

> Is it possible that we could have a race here? Where 2 threads both
> trying to allocate a hugetlb page when none exist in the system, both
> see h->vmemmap_tail == NULL, both call alloc_page and set
> h->vmemmap_tail?

Good catch. Will fix. I guess, serializing h-vmemmap_tail with
hugetlb_lock should be good enough.

> Also, is there a good point where we can see that the number of
> hstate->nr_huge_pages has gone down to 0 and free
> h->vmemmap_tail? Its a single page per hstate so not a big deal, but
> would be nice to have cleanup for it?

I didn't want to go to this complexity, but if you folks think that it
is needed, sure, can do.

--
Kiryl Shutsemau / Kirill A. Shutemov