Re: [PATCH v4 1/2] mm: move overlap memory map init check to memmap_init()
From: Wei Yang
Date: Sun Apr 26 2026 - 00:01:03 EST
On Sat, Apr 25, 2026 at 11:01:42AM +0200, Mike Rapoport wrote:
[...]
>>
>> for (j = 0; j < MAX_NR_ZONES; j++) {
>> struct zone *zone = node->node_zones + j;
>> @@ -978,6 +955,18 @@ static void __init memmap_init(void)
>> if (!populated_zone(zone))
>> continue;
>>
>> + if (mirrored_kernelcore) {
>> + const bool is_mirror = memblock_is_mirror(r);
>> + const bool is_movable_zone = (j == ZONE_MOVABLE);
>> +
>> + if (is_mirror && is_movable_zone)
>> + continue;
>> +
>> + if (!is_mirror && !is_movable_zone &&
>> + start_pfn >= zone_movable_pfn[nid])
>> + continue;
>> + }
>> +
>
Hi, Mike
Thanks for your review.
>I think this:
>
> if (mirrored_kernelcore && j == ZONE_MOVABLE &&
> memblock_is_mirror(r))
> continue;
>
>would be enough to remove overlap_memmap_init() and keep the existing
>logic.
>
>I wouldn't deal the theoretical cases Wei mentioned in this thread for
>now and prefer to keep the things simple.
That would be great to keep things simple.
>The assumptions that mirrored memory spans a contiguous range below some
>limit and that mirrored memory is not removable existed for years and I
>don't see why we should change the logic now and complicate the code for
>exotic theoretical memory layouts.
>
I don't follow here. Still not clear what the memory layout should be.
IIUC, case C is not real, but case A/B are.
I took case B as an example and do some tests. Below is my finding.
Here is memblock layout for case B, with the head 1G of ZONE_NORMAL is mirror
memory.
MEMBLOCK configuration:
memory size = 0x000000017ff7dc00 reserved size = 0x0000000005a939c2
memory.cnt = 0x4
memory[0x0] [0x0000000000001000-0x000000000009efff], node 0 flags: 0x2
memory[0x1] [0x0000000000100000-0x00000000bffdefff], node 0 flags: 0x2
memory[0x2] [0x0000000100000000-0x000000013fffffff], node 1 flags: 0x2
memory[0x3] [0x0000000140000000-0x00000001bfffffff], node 1 flags: 0x0
This meets:
* mirrored memory span from low to 0x13fffffff
Then I add below change along with your suggested change.
@@ -964,6 +964,8 @@ static void __init memmap_init_zone_range(struct zone *zone,
if (start_pfn >= end_pfn)
return;
+ pr_info(" [%lx, %lx] init to %s\n",
+ start_pfn, end_pfn, zone->name);
memmap_init_range(end_pfn - start_pfn, nid, zone_id, start_pfn,
zone_end_pfn, MEMINIT_EARLY, NULL, MIGRATE_MOVABLE,
false);
And see the last normal memory range is initialized twice.
[140000, 1c0000] init to Normal
[140000, 1c0000] init to Movable
Then I removed your suggested change and adjust code like below.
@@ -954,6 +954,7 @@ static void __init memmap_init_zone_range(struct zone *zone,
unsigned long end_pfn,
unsigned long *hole_pfn)
{
+ unsigned long old_start = start_pfn, old_end = end_pfn;
unsigned long zone_start_pfn = zone->zone_start_pfn;
unsigned long zone_end_pfn = zone_start_pfn + zone->spanned_pages;
int nid = zone_to_nid(zone), zone_id = zone_idx(zone);
,
start_pfn = clamp(start_pfn, zone_start_pfn, zone_end_pfn);
end_pfn = clamp(end_pfn, zone_start_pfn, zone_end_pfn);
- if (start_pfn >= end_pfn)
+ if (start_pfn >= end_pfn) {
+ pr_info(" [%lx, %lx] skipped to %s\n",
+ old_start, old_end, zone->name);
return;
+ }
+ pr_info(" [%lx, %lx] init to %s\n",
+ start_pfn, end_pfn, zone->name);
memmap_init_range(end_pfn - start_pfn, nid, zone_id, start_pfn,
zone_end_pfn, MEMINIT_EARLY, NULL, MIGRATE_MOVABLE,
false);
This shows current code already could skip the mirror range to ZONE_MOVABLE
for this kind memory layout, since ZONE_MOVABLE doesn't span to it.
[100000, 140000] skipped to Movable
[140000, 1c0000] init to Normal
[140000, 1c0000] init to Movable
So I am not sure the real mirrored memory layout could be. Would you mind
giving more detail to help me get on the right track?
>> memmap_init_zone_range(zone, start_pfn, end_pfn,
>> &hole_pfn);
>> zone_id = j;
>> --
>> 2.47.3
>>
>
>--
>Sincerely yours,
>Mike.
--
Wei Yang
Help you, Help me