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

From: James Houghton

Date: Mon Nov 23 2026 - 15:32:02 EST


On Sun, Nov 22, 2026 at 10:01 PM Muchun Song <muchun.song@xxxxxxxxx> wrote:
>
>
>
> > On Nov 23, 2026, at 02:44, James Houghton <jthoughton@xxxxxxxxxx> 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 <jthoughton@xxxxxxxxxx>
> > ---
> > 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!

>
> > +/*
> > + * 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.
>
> > + * 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
>
> > + */
> > +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
> >
>