Re: [PATCH v3] mm/hugetlb: update nr_huge_pages and surplus_huge_pages together

From: Andrew Morton
Date: Wed Apr 02 2025 - 23:53:11 EST


On Tue, 1 Apr 2025 16:12:29 +0800 Liu Shixin <liushixin2@xxxxxxxxxx> wrote:

> > + /*
> > + * nr_huge_pages needs to be adjusted within the same lock cycle
> > + * as surplus_pages, otherwise it might confuse
> > + * persistent_huge_pages() momentarily.
> > + */
> > + __prep_account_new_huge_page(h, nid);
> > +
> > /*
> > * We could have raced with the pool size change.
> > * Double check that and simply deallocate the new page
>
> Hi,
>
> Sorry, there's a mistake that the nid may be mismatch.
> Please use the following code to fix it, or should I send a fix patch ?
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 39f92aad7bd1..6670f9b9e07a 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -2271,7 +2271,7 @@ static struct folio *alloc_surplus_hugetlb_folio(struct hstate *h,
> * as surplus_pages, otherwise it might confuse
> * persistent_huge_pages() momentarily.
> */
> - __prep_account_new_huge_page(h, nid);
> + __prep_account_new_huge_page(h, folio_nid(folio));
>
> /*
> * We could have raced with the pool size change.

Yes, please send a formal patch, with

Fixes: 2273dea6b1e1 ("mm/hugetlb: update nr_huge_pages and surplus_huge_pages together")