[PATCH v4 05/18] hugetlb_vmemmap: Allow architectures to dynamically disallow HVO

James Houghton jthoughton at google.com
Tue Dec 1 07:07:47 PST 2026


For arm64, only some platforms support HVO. Add an arch hook,
arch_supports_vmemmap_remap(), to prevent HVO from taking effect if the
architecture lacks support. The hook is not HugeTLB-specific, so it can
also be used by other users of in-place vmemmap remapping (e.g. FS-DAX).

Check it in hugetlb_vmemmap_optimizable_size(), so that hstates are not
reported or treated as optimizable (e.g. by report_hugepages() and the
HugeTLB allocation and freeing paths) when the architecture does not
support HVO.

It may be the case that arch_supports_vmemmap_remap() returns false at
first but eventually returns true. This is the case on arm64, where
support depends on a system-wide CPU capability that is not yet known
when bootmem hugepages are allocated. Such architectures cannot pre-HVO
bootmem hugepages, so they must disable the section-based vmemmap
optimization in their vmemmap population path with
section_vmemmap_optimization_disable(). Their bootmem hugepages are then
optimized when they are gathered instead.

Signed-off-by: James Houghton <jthoughton at google.com>
---
 include/linux/pgtable.h | 16 ++++++++++++++++
 mm/hugetlb_vmemmap.h    |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 13edae56c7e0..1ecfef54a2db 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -481,6 +481,22 @@ static inline int vmemmap_update_pte(unsigned long addr, pte_t *ptep,
 }
 #endif
 
+#ifndef arch_supports_vmemmap_remap
+/*
+ * arch_supports_vmemmap_remap - Whether in-use vmemmap mappings may be remapped.
+ *
+ * Vmemmap optimizations, such as the HugeTLB vmemmap optimization (HVO),
+ * remap vmemmap page table entries while they are in use. Architectures that
+ * can only do this under certain runtime conditions may override
+ * this hook. It may return false early during boot and true later. Once
+ * it becomes true, it must not start returning false.
+ */
+static inline bool arch_supports_vmemmap_remap(void)
+{
+	return IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION);
+}
+#endif
+
 #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
 extern int ptep_set_access_flags(struct vm_area_struct *vma,
 				 unsigned long address, pte_t *ptep,
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index 8b28063d78cc..5d4ad1b1d423 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -48,6 +48,8 @@ static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate
 
 	if (!is_power_of_2(sizeof(struct page)))
 		return 0;
+	if (!arch_supports_vmemmap_remap())
+		return 0;
 	return size > 0 ? size : 0;
 }
 #else
-- 
2.56.1.839.g22a8290db9-goog




More information about the linux-arm-kernel mailing list