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

From: Andrew Morton

Date: Tue Sep 22 2026 - 22:01:08 EST


On Tue, 22 Sep 2026 17:07:49 +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 similarly for other hugetlb unmap paths,
> a shared mapping can pass the "PMD sharing is possible" range test in
> adjust_range_if_pmd_sharing_possible() even when the hugetlbfs file has
> never actually had any shared PMD page tables. KVM then receives a 1G
> invalidation for a 2M operation and zaps unrelated secondary mappings,
> so the guest has to fault them back in.
>
> Avoid this by remembering, per hugetlbfs inode, whether PMD sharing was
> ever established for the file. Set the flag when huge_pmd_share()
> successfully populates a shared PMD table. For the hugetlb unmap paths,
> skip the conservative PUD-sized notifier expansion while the file has
> never seen PMD sharing.
>
> The state is intentionally sticky and file-wide. Once PMD sharing has
> ever happened for the file, the unmap paths keep the existing
> conservative expansion. This avoids the no-sharing case without adding a
> page-table walk to every unmap.

Oh. It's not feasible to figure out when PMD sharing has ended and go
back to never-seen-sharing state?

> 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%.

How realistic is this test? IOW, how much benefit can people expect to
see in real-world usage?


> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -921,6 +921,9 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
> simple_inode_init_ts(inode);
> info->resv_map = resv_map;
> info->seals = F_SEAL_SEAL;
> +#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
> + info->pmd_sharing_seen = false;
> +#endif

This could use a slightly modified hugetlbfs_set_pmd_sharing_seen() and
remove the ifdefs.

hugetlbfs_set_pmd_sharing_seen(inode, false);

Not very important.