* [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* Re: [PATCH] mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios
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)
2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2026-11-24 5:05 UTC (permalink / raw)
To: Hongfu Li
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton,
linux-mm, Hongfu Li
> On Nov 24, 2026, at 12:41, Hongfu Li <hongfu.li@linux.dev> wrote:
>
> 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>
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Thanks
^ permalink raw reply [flat|nested] 4+ messages in thread* + mm-hugetlb-fix-nr_hugetlb-accounting-for-kept-surplus-folios.patch added to mm-new branch
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 ` Andrew Morton
2026-11-24 8:42 ` [PATCH] mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios Oscar Salvador (SUSE)
2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-11-24 5:21 UTC (permalink / raw)
To: mm-commits, osalvador, muchun.song, david, lihongfu, akpm
The patch titled
Subject: mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios
has been added to the -mm mm-new branch. Its filename is
mm-hugetlb-fix-nr_hugetlb-accounting-for-kept-surplus-folios.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-hugetlb-fix-nr_hugetlb-accounting-for-kept-surplus-folios.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Hongfu Li <lihongfu@kylinos.cn>
Subject: mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios
Date: Tue, 24 Nov 2026 12:41:02 +0800
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.
Link: https://patch.msgid.link/20261124-for-gather-surplus-v1-1-231e5660f3d8@kylinos.cn
Fixes: a11a13ebbc5d ("mm/hugetlb: account restored reservations before freeing folios")
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Muchun Song (ByteDance) <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@kernel.org>
mm/hugetlb.c | 2 ++
1 file changed, 2 insertions(+)
--- a/mm/hugetlb.c~mm-hugetlb-fix-nr_hugetlb-accounting-for-kept-surplus-folios
+++ a/mm/hugetlb.c
@@ -2489,6 +2489,8 @@ free:
* 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;
}
_
Patches currently in -mm which might be from lihongfu@kylinos.cn are
mm-hugetlb-charge-hugetlb-cgroup-and-memcg-in-alloc_hugetlb_folio_reserve.patch
selftests-mm-mlock2-tests-fix-fclosenull-in-is_vmflag_set.patch
selftests-mm-protection_keys-use-_exit-in-aarch64-ptrace-tracee.patch
mm-hugetlb-fix-nr_hugetlb-accounting-for-kept-surplus-folios.patch
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm/hugetlb: fix NR_HUGETLB accounting for kept surplus folios
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 ` Oscar Salvador (SUSE)
2 siblings, 0 replies; 4+ messages in thread
From: Oscar Salvador (SUSE) @ 2026-11-24 8:42 UTC (permalink / raw)
To: Hongfu Li
Cc: Muchun Song, Oscar Salvador, David Hildenbrand, Andrew Morton,
linux-mm, Hongfu Li
On Tue, Nov 24, 2026 at 12:41:02PM +0800, Hongfu Li wrote:
> 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>
Acked-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [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.