Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] mm/hugetlb: keep max_huge_pages when dissolving surplus folios
@ 2026-08-14  8:30 Longlong Xia
  2026-08-14 18:40 ` Andrew Morton
  2026-08-15  3:54 ` Muchun Song
  0 siblings, 2 replies; 3+ messages in thread
From: Longlong Xia @ 2026-08-14  8:30 UTC (permalink / raw)
  To: Muchun Song, Oscar Salvador
  Cc: David Hildenbrand, Andrew Morton, Jinjiang Tu, linux-mm,
	linux-kernel, Longlong Xia

From: Longlong Xia <xialonglong@kylinos.cn>

dissolve_free_hugetlb_folio() can remove a free folio as surplus when
its node has surplus pages.  In that case remove_hugetlb_folio()
decrements both nr_huge_pages and surplus_huge_pages, leaving the
persistent pool size unchanged.

Updating max_huge_pages as if a persistent folio had been removed can
therefore corrupt the persistent pool target and underflow it when
max_huge_pages is zero.  Keep max_huge_pages unchanged for surplus
folios, including the vmemmap restoration rollback path.

Fixes: cb402bbdabca ("mm/hugetlb: fix surplus pages in dissolve_free_huge_page()")
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Longlong Xia <xialonglong@kylinos.cn>
---
 mm/hugetlb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e93c4d2456aa..2239e2566a52 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2002,7 +2002,8 @@ int dissolve_free_hugetlb_folio(struct folio *folio)
 		if (h->surplus_huge_pages_node[folio_nid(folio)])
 			adjust_surplus = true;
 		remove_hugetlb_folio(h, folio, adjust_surplus);
-		h->max_huge_pages--;
+		if (!adjust_surplus)
+			h->max_huge_pages--;
 		spin_unlock_irq(&hugetlb_lock);
 
 		/*
@@ -2022,7 +2023,8 @@ int dissolve_free_hugetlb_folio(struct folio *folio)
 			if (rc) {
 				spin_lock_irq(&hugetlb_lock);
 				add_hugetlb_folio(h, folio, adjust_surplus);
-				h->max_huge_pages++;
+				if (!adjust_surplus)
+					h->max_huge_pages++;
 				goto out;
 			}
 		} else {
-- 
2.43.0



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

* Re: [PATCH 1/1] mm/hugetlb: keep max_huge_pages when dissolving surplus folios
  2026-08-14  8:30 [PATCH 1/1] mm/hugetlb: keep max_huge_pages when dissolving surplus folios Longlong Xia
@ 2026-08-14 18:40 ` Andrew Morton
  2026-08-15  3:54 ` Muchun Song
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-08-14 18:40 UTC (permalink / raw)
  To: Longlong Xia
  Cc: Muchun Song, Oscar Salvador, David Hildenbrand, Jinjiang Tu,
	linux-mm, linux-kernel, Longlong Xia

On Fri, 14 Aug 2026 16:30:27 +0800 Longlong Xia <xialonglong2025@163.com> wrote:

> From: Longlong Xia <xialonglong@kylinos.cn>
> 
> dissolve_free_hugetlb_folio() can remove a free folio as surplus when
> its node has surplus pages.  In that case remove_hugetlb_folio()
> decrements both nr_huge_pages and surplus_huge_pages, leaving the
> persistent pool size unchanged.
> 
> Updating max_huge_pages as if a persistent folio had been removed can
> therefore corrupt the persistent pool target and underflow it when
> max_huge_pages is zero.  Keep max_huge_pages unchanged for surplus
> folios, including the vmemmap restoration rollback path.

Thanks.

> Fixes: cb402bbdabca ("mm/hugetlb: fix surplus pages in dissolve_free_huge_page()")

That's a year old, so I'm assuming there's no urgency here.  I'll 
save the fix for later and shall await maintainer input.  While at it,
please suggest whether we should backport this.

AI review might have found a couple of bugs in the surrounding code.  If true,
they look rather nasty.

	https://sashiko.dev/#/patchset/20260814083027.1419487-1-xialonglong2025@163.com




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

* Re: [PATCH 1/1] mm/hugetlb: keep max_huge_pages when dissolving surplus folios
  2026-08-14  8:30 [PATCH 1/1] mm/hugetlb: keep max_huge_pages when dissolving surplus folios Longlong Xia
  2026-08-14 18:40 ` Andrew Morton
@ 2026-08-15  3:54 ` Muchun Song
  1 sibling, 0 replies; 3+ messages in thread
From: Muchun Song @ 2026-08-15  3:54 UTC (permalink / raw)
  To: Longlong Xia
  Cc: Oscar Salvador, David Hildenbrand, Andrew Morton, Jinjiang Tu,
	linux-mm, linux-kernel, Longlong Xia



> On Aug 14, 2026, at 16:30, Longlong Xia <xialonglong2025@163.com> wrote:
> 
> From: Longlong Xia <xialonglong@kylinos.cn>
> 
> dissolve_free_hugetlb_folio() can remove a free folio as surplus when
> its node has surplus pages.  In that case remove_hugetlb_folio()
> decrements both nr_huge_pages and surplus_huge_pages, leaving the
> persistent pool size unchanged.
> 
> Updating max_huge_pages as if a persistent folio had been removed can
> therefore corrupt the persistent pool target and underflow it when
> max_huge_pages is zero.  Keep max_huge_pages unchanged for surplus
> folios, including the vmemmap restoration rollback path.
> 
> Fixes: cb402bbdabca ("mm/hugetlb: fix surplus pages in dissolve_free_huge_page()")
> Assisted-by: Codex:gpt-5.6-sol
> Signed-off-by: Longlong Xia <xialonglong@kylinos.cn>

Reviewed-by: Muchun Song <muchun.song@linux.dev>

Thanks.



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

end of thread, other threads:[~2026-08-15  3:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14  8:30 [PATCH 1/1] mm/hugetlb: keep max_huge_pages when dissolving surplus folios Longlong Xia
2026-08-14 18:40 ` Andrew Morton
2026-08-15  3:54 ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox