Re: [PATCH v2 3/4] mm: hugetlb: Fix subpool usage leak on allocation failure

From: Andrew Morton

Date: Wed Sep 09 2026 - 19:01:12 EST


On Wed, 09 Sep 2026 14:49:28 -0700 Ackerley Tng via B4 Relay <devnull+ackerleytng.google.com@xxxxxxxxxx> wrote:

> From: Ackerley Tng <ackerleytng@xxxxxxxxxx>
>
> When folio allocation fails early (e.g. buddy allocation failure or
> cgroup charging failure) and a reservation was not used (meaning an
> unreserved global page was needed), the subpool page acquired during the
> allocation attempt must still be returned.
>
> Currently, the subpool cleanup error path only returns the page to the
> subpool if a reservation was used. If no reservation was used, it skips
> releasing the page back to the subpool, permanently leaking the subpool's
> used pages counter.
>
> With subpools now always tracking used pages, always release the page
> back to the subpool whenever a subpool page was acquired.
>
> Opportunistically rename the local variables tracking global reservations
> needed and global reservations returned. This clarifies the accounting:
> a value of zero for needed global reservations indicates an existing
> reservation satisfies the allocation, while a non-zero value indicates
> new global pages are required.
>
> Adjust global reservations using the difference between reservations
> needed and reservations returned to properly handle races where concurrent
> threads interact with the same subpool.

This one conflicts with "mm/hugetlb: fix max-only subpool accounting on
alloc_hugetlb_folio failure".
https://lore.kernel.org/20260428113037.88766-2-enderaoelyther@xxxxxxxxx.


> @@ -3074,13 +3074,10 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
> return folio;
>
> out_subpool_put:
> - /*
> - * put page to subpool iff the quota of subpool's rsv_hpages is used
> - * during hugepage_subpool_get_pages.
> - */
> - if (map_chg && !gbl_chg) {
> - gbl_reserve = hugepage_subpool_put_pages(spool, 1);
> - hugetlb_acct_memory(h, -gbl_reserve);
> + if (map_chg) {
> + long gbl_resv_put = hugepage_subpool_put_pages(spool, 1);
> +
> + hugetlb_acct_memory(h, gbl_resv_get - gbl_resv_put);
> }
>
> out_end_reservation:

Here.

I presently have Zhao Li's patch staged in mm.git's
mm-hotfixes-unstable branch, awaiting review.

What to do?