[PATCH 13/49] mm: integrate sparse_vmemmap_init_nid_late() into sparse_init_nid()

Muchun Song
2026-04-05T12:54:52Z

Move the call to sparse_vmemmap_init_nid_late() from mm_core_init_early()
into sparse_init_nid().

Since sparse_init() has been deferred until after zone initialization,
the zone data structures are now available during sparse_init(). This
satisfies the requirements of sparse_vmemmap_init_nid_late(), allowing
it to be moved safely.

This change unifies the vmemmap initialization steps by placing both
sparse_vmemmap_init_nid_early() and sparse_vmemmap_init_nid_late()
within the sparse memory initialization logic, making the code structure
clearer.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/mm_init.c | 4 ----
mm/sparse.c | 2 ++
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 64363f35ad0d..7a710fcbe3c8 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -2664,15 +2664,11 @@ void __init __weak mem_init(void)

void __init mm_core_init_early(void)
{
- int nid;
-
free_area_init();
/* Zone data structures are available from here. */
hugetlb_cma_reserve();
hugetlb_bootmem_alloc();
sparse_init();
- for_each_node_state(nid, N_MEMORY)
- sparse_vmemmap_init_nid_late(nid);
memmap_init();
}

diff --git a/mm/sparse.c b/mm/sparse.c
index 5fe0a7e66775..d940b973df66 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -383,6 +383,8 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin,
}
sparse_usage_fini();
sparse_buffer_fini();
+
+ sparse_vmemmap_init_nid_late(nid);
}

/*
--
2.20.1