Later patches need struct mem_section entries to be available before HugeTLB bootmem allocation starts, so the section metadata can be set up at that stage.
Move the memblock-based section present marking out of sparse_init() and call it earlier from mm_core_init_early(). Rename the helper to sparse_memblocks_present() while doing so. This prepares sparsemem section metadata before the early HugeTLB setup path. Signed-off-by: Muchun Song <[email protected]> --- mm/internal.h | 2 ++ mm/mm_init.c | 1 + mm/sparse.c | 4 +--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 2defdef1aedf..bf30617c78d8 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -962,6 +962,7 @@ void memmap_init_range(unsigned long, int, unsigned long, unsigned long, * mm/sparse.c */ #ifdef CONFIG_SPARSEMEM +void sparse_memblocks_present(void); void sparse_init(void); int sparse_index_init(unsigned long section_nr, int nid); @@ -999,6 +1000,7 @@ static inline void __section_mark_present(struct mem_section *ms, int section_nr_vmemmap_pages(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap, struct dev_pagemap *pgmap); #else +static inline void sparse_memblocks_present(void) {} static inline void sparse_init(void) {} #endif /* CONFIG_SPARSEMEM */ diff --git a/mm/mm_init.c b/mm/mm_init.c index 3aaee1cf7bf0..6723c604eefd 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2693,6 +2693,7 @@ void __init __weak mem_init(void) void __init mm_core_init_early(void) { + sparse_memblocks_present(); free_area_init(); hugetlb_cma_reserve(); diff --git a/mm/sparse.c b/mm/sparse.c index 3e96478a63e0..33e89bf1ec0c 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -195,7 +195,7 @@ static void __init memory_present(int nid, unsigned long start, unsigned long en * This is a convenience function that is useful to mark all of the systems * memory as present during initialization. */ -static void __init memblocks_present(void) +void __init sparse_memblocks_present(void) { unsigned long start, end; int i, nid; @@ -361,8 +361,6 @@ void __init sparse_init(void) unsigned long pnum_end, pnum_begin, map_count = 1; int nid_begin; - memblocks_present(); - if (compound_info_has_mask()) { VM_WARN_ON_ONCE(!IS_ALIGNED((unsigned long) pfn_to_page(0), MAX_FOLIO_VMEMMAP_ALIGN)); -- 2.54.0
