From: Guillaume Morin <guillaume@morinfr.org>
To: linux-mm@kvack.org
Cc: muchun.song@linux.dev, leitao@debian.org,
Rik van Riel <riel@surriel.com>
Subject: [PATCH] hugetlb: only adjust reservation during unmapping if mapcount is 0
Date: Wed, 15 Jul 2026 15:57:13 +0200 [thread overview]
Message-ID: <aleRuVBaWu6eTCJb@bender.morinfr.org> (raw)
Since df7a6d1f6405, __unmap_hugepage_range can adjust reservations. In
the case of folio mapped in both a parent and a child, if the parent
unmaps the range first, the reservation adjustment will result in
an underflow of the reserved count. Once the child unmaps the range, the
count is restored.
This patch changes __unmap_hugepage_range() so it now checks the
mapcount before adjusting the reservation.
Link: https://lore.kernel.org/all/alEJkwn5VlTTH_ZX@bender.morinfr.org/
Fixes: df7a6d1f6405 ("mm/hugetlb: restore the reservation if needed")
Signed-off-by: Guillaume Morin <guillaume@morinfr.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Breno Leitao <leitao@debian.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: <stable@vger.kernel.org>
---
mm/hugetlb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 571212b80835..c0167a09a0c4 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5252,7 +5252,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
spin_lock_irq(&hugetlb_lock);
if (!h->surplus_huge_pages && __vma_private_lock(vma) &&
- folio_test_anon(folio)) {
+ folio_mapcount(folio) == 0 && folio_test_anon(folio)) {
folio_set_hugetlb_restore_reserve(folio);
/* Reservation to be adjusted after the spin lock */
adjust_reservation = true;
--
2.39.1
--
Guillaume Morin <guillaume@morinfr.org>
reply other threads:[~2026-07-15 13:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aleRuVBaWu6eTCJb@bender.morinfr.org \
--to=guillaume@morinfr.org \
--cc=leitao@debian.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=riel@surriel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.