* [PATCH] mm/hugetlb: fix subpool accounting after cgroup charge failure
@ 2026-04-27 14:52 Catherine
2026-04-27 15:12 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Catherine @ 2026-04-27 14:52 UTC (permalink / raw)
To: Andrew Morton
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, linux-mm,
linux-kernel, Catherine
alloc_hugetlb_folio() calls hugepage_subpool_get_pages() when map_chg
is set. For subpools with max_hpages, that increments used_hpages even
when the returned gbl_chg is positive.
If a later hugetlb cgroup charge fails, the cleanup currently calls
hugepage_subpool_put_pages() only for !gbl_chg. The gbl_chg > 0 path
therefore leaks one used_hpages charge per failure.
Always undo the subpool charge after a successful subpool get. Keep the
global reservation accounting under !gbl_chg, because only that path
consumed a reservation from the subpool.
Signed-off-by: Catherine <enderaoelyther@gmail.com>
---
mm/hugetlb.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index f24bf49be..b3ad024a0 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3026,12 +3026,14 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
h_cg);
out_subpool_put:
/*
- * put page to subpool iff the quota of subpool's rsv_hpages is used
- * during hugepage_subpool_get_pages.
+ * map_chg means hugepage_subpool_get_pages() succeeded above.
+ * Always undo the subpool quota charge; only drop global reservation
+ * accounting if the subpool consumed a reservation.
*/
- if (map_chg && !gbl_chg) {
+ if (map_chg) {
gbl_reserve = hugepage_subpool_put_pages(spool, 1);
- hugetlb_acct_memory(h, -gbl_reserve);
+ if (!gbl_chg)
+ hugetlb_acct_memory(h, -gbl_reserve);
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] mm/hugetlb: fix subpool accounting after cgroup charge failure
2026-04-27 14:52 [PATCH] mm/hugetlb: fix subpool accounting after cgroup charge failure Catherine
@ 2026-04-27 15:12 ` Andrew Morton
2026-04-27 15:19 ` Catherine
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-04-27 15:12 UTC (permalink / raw)
To: Catherine
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, linux-mm,
linux-kernel
On Mon, 27 Apr 2026 22:52:48 +0800 Catherine <enderaoelyther@gmail.com> wrote:
> alloc_hugetlb_folio() calls hugepage_subpool_get_pages() when map_chg
> is set. For subpools with max_hpages, that increments used_hpages even
> when the returned gbl_chg is positive.
>
> If a later hugetlb cgroup charge fails, the cleanup currently calls
> hugepage_subpool_put_pages() only for !gbl_chg. The gbl_chg > 0 path
> therefore leaks one used_hpages charge per failure.
>
> Always undo the subpool charge after a successful subpool get. Keep the
> global reservation accounting under !gbl_chg, because only that path
> consumed a reservation from the subpool.
Thanks.
We do prefer full, real names for kernel alterations. Can you please
provide that?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-27 21:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 14:52 [PATCH] mm/hugetlb: fix subpool accounting after cgroup charge failure Catherine
2026-04-27 15:12 ` Andrew Morton
2026-04-27 15:19 ` Catherine
2026-04-27 21:12 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox