[PATCH 08/17] mm/sparse: mark memory sections present earlier
From: Muchun Song
Date: Thu Jul 02 2026 - 06:00:52 EST
Upcoming HugeTLB bootmem changes need sparsemem section metadata before
the HugeTLB bootmem allocation path runs. The memblock ranges are marked
present from sparse_init(), which is called too late for that setup.
Move the code that marks memblock ranges present into
mm_core_init_early(), before free_area_init() and the HugeTLB bootmem
setup. Rename the helper to sparse_memblock_present() to make the new
caller describe the sparsemem-specific initialization step.
This is a preparatory change.
Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
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 8ec8b447d75e..11844b40f47a 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -960,6 +960,7 @@ void memmap_init_range(unsigned long, int, unsigned long, unsigned long,
* mm/sparse.c
*/
#ifdef CONFIG_SPARSEMEM
+void sparse_memblock_present(void);
void sparse_init(void);
int sparse_index_init(unsigned long section_nr, int nid);
@@ -997,6 +998,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 477d39ad1e9e..0256ab4ba839 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -2682,6 +2682,7 @@ void __init __weak mem_init(void)
void __init mm_core_init_early(void)
{
+ sparse_memblock_present();
free_area_init();
hugetlb_cma_reserve();
diff --git a/mm/sparse.c b/mm/sparse.c
index 3e96478a63e0..2a1a1f5e97c4 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_memblock_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