[PATCH] fixup! mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION

Muchun Song posted 1 patch 1 week, 1 day ago
drivers/dax/Kconfig | 2 --
mm/Kconfig          | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
[PATCH] fixup! mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION
Posted by Muchun Song 1 week, 1 day ago
The section-based vmemmap optimization infrastructure is guarded by
CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP, but it can also be used by
ZONE_DEVICE users that set dev_pagemap::vmemmap_shift. Introduce
CONFIG_VMEMMAP_OPTIMIZATION as a common config for the shared
infrastructure.

Select the new option from HUGETLB_PAGE_OPTIMIZE_VMEMMAP and from
ZONE_DEVICE when the architecture opts in to DAX vmemmap optimization,
and use it to guard the generic sparse-vmemmap state and helpers.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Qi Zheng <qi.zheng@linux.dev>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
Note: When folding this fix into
"mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION",
please use this commit message for the resulting patch.

v5:
- Select VMEMMAP_OPTIMIZATION from ZONE_DEVICE instead of DEV_DAX,
  covering all users of dev_pagemap::vmemmap_shift, reported by
  Sashiko.
- Drop the DEV_DAX dependency on ZONE_DEVICE added in v2, as it is
  no longer needed by this patch.

v4:
- Rename SPARSEMEM_VMEMMAP_OPTIMIZATION to VMEMMAP_OPTIMIZATION
  (suggested by Mike Rapoport)
- Collect Acked-by from Mike Rapoport

v2:
- Fix SPARSEMEM_VMEMMAP_OPTIMIZATION being selected without
  SPARSEMEM_VMEMMAP, reported by Sashiko.
- Add an explicit DEV_DAX dependency on ZONE_DEVICE
- Collect Acked-by from Qi Zheng
---
 drivers/dax/Kconfig | 2 --
 mm/Kconfig          | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index f50c6b32d826..602f9a0839a9 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -8,8 +8,6 @@ if DAX
 config DEV_DAX
 	tristate "Device DAX: direct access mapping device"
 	depends on TRANSPARENT_HUGEPAGE
-	depends on ZONE_DEVICE
-	select VMEMMAP_OPTIMIZATION if ARCH_WANT_OPTIMIZE_DAX_VMEMMAP
 	help
 	  Support raw access to differentiated (persistence, bandwidth,
 	  latency...) memory via an mmap(2) capable character
diff --git a/mm/Kconfig b/mm/Kconfig
index 0fa2eb76e4f2..30170a936f1f 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1224,6 +1224,7 @@ config ZONE_DMA32
 config ZONE_DEVICE
 	bool "Device memory (pmem, HMM, etc...) hotplug support"
 	depends on MEMORY_HOTREMOVE
+	select VMEMMAP_OPTIMIZATION if ARCH_WANT_OPTIMIZE_DAX_VMEMMAP
 	select XARRAY_MULTI
 
 	help
-- 
2.54.0
Re: [PATCH] fixup! mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION
Posted by Muchun Song 1 week, 1 day ago

> On Sep 16, 2026, at 16:36, Muchun Song <songmuchun@bytedance.com> wrote:
> 
> The section-based vmemmap optimization infrastructure is guarded by
> CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP, but it can also be used by
> ZONE_DEVICE users that set dev_pagemap::vmemmap_shift. Introduce
> CONFIG_VMEMMAP_OPTIMIZATION as a common config for the shared
> infrastructure.
> 
> Select the new option from HUGETLB_PAGE_OPTIMIZE_VMEMMAP and from
> ZONE_DEVICE when the architecture opts in to DAX vmemmap optimization,
> and use it to guard the generic sparse-vmemmap state and helpers.
> 
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> Acked-by: Qi Zheng <qi.zheng@linux.dev>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> Note: When folding this fix into
> "mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION",
> please use this commit message for the resulting patch.

Hi Andrew,

Sashiko found a configuration issue in patch 1 [1].

MSHV_VTL sets a non-zero dev_pagemap::vmemmap_shift for VTL0
memory. However, VMEMMAP_OPTIMIZATION is currently selected only by
DEV_DAX or HUGETLB_PAGE_OPTIMIZE_VMEMMAP.

With ZONE_DEVICE=y and MSHV_VTL=y, but DEV_DAX=n and
HUGETLB_PAGE=n, VMEMMAP_OPTIMIZATION is therefore disabled.
__vmemmap_can_optimize() always returns false in this configuration,
so VTL0 memory uses an unoptimized vmemmap despite its non-zero
vmemmap_shift. On common x86-64 configurations, this can consume up
to about 1.5% of the mapped VTL0 memory for vmemmap metadata.

The report is correct. The fixup in the parent message moves the
conditional selection of VMEMMAP_OPTIMIZATION from DEV_DAX to
ZONE_DEVICE. This covers every ZONE_DEVICE user that sets
dev_pagemap::vmemmap_shift while retaining the architecture opt-in
through ARCH_WANT_OPTIMIZE_DAX_VMEMMAP.

It also removes the DEV_DAX dependency on ZONE_DEVICE that patch 1
added solely to satisfy the Kconfig dependency of
VMEMMAP_OPTIMIZATION.

Andrew, could you please fold this fixup into patch 1,

"mm/sparse-vmemmap: introduce CONFIG_VMEMMAP_OPTIMIZATION"?

[1] https://sashiko.dev/#/patchset/20260916064341.1825793-1-songmuchun%40bytedance.com

Thanks,
Muchun