mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore
@ 2026-06-23  9:23 Wei Yang
  2026-06-23  9:23 ` [RFC Patch 1/3] mm/mm_init: adjust overlapped zone for mirror memory too Wei Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Wei Yang @ 2026-06-23  9:23 UTC (permalink / raw)
  To: rppt, akpm, izumi.taku; +Cc: linux-mm, linux-kernel, david, yuan1.liu, Wei Yang

When reviewing patch set "mm/memory_hotplug: optimize zone contiguous check
when changing pfn range" [1], we notice mirrored_kernelcore introduced some
special case to handle.

While during the discussion and test, it shows current mirrored_kernelcore
implementation breaks other memmap_init() behavior:

  * disturbs defer_init()
  * some Movable zone range would be initialized twice

The reason is Zone Movable and Zone Normal overlaps and current logic doesn't
handle it well.

As Yuan shows in [2], physical overlapped zone seems not exist in practice. If
remove the possibility of overlapped zone, problem could be solved. And also
could benefit zone contiguous optimization, IIUC.

Patch [1]: remove the overlapped zone, which fix the above two problem
Patch [2]: remove overlap_memmap_init() as there is no overlapped zone, but
           record current double initialize problem for reference
Patch [3]: remove absent pages calculation for mirrored_kernelcore

[1]: https://lore.kernel.org/all/20260520093457.3719960-1-yuan1.liu@intel.com/T/#u
[2]: https://lore.kernel.org/all/20260520093457.3719960-1-yuan1.liu@intel.com/T/#mb0bd07ffd562a5b029f0f07751e580ca339c5b51

Cc: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Yuan Liu <yuan1.liu@intel.com>

Wei Yang (3):
  mm/mm_init: adjust overlapped zone for mirror memory too
  mm/mm_init: remove overlap_memmap_init() as no overlapped zone
  mm/mm_init: remove special handling absent pages for
    mirrored_kernelcore

 mm/mm_init.c | 58 ++--------------------------------------------------
 1 file changed, 2 insertions(+), 56 deletions(-)

---

This series is based on one proposed fix for node_spanned_pages:

https://lore.kernel.org/linux-mm/20260622022403.16375-1-richard.weiyang@gmail.com/

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC Patch 1/3] mm/mm_init: adjust overlapped zone for mirror memory too
  2026-06-23  9:23 [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore Wei Yang
@ 2026-06-23  9:23 ` Wei Yang
  2026-06-23  9:23 ` [RFC Patch 2/3] mm/mm_init: remove overlap_memmap_init() as no overlapped zone Wei Yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2026-06-23  9:23 UTC (permalink / raw)
  To: rppt, akpm, izumi.taku; +Cc: linux-mm, linux-kernel, david, yuan1.liu, Wei Yang

When mirrored_kernelcore is set, adjust_zone_range_for_zone_movable() would
skip the adjustment if ZONE_MOVABLE starts within one zone.

This makes the zone, usually ZONE_NORMAL, ends the same as ZONE_MOVABLE.

For example, we have a system with following memory layout:

  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

With kernelcore=mirror set, current kernel set zone with below range:

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

This changes the expected behavior of defer_init(), because it only expect to
defer_init() memory in last zone. As Zone Normal and Movable stops at the same
end_pfn, defer_init() would set first_deferred_pfn in Zone Normal. And what is
worse, pages belongs to Zone Normal would be counted as Zone Movable.

  Node 0, zone   Normal
          spanned  786432
          present  262144
          managed  34390
  Node 0, zone  Movable
          spanned  524288
          present  524288
          managed  715855    <- manage more pages than present

While when we look at the memory layout, we can see Zone Normal and Movable
could be not overlapped if we adjust Zone Normal just other movable zone case.
And we don't expect they would interleave.

After doing so, we have non-overlap Zones:

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

And the page locality looks correct:

  Node 0, zone   Normal
          spanned  262144
          present  262144
          managed  233614
  Node 0, zone  Movable
          spanned  524288
          present  524288
          managed  524242

Fixes: 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror option")
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Yuan Liu <yuan1.liu@intel.com>
---
 mm/mm_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 7c4af27a6557..b8ff4aff19c0 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1170,8 +1170,7 @@ static void __init adjust_zone_range_for_zone_movable(int nid,
 				arch_zone_highest_possible_pfn[movable_zone]);
 
 		/* Adjust for ZONE_MOVABLE starting within this range */
-		} else if (!mirrored_kernelcore &&
-			*zone_start_pfn < zone_movable_pfn[nid] &&
+		} else if (*zone_start_pfn < zone_movable_pfn[nid] &&
 			*zone_end_pfn > zone_movable_pfn[nid]) {
 			*zone_end_pfn = zone_movable_pfn[nid];
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC Patch 2/3] mm/mm_init: remove overlap_memmap_init() as no overlapped zone
  2026-06-23  9:23 [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore Wei Yang
  2026-06-23  9:23 ` [RFC Patch 1/3] mm/mm_init: adjust overlapped zone for mirror memory too Wei Yang
