Re: [PATCH v3 05/19] hugetlb_vmemmap: Allow architectures to dynamically disallow HVO

From
James Houghton <hidden>
Date
2026-11-23 20:31:56
Also in
linux-mm, lkml
Reply to
Muchun Song, 2026-11-23
On Sun, Nov 22, 2026 at 10:01 PM Muchun Song [off-list ref] wrote:

quoted
On Nov 23, 2026, at 02:44, James Houghton [off-list ref] wrote:

For arm64, only some platforms support HVO. Add an arch hook,
arch_support_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_support_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 <redacted>
---
include/linux/pgtable.h | 15 +++++++++++++++
mm/hugetlb_vmemmap.h    |  2 ++
2 files changed, 17 insertions(+)
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index ab33df268955..8cf44120e2ed 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -480,6 +480,21 @@ static inline int try_update_vmemmap_pte(unsigned long addr, pte_t *ptep,
}
#endif

+#ifndef arch_support_vmemmap_remap
We usually add a 's' to 'support'. Like arch_supports_vmemmap_remap.
Oh yeah, I'll fix that. Thanks, Muchun!
quoted
+/*
+ * arch_support_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 on some systems may override this hook. It may return false
"Some systems" is not clear for me, How about rewrite this sentence with:

  May override this hook based on architecture-specific runtime conditions.
quoted
+ * early during boot and true later, once system-wide features are known.
I think the description should be general, so the last sentence I think should
be removed.
I think it's important to clarify that the return value can transition
from false to true, but not from true to false.

Okay how about this:
   * 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.

What do you think?

Thanks!

Thanks,
Muchun
quoted
+ */
+static inline bool arch_support_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..440477288d19 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_support_vmemmap_remap())
+             return 0;
      return size > 0 ? size : 0;
}
#else
--
2.56.1.809.ga0b61035b5-goog
  
Thread (43 messages) 43 messages, 2 authors, last reply 4d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help