Re: [PATCH] mm/hugetlb: fix overbroad MMU notifiers for unshared PMDs

From: Andrew Morton

Date: Mon Aug 31 2026 - 20:32:26 EST


On Mon, 31 Aug 2026 17:10:23 +0800 "Li Zhe" <lizhe.67@xxxxxxxxxxxxx> wrote:

> Hugetlb currently expands MMU notifier ranges to PUD boundaries whenever
> PMD sharing is possible. That is only needed when huge_pmd_unshare()
> actually detaches a shared PMD page table, because clearing the PUD
> invalidates the whole PUD-sized virtual address range.
>
> For hugetlbfs hole punch and MADV_DONTNEED, a shared mapping can pass
> the "PMD sharing is possible" range test in function
> adjust_range_if_pmd_sharing_possible() even when the PMD table covering
> the target 2M page is not shared. KVM then receives a 1G invalidation for
> a 2M operation and zaps unrelated secondary mappings, so the guest has to
> fault them back in.
>
> Fix this by using the existing cheap "sharing possible" test only as a
> gate, then inspect the candidate PMD tables under the locks held by the
> hugetlb unmap paths. The notifier is expanded only for PUDs whose PMD
> table is actually shared, while the other callers keep the existing
> conservative expansion.

Thanks.

> On a Redis-in-VM workload that punches cold 2M hugetlb pages, this
> patch improves P99 QPS stability while punching pages, reducing the QPS
> degradation ratio from 7.09% to 1.45%.

So a modest performance improvement?

This led Sashiko to perhaps discover what it considers a "critical"
pre-existing bug.

https://sashiko.dev/#/patchset/20260831091023.66581-1-lizhe.67@xxxxxxxxxxxxx