@ 2026-06-23  9:23 ` Wei Yang
  2026-06-23  9:23 ` [RFC Patch 3/3] mm/mm_init: remove special handling absent pages for mirrored_kernelcore Wei Yang
  2026-06-25  6:36 ` [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore David Hildenbrand (Arm)
  3 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2026-06-23  9:23 UTC (permalink / raw)
  To: rppt, akpm, izumi.taku; +Cc: linux-mm, linux-kernel, david, yuan1.liu, Wei Yang

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@gmail.com>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Yuan Liu <yuan1.liu@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC Patch 3/3] mm/mm_init: remove special handling absent pages for mirrored_kernelcore
  2026-06-23  9:23 [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore Wei Yang
  2026-06-23  9:23 ` [RFC Patch 1/3] mm/mm_init: adjust overlapped zone for mirror memory too Wei Yang
  2026-06-23  9:23 ` [RFC Patch 2/3] mm/mm_init: remove overlap_memmap_init() as no overlapped zone Wei Yang
@ 2026-06-23  9:23 ` Wei Yang
  2026-06-25  6:36 ` [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore David Hildenbrand (Arm)
  3 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2026-06-23  9:23 UTC (permalink / raw)
  To: rppt, akpm, izumi.taku; +Cc: linux-mm, linux-kernel, david, yuan1.liu, Wei Yang

After making Zone Normal/Movable non-overlap, it is not necessary to
calculate absent pages for mirrored_kernelcore specially.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Yuan Liu <yuan1.liu@intel.com>
---
 mm/mm_init.c | 31 +------------------------------
 1 file changed, 1 insertion(+), 30 deletions(-)

diff --git a/mm/mm_init.c b/mm/mm_init.c
index da0e65bf8d02..b34ca1cf117f 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1195,40 +1195,11 @@ static unsigned long __init zone_absent_pages_in_node(int nid,
 					unsigned long zone_start_pfn,
 					unsigned long zone_end_pfn)
 {
-	unsigned long nr_absent;
-
 	/* zone is empty, we don't have any absent pages */
 	if (zone_start_pfn == zone_end_pfn)
 		return 0;
 
-	nr_absent = __absent_pages_in_range(nid, zone_start_pfn, zone_end_pfn);
-
-	/*
-	 * ZONE_MOVABLE handling.
-	 * Treat pages to be ZONE_MOVABLE in ZONE_NORMAL as absent pages
-	 * and vice versa.
-	 */
-	if (mirrored_kernelcore && zone_movable_pfn[nid]) {
-		unsigned long start_pfn, end_pfn;
-		struct memblock_region *r;
-
-		for_each_mem_region(r) {
-			start_pfn = clamp(memblock_region_memory_base_pfn(r),
-					  zone_start_pfn, zone_end_pfn);
-			end_pfn = clamp(memblock_region_memory_end_pfn(r),
-					zone_start_pfn, zone_end_pfn);
-
-			if (zone_type == ZONE_MOVABLE &&
-			    memblock_is_mirror(r))
-				nr_absent += end_pfn - start_pfn;
-
-			if (zone_type == ZONE_NORMAL &&
-			    !memblock_is_mirror(r))
-				nr_absent += end_pfn - start_pfn;
-		}
-	}
-
-	return nr_absent;
+	return __absent_pages_in_range(nid, zone_start_pfn, zone_end_pfn);
 }
 
 /*
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore
  2026-06-23  9:23 [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore Wei Yang
                   ` (2 preceding siblings ...)
  2026-06-23  9:23 ` [RFC Patch 3/3] mm/mm_init: remove special handling absent pages for mirrored_kernelcore Wei Yang
@ 2026-06-25  6:36 ` David Hildenbrand (Arm)
  3 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-25  6:36 UTC (permalink / raw)
  To: Wei Yang, rppt, akpm, izumi.taku; +Cc: linux-mm, linux-kernel, yuan1.liu

On 6/23/26 11:23, Wei Yang wrote:
> When reviewing patch set "mm/memory_hotplug: optimize zone contiguous check
> when changing pfn range" [1], we notice mirrored_kernelcore introduced some
> special case to handle.
> 
> While during the discussion and test, it shows current mirrored_kernelcore
> implementation breaks other memmap_init() behavior:
> 
>   * disturbs defer_init()
>   * some Movable zone range would be initialized twice
> 
> The reason is Zone Movable and Zone Normal overlaps and current logic doesn't
> handle it well.
> 
> As Yuan shows in [2], physical overlapped zone seems not exist in practice. If
> remove the possibility of overlapped zone, problem could be solved. And also
> could benefit zone contiguous optimization, IIUC.
> 
> Patch [1]: remove the overlapped zone, which fix the above two problem
> Patch [2]: remove overlap_memmap_init() as there is no overlapped zone, but
>            record current double initialize problem for reference
> Patch [3]: remove absent pages calculation for mirrored_kernelcore
> 
> [1]: https://lore.kernel.org/all/20260520093457.3719960-1-yuan1.liu@intel.com/T/#u
> [2]: https://lore.kernel.org/all/20260520093457.3719960-1-yuan1.liu@intel.com/T/#mb0bd07ffd562a5b029f0f07751e580ca339c5b51
> 

IIUC, Mike will send an alternative.

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-25  6:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-23  9:23 [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore Wei Yang
2026-06-23  9:23 ` [RFC Patch 1/3] mm/mm_init: adjust overlapped zone for mirror memory too Wei Yang
2026-06-23  9:23 ` [RFC Patch 2/3] mm/mm_init: remove overlap_memmap_init() as no overlapped zone Wei Yang
2026-06-23  9:23 ` [RFC Patch 3/3] mm/mm_init: remove special handling absent pages for mirrored_kernelcore Wei Yang
2026-06-25  6:36 ` [RFC Patch 0/3] mm/mm_init: fix and cleanup mirrored_kernelcore David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox