All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios
@ 2026-11-24  4:41 Hongfu Li
  2026-11-24  5:05 ` Muchun Song
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hongfu Li @ 2026-11-24  4:41 UTC (permalink / raw)
  To: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton
  Cc: hongfu.li, linux-mm, Hongfu Li

From: Hongfu Li <lihongfu@kylinos.cn>

Commit a11a13ebbc5d ("mm/hugetlb: account restored reservations before
freeing folios") reworked the free path of gather_surplus_pages(): when
the pool was resized concurrently, folios that are no longer surplus
are kept and enqueued directly instead of being freed.

However, folios on the surplus list are accounted in NR_HUGETLB when
allocated in alloc_surplus_hugetlb_folio(), and every other path that
returns an already accounted folio to the free list decrements
NR_HUGETLB first, as folios on the free list must not be counted. The
new enqueue branch skips that decrement, so the folio remains counted
while on the free list, leaving NR_HUGETLB permanently overcounted by
pages_per_huge_page for each kept folio. Nothing corrects that later,
whichever path the folio takes next.

Fix this by decrementing NR_HUGETLB before enqueueing the folio, as
done in the other enqueue paths.

Fixes: a11a13ebbc5d ("mm/hugetlb: account restored reservations before freeing folios")
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
 mm/hugetlb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index d0e66fb30622..b2c14f4f99b7 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2489,6 +2489,8 @@ static int gather_surplus_pages(struct hstate *h, long delta)
 		 * count as persistent and we must keep them.
 		 */
 		if (!h->surplus_huge_pages_node[folio_nid(folio)]) {
+			mod_node_page_state(folio_pgdat(folio), NR_HUGETLB,
+					    -(long)pages_per_huge_page(h));
 			enqueue_hugetlb_folio(h, folio);
 			continue;
 		}

---
base-commit: 87cdbd9bd63174de47ba16555bfe9800a8f3da07
change-id: 20261124-for-gather-surplus-1e886c29b251

Best regards,
--  
Hongfu Li <lihongfu@kylinos.cn>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24  8:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  4:41 [PATCH] mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios Hongfu Li
2026-11-24  5:05 ` Muchun Song
2026-11-24  5:21 ` + mm-hugetlb-fix-nr_hugetlb-accounting-for-kept-surplus-folios.patch added to mm-new branch Andrew Morton
2026-11-24  8:42 ` [PATCH] mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios Oscar Salvador (SUSE)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.