[PATCH 26/49] mm/hugetlb: use generic vmemmap optimization macros
Muchun Song
songmuchun at bytedance.com
Sun Apr 5 22:52:17 AEST 2026
Use the generic macros OPTIMIZED_FOLIO_VMEMMAP_SIZE,
OPTIMIZED_FOLIO_VMEMMAP_PAGE_STRUCTS and OPTIMIZED_FOLIO_VMEMMAP_PAGES
instead of the hugetlb-specific HUGETLB_VMEMMAP_RESERVE_SIZE and
HUGETLB_VMEMMAP_RESERVE_PAGES to describe the vmemmap-optimized folio.
Signed-off-by: Muchun Song <songmuchun at bytedance.com>
---
mm/hugetlb.c | 4 ++--
mm/hugetlb_vmemmap.c | 14 +++++++-------
mm/hugetlb_vmemmap.h | 9 +--------
3 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index a00c9f3672b7..a7e0599802cb 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3241,7 +3241,7 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h,
* be no contention.
*/
hugetlb_folio_init_tail_vmemmap(folio, h,
- HUGETLB_VMEMMAP_RESERVE_PAGES,
+ OPTIMIZED_FOLIO_VMEMMAP_PAGE_STRUCTS,
pages_per_huge_page(h));
}
hugetlb_bootmem_init_migratetype(folio, h);
@@ -3280,7 +3280,7 @@ static void __init gather_bootmem_prealloc_node(unsigned long nid)
WARN_ON(folio_ref_count(folio) != 1);
hugetlb_folio_init_vmemmap(folio, h,
- HUGETLB_VMEMMAP_RESERVE_PAGES);
+ OPTIMIZED_FOLIO_VMEMMAP_PAGE_STRUCTS);
init_new_hugetlb_folio(folio);
if (hugetlb_bootmem_page_prehvo(m))
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index d6dd47c232e0..0af528c0e229 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -407,7 +407,7 @@ static int __hugetlb_vmemmap_restore_folio(const struct hstate *h,
vmemmap_start = (unsigned long)&folio->page;
vmemmap_end = vmemmap_start + hugetlb_vmemmap_size(h);
- vmemmap_start += HUGETLB_VMEMMAP_RESERVE_SIZE;
+ vmemmap_start += OPTIMIZED_FOLIO_VMEMMAP_SIZE;
/*
* The pages which the vmemmap virtual address range [@vmemmap_start,
@@ -637,10 +637,10 @@ static void __hugetlb_vmemmap_optimize_folios(struct hstate *h,
spfn = (unsigned long)&folio->page;
epfn = spfn + pages_per_huge_page(h);
vmemmap_wrprotect_hvo(spfn, epfn, folio_nid(folio),
- HUGETLB_VMEMMAP_RESERVE_SIZE);
+ OPTIMIZED_FOLIO_VMEMMAP_SIZE);
register_page_bootmem_memmap(pfn_to_section_nr(spfn),
&folio->page,
- HUGETLB_VMEMMAP_RESERVE_SIZE);
+ OPTIMIZED_FOLIO_VMEMMAP_SIZE);
continue;
}
@@ -791,8 +791,8 @@ void __init hugetlb_vmemmap_init_early(int nid)
zone = pfn_to_zone(nid, pfn);
BUG_ON(vmemmap_populate_hvo(start, end, huge_page_order(m->hstate),
- zone, HUGETLB_VMEMMAP_RESERVE_SIZE));
- memmap_boot_pages_add(HUGETLB_VMEMMAP_RESERVE_SIZE / PAGE_SIZE);
+ zone, OPTIMIZED_FOLIO_VMEMMAP_SIZE));
+ memmap_boot_pages_add(OPTIMIZED_FOLIO_VMEMMAP_PAGES);
pnum = pfn_to_section_nr(pfn);
ns = psize / section_size;
@@ -824,8 +824,8 @@ static int __init hugetlb_vmemmap_init(void)
const struct hstate *h;
struct zone *zone;
- /* HUGETLB_VMEMMAP_RESERVE_SIZE should cover all used struct pages */
- BUILD_BUG_ON(__NR_USED_SUBPAGE > HUGETLB_VMEMMAP_RESERVE_PAGES);
+ /* OPTIMIZED_FOLIO_VMEMMAP_SIZE should cover all used struct pages */
+ BUILD_BUG_ON(__NR_USED_SUBPAGE > OPTIMIZED_FOLIO_VMEMMAP_PAGE_STRUCTS);
for_each_zone(zone) {
for (int i = 0; i < NR_OPTIMIZABLE_FOLIO_SIZES; i++) {
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index 7ac49c52457d..66e11893d076 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -12,13 +12,6 @@
#include <linux/io.h>
#include <linux/memblock.h>
-/*
- * Reserve one vmemmap page, all vmemmap addresses are mapped to it. See
- * Documentation/mm/vmemmap_dedup.rst.
- */
-#define HUGETLB_VMEMMAP_RESERVE_SIZE PAGE_SIZE
-#define HUGETLB_VMEMMAP_RESERVE_PAGES (HUGETLB_VMEMMAP_RESERVE_SIZE / sizeof(struct page))
-
#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio);
long hugetlb_vmemmap_restore_folios(const struct hstate *h,
@@ -43,7 +36,7 @@ static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h)
*/
static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
{
- int size = hugetlb_vmemmap_size(h) - HUGETLB_VMEMMAP_RESERVE_SIZE;
+ int size = hugetlb_vmemmap_size(h) - OPTIMIZED_FOLIO_VMEMMAP_SIZE;
if (!is_power_of_2(sizeof(struct page)))
return 0;
--
2.20.1
More information about the Linuxppc-dev
mailing list