[PATCH v3 06/19] hugetlb: Optimize bootmem folios that were not pre-HVOed

From: James Houghton

Date: Sun Nov 22 2026 - 13:45:28 EST


Boot-time gigantic folios are expected to be pre-HVOed through the
section-based vmemmap optimization, so the bulk optimization pass for
bootmem folios was dropped.

However, arch_support_vmemmap_remap() may not yet
return true when bootmem folios are allocated (e.g. on arm64, where
support depends on a system-wide CPU capability), while it does return
true by the time the bootmem folios are gathered. Such architectures
disable the section-based vmemmap optimization in their vmemmap
population path (see section_vmemmap_optimization_disable()), so the
folios are not pre-HVOed and would never be optimized.

Optimize such folios when gathering bootmem folios. Their tail struct
pages have all been initialized by memmap_init_compound_page(),
as they were not pre-HVOed. Pre-HVOed folios are skipped by
vmemmap_should_optimize_folio().

Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
---
mm/hugetlb.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 72839e98f998..8756c0206922 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3325,6 +3325,17 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h,
unsigned long flags;
struct folio *folio, *tmp_f;

+ /*
+ * Bootmem folios are normally pre-HVOed through the section-based
+ * vmemmap optimization. However, an architecture that can only
+ * determine whether it supports HVO after bootmem allocation disables
+ * the section-based optimization (see
+ * section_vmemmap_optimization_disable()), in which case the folios
+ * were not pre-HVOed and must be optimized now. Pre-HVOed folios are
+ * skipped.
+ */
+ hugetlb_vmemmap_optimize_folios(h, folio_list);
+
list_for_each_entry_safe(folio, tmp_f, folio_list, lru) {
/* Subdivide locks to achieve better parallel performance */
spin_lock_irqsave(&hugetlb_lock, flags);
--
2.56.1.809.ga0b61035b5-goog