[PATCH 16/17] mm/hugetlb: localize struct huge_bootmem_page

From: Muchun Song

Date: Thu Jul 02 2026 - 06:08:17 EST


struct huge_bootmem_page is only used by hugetlb boot-time allocation
code, but its definition currently lives in mm/internal.h because
hugetlb_vmemmap_optimize_bootmem_page() takes it as an argument. This
exposes a hugetlb-specific internal type more broadly than needed.

Change hugetlb_vmemmap_optimize_bootmem_page() to take the information it
actually needs. With that interface, mm/hugetlb_vmemmap.h no longer needs
to include mm/internal.h, and struct huge_bootmem_page can move into
mm/hugetlb.c.

Make huge_page_order() take const struct hstate * as well so the new
helper interface does not need to discard constness.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
include/linux/hugetlb.h | 4 ++--
mm/hugetlb.c | 8 +++++++-
mm/hugetlb_vmemmap.c | 6 +++---
mm/hugetlb_vmemmap.h | 5 ++---
mm/internal.h | 7 -------
5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index d07dc99d8448..99fcb25cc201 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -757,7 +757,7 @@ static inline unsigned long huge_page_mask(struct hstate *h)
return h->mask;
}

-static inline unsigned int huge_page_order(struct hstate *h)
+static inline unsigned int huge_page_order(const struct hstate *h)
{
return h->order;
}
@@ -1165,7 +1165,7 @@ static inline unsigned long huge_page_mask(struct hstate *h)
return PAGE_MASK;
}

-static inline unsigned int huge_page_order(struct hstate *h)
+static inline unsigned int huge_page_order(const struct hstate *h)
{
return 0;
}
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 265d179a8929..5eae762c99d5 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -52,6 +52,12 @@
#include "hugetlb_internal.h"
#include <linux/page-isolation.h>

+struct huge_bootmem_page {
+ struct list_head list;
+ struct hstate *hstate;
+ unsigned long flags;
+};
+
int hugetlb_max_hstate __read_mostly;
unsigned int default_hstate_idx;
struct hstate hstates[HUGE_MAX_HSTATE];
@@ -3094,7 +3100,7 @@ static bool __init alloc_bootmem_huge_page(struct hstate *h, int nid)
} else {
list_add_tail(&m->list, &huge_boot_pages[nid]);
m->flags |= HUGE_BOOTMEM_ZONES_VALID;
- hugetlb_vmemmap_optimize_bootmem_page(m);
+ hugetlb_vmemmap_optimize_bootmem_page(h, m);
/*
* Only initialize the head struct page in memmap_init_reserved_pages,
* rest of the struct pages will be initialized by the HugeTLB
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index e3a200d98389..c3d4284c19fd 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -20,6 +20,7 @@

#include <asm/tlbflush.h>
#include "hugetlb_vmemmap.h"
+#include "internal.h"

/**
* struct vmemmap_remap_walk - walk vmemmap page table
@@ -708,10 +709,9 @@ void hugetlb_vmemmap_optimize_bootmem_folios(struct hstate *h, struct list_head
__hugetlb_vmemmap_optimize_folios(h, folio_list, true);
}

-void __init hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m)
+void __init hugetlb_vmemmap_optimize_bootmem_page(const struct hstate *h, void *addr)
{
- struct hstate *h = m->hstate;
- unsigned long pfn = PHYS_PFN(__pa(m));
+ unsigned long pfn = PHYS_PFN(__pa(addr));

if (!vmemmap_should_optimize(h))
return;
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index 20eb03df542a..0845575207fd 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -9,7 +9,6 @@
#ifndef _LINUX_HUGETLB_VMEMMAP_H
#define _LINUX_HUGETLB_VMEMMAP_H
#include <linux/hugetlb.h>
-#include "internal.h"

/*
* Reserve one vmemmap page, all vmemmap addresses are mapped to it. See
@@ -26,7 +25,7 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h,
void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio);
void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list);
void hugetlb_vmemmap_optimize_bootmem_folios(struct hstate *h, struct list_head *folio_list);
-void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m);
+void hugetlb_vmemmap_optimize_bootmem_page(const struct hstate *h, void *addr);

static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h)
{
@@ -77,7 +76,7 @@ static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate
return 0;
}

-static inline void hugetlb_vmemmap_optimize_bootmem_page(struct huge_bootmem_page *m)
+static inline void hugetlb_vmemmap_optimize_bootmem_page(const struct hstate *h, void *addr)
{
}
#endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */
diff --git a/mm/internal.h b/mm/internal.h
index 1348c8bb18e0..fdf40fecae57 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -23,13 +23,6 @@
#include "vma.h"

struct folio_batch;
-struct hstate;
-
-struct huge_bootmem_page {
- struct list_head list;
- struct hstate *hstate;
- unsigned long flags;
-};

/*
* Maintains state across a page table move. The operation assumes both source
--
2.54.0