* [PATCH] hugetlb: only adjust reservation during unmapping if mapcount is 0
@ 2026-07-15 13:57 Guillaume Morin
0 siblings, 0 replies; only message in thread
From: Guillaume Morin @ 2026-07-15 13:57 UTC (permalink / raw)
To: linux-mm; +Cc: muchun.song, leitao, Rik van Riel
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>
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-15 13:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 13:57 [PATCH] hugetlb: only adjust reservation during unmapping if mapcount is 0 Guillaume Morin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox