mm/hugetlb: localize struct huge_bootmem_page

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.

Link: https://lore.kernel.org/20260910063256.64386-17-songmuchun@bytedance.com
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Qi Zheng <qi.zheng@linux.dev>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: David Laight <david.laight.linux@gmail.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
This commit is contained in:
Muchun Song 2026-09-10 14:32:55 +08:00 committed by Andrew Morton
parent eedb6c3835
commit a28e034883
4 changed files with 12 additions and 17 deletions

View File

@ -55,6 +55,12 @@
#include "sparse.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];
@ -3151,7 +3157,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(pfn, huge_page_order(h));
/*
* Only initialize the head struct page in memmap_init_reserved_pages,
* rest of the struct pages will be initialized by the HugeTLB

View File

@ -19,6 +19,7 @@
#include <asm/tlbflush.h>
#include "hugetlb_vmemmap.h"
#include "sparse.h"
#include "internal.h"
/**
* struct vmemmap_remap_walk - walk vmemmap page table
@ -705,16 +706,12 @@ 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(unsigned long pfn, unsigned int order)
{
struct hstate *h = m->hstate;
unsigned long pfn = PHYS_PFN(__pa(m));
if (!READ_ONCE(vmemmap_optimize_enabled))
return;
section_set_compound_order_range(pfn, pages_per_huge_page(h),
huge_page_order(h));
section_set_compound_order_range(pfn, 1UL << order, order);
}
static const struct ctl_table hugetlb_vmemmap_sysctls[] = {

View File

@ -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(unsigned long pfn, unsigned int order);
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(unsigned long pfn, unsigned int order)
{
}
#endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */

View File

@ -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;
};
/* mm/workingset.c */
bool workingset_test_recent(void *shadow, bool file, bool *workingset,