[RFC Patch 2/3] mm/mm_init: remove overlap_memmap_init() as no overlapped zone

From: Wei Yang

Date: Tue Jun 23 2026 - 05:31:02 EST


When commit 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror
option") is introduced, it would have overlapped Zone Normal and Zone
Movable. And this original code would initialize overlapped range twice.

For example, if the memory layout is below:

memory[0x0] [0x0000000000001000-0x000000000009efff], 0x000000000009e000 bytes on node 0 flags: 0x2
memory[0x1] [0x0000000000100000-0x00000000bffdefff], 0x00000000bfedf000 bytes on node 0 flags: 0x2
memory[0x2] [0x0000000100000000-0x000000013fffffff], 0x0000000040000000 bytes on node 0 flags: 0x2
memory[0x3] [0x0000000140000000-0x00000001bfffffff], 0x0000000080000000 bytes on node 0 flags: 0x0

We would get Zone range with kernelcore=mirror set:

Normal [100000, 1c0000]
Movable [140000, 1c0000]

According to original logic, during memmap_init() it calls
memmap_init_zone_range() with the same range from
for_each_mem_pfn_range() for each populated zone. And then clamp the
same memory range with specific zone boundary.

memmap_init()
for_each_mem_pfn_range(&start_pfn, &end_pfn)
for: zone = ZONE_DMA, ZONE_DEVICE
memmap_init_zone_range(zone, start_pfn, end_pfn) <-- same range, but different zone
memmap_init_range() <-- clamped with zone range

For the last memblock region:

[0x0000000140000000-0x00000001bfffffff]

It belongs to both Zone Normal and Zone Movable, which means the same range
would be initialized twice by memmap_init_range(), but with different
zone_id.

Original code is expected to skip overlapped range with
overlap_memmap_init(). But it only skip when (zone == ZONE_MOVABLE), which
in turn has no effect for this memory layout. So the last range is first
initialized to Zone Normal, then to Zone Movable which is what we
expect.

After previous cleanup, the overlapped zone is gone, so the
overlap_memmap_init() is not necessary anymore.

Signed-off-by: Wei Yang <richard.weiyang@xxxxxxxxx>
Cc: "David Hildenbrand (Arm)" <david@xxxxxxxxxx>
Cc: Yuan Liu <yuan1.liu@xxxxxxxxx>
---
mm/mm_init.c | 24 ------------------------
1 file changed, 24 deletions(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index b8ff4aff19c0..da0e65bf8d02 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -797,28 +797,6 @@ void __meminit init_deferred_page(unsigned long pfn, int nid)
__init_deferred_page(pfn, nid);
}

-/* If zone is ZONE_MOVABLE but memory is mirrored, it is an overlapped init */
-static bool __meminit
-overlap_memmap_init(unsigned long zone, unsigned long *pfn)
-{
- static struct memblock_region *r __meminitdata;
-
- if (mirrored_kernelcore && zone == ZONE_MOVABLE) {
- if (!r || *pfn >= memblock_region_memory_end_pfn(r)) {
- for_each_mem_region(r) {
- if (*pfn < memblock_region_memory_end_pfn(r))
- break;
- }
- }
- if (*pfn >= memblock_region_memory_base_pfn(r) &&
- memblock_is_mirror(r)) {
- *pfn = memblock_region_memory_end_pfn(r);
- return true;
- }
- }
- return false;
-}
-
/*
* Only struct pages that correspond to ranges defined by memblock.memory
* are zeroed and initialized by going through __init_single_page() during
@@ -905,8 +883,6 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone
* function. They do not exist on hotplugged memory.
*/
if (context == MEMINIT_EARLY) {
- if (overlap_memmap_init(zone, &pfn))
- continue;
if (defer_init(nid, pfn, zone_end_pfn)) {
deferred_struct_pages = true;
break;
--
2.34.1