Even if HVO is enabled, architectures may at run-time determine that it cannot be used. 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(), part of hugetlb_init(). Signed-off-by: James Houghton --- 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 e1a2e1b7c8e7..c4796c54b702 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) +{ + 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 3951c043164a..21377f795293 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -17,6 +17,7 @@ #include #include +#include "linux/hugetlb.h" #include #include "hugetlb_vmemmap.h" #include "internal.h" @@ -556,6 +557,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; @@ -764,6 +768,14 @@ static bool vmemmap_should_optimize_bootmem_page(struct huge_bootmem_page *m) if (!READ_ONCE(vmemmap_optimize_enabled)) return false; + /* + * 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 false; + if (!hugetlb_vmemmap_optimizable(m->hstate)) return false; -- 2.55.0.795.g602f6c329a-goog