Re: [PATCH v2 06/20] hugetlb_vmemmap: Allow architectures to dynamically disallow HVO
From: Muchun Song
Date: Sat Nov 07 2026 - 01:44:28 EST
> On Oct 3, 2026, at 08:21, James Houghton <jthoughton@xxxxxxxxxx> wrote:
>
> For arm64, only some platforms support HVO. Add an arch hook to prevent
> HVO from taking affect if the architecture lacks support.
>
> It may be the case that arch_supports_hugetlb_vmemmap_optimization()
> returns false at first but eventually returns true. This is the case on
> arm64. When this happens, bootmem hugepages won't be immediately HVOed,
> but they will be optimized in prep_and_add_bootmem_folios().
>
> Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
> ---
> include/asm-generic/hugetlb.h | 7 +++++++
> mm/hugetlb_vmemmap.c | 12 ++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h
> index 635c41cc3479..8d24075d53d4 100644
> --- a/include/asm-generic/hugetlb.h
> +++ b/include/asm-generic/hugetlb.h
> @@ -128,4 +128,11 @@ static inline bool gigantic_page_runtime_supported(void)
> }
> #endif /* __HAVE_ARCH_GIGANTIC_PAGE_RUNTIME_SUPPORTED */
>
> +#ifndef __HAVE_ARCH_HVO_SUPPORTED
> +static inline bool arch_hugetlb_vmemmap_optimization_supported(void)
I suggest using arch_support_vmemmap_remap (see [1]), which can also be
applied to FS-DAX.
[1] https://lore.kernel.org/all/20260903122128.12264-2-songmuchun@xxxxxxxxxxxxx/
> +{
> + return IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP);
> +}
> +#endif /* __HAVE_ARCH_HVO_SUPPORTED */
> +
> #endif /* _ASM_GENERIC_HUGETLB_H */
> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
> index 3fdb1e4ce1a1..8596a462fee6 100644
> --- a/mm/hugetlb_vmemmap.c
> +++ b/mm/hugetlb_vmemmap.c
> @@ -16,6 +16,7 @@
> #include <linux/pagewalk.h>
> #include <linux/pgalloc.h>
> #include <linux/vmemmap-optimization.h>
> +#include <linux/hugetlb.h>
>
> #include <asm/tlbflush.h>
> #include "hugetlb_vmemmap.h"
> @@ -529,6 +530,9 @@ static bool vmemmap_should_optimize_folio(const struct hstate *h, struct folio *
> if (!READ_ONCE(vmemmap_optimize_enabled))
> return false;
>
> + if (!arch_hugetlb_vmemmap_optimization_supported())
> + return false;
> +
> if (!hugetlb_vmemmap_optimizable(h))
> return false;
>
> @@ -731,6 +735,14 @@ void __init hugetlb_vmemmap_optimize_bootmem_page(unsigned long pfn, unsigned in
> if (!READ_ONCE(vmemmap_optimize_enabled))
> return;
>
> + /*
> + * Architectures may return false here but true by the time
> + * hugetlb_init() is called. In this case, although the folios will
> + * not be pre-HVOed, they will be optimized in hugetlb_init().
> + */
> + if (!arch_hugetlb_vmemmap_optimization_supported())
> + return;
I plan to add a new helper, section_vmemmap_optimization_disable() [2],
intended to disable vmemmap optimization in the architectural vmemmap
population path. Since arm64 does not support section-based vmemmap
optimization, section_vmemmap_optimization_disable() should be used there.
[2] https://lore.kernel.org/all/20261107043122.25650-3-songmuchun@xxxxxxxxxxxxx/
Thanks,
Muchun
> +
> section_set_compound_order_range(pfn, 1UL << order, order);
> }
>
> --
> 2.56.0.rc1.315.gc6ed9934b7-goog
>