Boot-time gigantic hugetlb folios open-code the frozen compound struct page initialization across two helpers. Use memmap_init_compound_page_frozen() and remove the open-coded helpers. This keeps the initialization rules shared with ZONE_DEVICE instead of maintaining two implementations. No functional change is intended. Signed-off-by: Muchun Song --- mm/hugetlb.c | 65 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 2716a83a7386..6ee36ca5f435 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3249,63 +3249,6 @@ static bool __init alloc_bootmem_huge_page(struct hstate *h, int nid) return true; } -/* Initialize [start_page:end_page_number] tail struct pages of a hugepage */ -static void __init hugetlb_folio_init_tail_vmemmap(struct folio *folio, - struct hstate *h, - unsigned long start_page_number, - unsigned long end_page_number) -{ - enum zone_type zone = folio_zonenum(folio); - int nid = folio_nid(folio); - struct page *page = folio_page(folio, start_page_number); - struct page template; - unsigned long head_pfn = folio_pfn(folio); - unsigned long pfn, end_pfn = head_pfn + end_page_number; - unsigned int order = huge_page_order(h); - - /* - * As we marked all tail pages with memblock_reserved_mark_noinit(), - * we must initialize them ourselves here. - */ - if (start_page_number >= end_page_number) - return; - - pfn = head_pfn + start_page_number; - - /* - * Seed a template from the first real tail page and refresh only - * PFN-dependent fields before copying it. - */ - __init_single_page(page, pfn, zone, nid); - prep_compound_tail(page, &folio->page, order); - set_page_count(page, 0); - memcpy(&template, page, sizeof(template)); - - for (pfn++; pfn < end_pfn; pfn++) - memmap_init_page_from_template(pfn_to_page(pfn), pfn, - folio_zone(folio), &template); -} - -static void __init hugetlb_folio_init_vmemmap(struct folio *folio, - unsigned long pfn, - struct hstate *h, - enum zone_type zone, int nid, - unsigned long nr_pages) -{ - struct page *head = &folio->page; - - /* - * This is an open-coded prep_compound_page() whereby we avoid - * walking pages twice by initializing/preparing+freezing them in the - * same go. - */ - __init_single_page(head, pfn, zone, nid); - __folio_set_head(folio); - set_page_count(head, 0); - hugetlb_folio_init_tail_vmemmap(folio, h, 1, nr_pages); - prep_compound_head(head, huge_page_order(h)); -} - /* * memblock-allocated pageblocks might not have the migrate type set * if marked with the 'noinit' flag. Set it to the default (MIGRATE_MOVABLE) @@ -3363,8 +3306,7 @@ static void __init gather_bootmem_prealloc_node(unsigned long nid) struct folio *folio = (void *)page; const unsigned long pfn = PHYS_PFN(__pa(m)); const unsigned long nr_pages = pages_per_huge_page(m->hstate); - const enum zone_type zone = zone_idx(pfn_to_zone(pfn, nid)); - unsigned long nr_struct_pages = nr_pages; + const struct zone *zone = pfn_to_zone(pfn, nid); h = m->hstate; /* @@ -3376,10 +3318,7 @@ static void __init gather_bootmem_prealloc_node(unsigned long nid) prev_h = h; VM_BUG_ON(!hstate_is_gigantic(h)); - - if (vmemmap_optimizable_order(pfn_to_section_compound_order(pfn))) - nr_struct_pages = VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; - hugetlb_folio_init_vmemmap(folio, pfn, h, zone, nid, nr_struct_pages); + memmap_init_compound_page_frozen(page, pfn, zone, huge_page_order(h)); init_new_hugetlb_folio(folio); if (vmemmap_optimizable_order(pfn_to_section_compound_order(pfn))) -- 2.54.0