From: Breno Leitao <leitao@debian.org>
To: Guillaume Morin <guillaume@morinfr.org>,
osalvador@suse.de, avid@kernel.org
Cc: linux-mm@kvack.org, riel@surriel.com,
Muchun Song <muchun.song@linux.dev>
Subject: Re: [BUG] mm/hugetlb: possible temporary resv underflow
Date: Mon, 13 Jul 2026 02:43:06 -0700 [thread overview]
Message-ID: <alSyhslcItgtqSHT@gmail.com> (raw)
In-Reply-To: <alEJkwn5VlTTH_ZX@bender.morinfr.org>
Hi Guillaume,
On Fri, Jul 10, 2026 at 05:02:43PM +0200, Guillaume Morin wrote:
> Hi,
>
> We've encountered a temporary underflow in the reserved count after a fork when
> a parent unmaps a faulted hugetlb page before a child process.
>
> After a reservation is consumed (i.e the page is faulted), if there is a fork()
> and the parent munmaps the page before the child, the reserved count
> underflows. The count is restored when the child unmaps the page/exits. I have
> reproduced the issue in 6.12.95 and 6.18.38. I believe it's still present in
> 7.2-rc2 but didn't try to reproduce.
Thanks for the detailed report and the reproducer.
I reproduced the underflow on current linux-next (7.2.0-rc2-next-20260710)
with your program — it fires on every run. I also confirmed your
folio_mapcount() == 0 check fixes it: with it applied the underflow is gone
across many runs, and the existing hugetlb reservation selftests still pass.
> The patch that seems to have introduced the issue is df7a6d1f6405, "mm/hugetlb:
> restore the reservation if needed"
>
> I am not sure what the best fix is but checking folio_mapcount() == 0
> in __unmap_hugepage_range() seems to do the trick
>
> adjust_reservation = false;
>
> spin_lock_irq(&hugetlb_lock);
> if (!h->surplus_huge_pages && __vma_private_lock(vma) &&
> - folio_test_anon(folio)) {
> + folio_test_anon(folio) &&
> + folio_mapcount(folio) == 0) {
> folio_set_hugetlb_restore_reserve(page_folio(page));
> /* Reservation to be adjusted after the spin lock */
> adjust_reservation = true;
The fix looks correct to me.
> Reproducer (it only works if HugePages_Rsvd is 0 at the beginning of the test)
Would you be up for turning your reproducer into an expansion of the selftest
I've added a while ago for the fix I've added a while ago:
tools/testing/selftests/mm/hugetlb_madv_vs_map.c
Your case is a nice complement to it, so it'd be great to have it there.
prev parent reply other threads:[~2026-07-13 9:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 15:02 [BUG] mm/hugetlb: possible temporary resv underflow Guillaume Morin
2026-07-13 9:43 ` Breno Leitao [this message]
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=alSyhslcItgtqSHT@gmail.com \
--to=leitao@debian.org \
--cc=avid@kernel.org \
--cc=guillaume@morinfr.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox