Skip to contentSkip to conversation

mm/mm_init: fix incorrect node_spanned_pages

PATCH Applied Wei Yang 2 participants 8 messages Jun 22 – Jun 30

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/mm_init: fix incorrect node_spanned_pages

Current node_spanned_pages is got as a summation of all zone's spanned page in calculate_node_totalpages(). Generally this is good, but if we use kernelcore=mirror, it is would be wrong.

Without kernelcore=mirror:

    The test machine has below memory layout:

      memory[0x0]     [0x0000000000001000-0x000000000009efff], 0x000000000009e000 bytes on node 0 flags: 0x0
      memory[0x1]     [0x0000000000100000-0x00000000bffdefff], 0x00000000bfedf000 bytes on node 0 flags: 0x0
      memory[0x2]     [0x0000000100000000-0x00000001bfffffff], 0x00000000c0000000 bytes on node 0 flags: 0x0

    And the Zone range is:

      DMA      [mem 0x0000000000001000-0x0000000000ffffff]
      DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
      Normal   [mem 0x0000000100000000-0x00000001bfffffff]

    Then we see, with spanned_pages printed:

      On node 0 spanned_pages: 1835007 totalpages: 1572733

With kernelcore=mirror:

    The test machine has below 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

    And the Zone range is:

      DMA      [mem 0x0000000000001000-0x0000000000ffffff]
      DMA32    [mem 0x0000000001000000-0x00000000ffffffff]
      Normal   [mem 0x0000000100000000-0x00000001bfffffff]
      Device   empty
    Movable zone start for each node
      Node 0: 0x0000000140000000

    Then we see, with spanned_pages printed:

      On node 0 spanned_pages: 2359295 totalpages: 1572733

The total range of memory on node 0 doesn't change, but the spanned_pages becomes much larger.

The reason is when kernelcore=mirror is specified, the range of Zone Normal and Zone Movable would overlap. So the overlapped range would be calculated twice.

A wrong node_spanned_pages would effect defer_init(), since each zone_end_pfn is less than pgdat_end_pfn().

As we already passed in node_start_pfn and node_end_pfn, fix this by get it from (node_start_pfn - node_end_pfn) directly.

Fixes 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror option")
Cc Yuan Liu <[email protected]>
---
 mm/mm_init.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/mm_init.c +2 -3
index a0e6a91283fb..7ad01eeddda9 100644
@@ -1304,7 +1304,7 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
 						unsigned long node_start_pfn,
 						unsigned long node_end_pfn)
 {
-	unsigned long realtotalpages = 0, totalpages = 0;
+	unsigned long realtotalpages = 0;
 	enum zone_type i;
 
 	for (i = 0; i < MAX_NR_ZONES; i++) {
@@ -1334,11 +1334,10 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
 		zone->present_early_pages = real_size;
 #endif
 
-		totalpages += spanned;
 		realtotalpages += real_size;
 	}
 
-	pgdat->node_spanned_pages = totalpages;
+	pgdat->node_spanned_pages = node_end_pfn - node_start_pfn;
 	pgdat->node_present_pages = realtotalpages;
 	pr_debug("On node %d totalpages: %lu\n", pgdat->node_id, realtotalpages);
 }
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi Wei,

Quoted 10 lines · Wei Yang

Current node_spanned_pages is got as a summation of all zone's spanned page in calculate_node_totalpages(). Generally this is good, but if we use kernelcore=mirror, it is would be wrong.

As we already passed in node_start_pfn and node_end_pfn, fix this by get it from (node_start_pfn - node_end_pfn) directly.

Fixes 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror option")
Cc Yuan Liu <[email protected]>

I queued it for now, will push to one of memblock branches after merge window closes.

Quoted 3 lines
---
 mm/mm_init.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 2 lines
Sincerely yours,
Mike.
author
#2 lore raw
Quoted 1 line · Mike Rapoport

Hi Wei,

Hi, Mike

Quoted 9 lines · Wei Yang
Quoted 7 lines

Current node_spanned_pages is got as a summation of all zone's spanned page in calculate_node_totalpages(). Generally this is good, but if we use kernelcore=mirror, it is would be wrong.

As we already passed in node_start_pfn and node_end_pfn, fix this by get it from (node_start_pfn - node_end_pfn) directly.

Quoted 7 lines
Quoted 3 lines
Fixes 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror option")
Cc Yuan Liu <[email protected]>

I queued it for now, will push to one of memblock branches after merge window closes.

After some investigation, I found current mirrored_kernelcore may still affect memmap_init() in some aspects.

But how to fix is not sure, will prepare an RFC for discussion.

Quoted 7 lines
Quoted 3 lines
---
 mm/mm_init.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
Signature · 2 lines
Sincerely yours,
Mike.
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#3 lore raw

Hi Wei,

Quoted 13 lines · Wei Yang
Quoted 12 lines · Mike Rapoport
Quoted 10 lines · Wei Yang

Current node_spanned_pages is got as a summation of all zone's spanned page in calculate_node_totalpages(). Generally this is good, but if we use kernelcore=mirror, it is would be wrong.

As we already passed in node_start_pfn and node_end_pfn, fix this by get it from (node_start_pfn - node_end_pfn) directly.

Fixes 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror option")
Cc Yuan Liu <[email protected]>
Quoted 8 lines
Quoted 3 lines

I queued it for now, will push to one of memblock branches after merge window closes.

After some investigation, I found current mirrored_kernelcore may still affect memmap_init() in some aspects.

But how to fix is not sure, will prepare an RFC for discussion.

After I applied your patch, I did some checks to see why mirrored_kernelcore causes us troubles. I found that unlike other variants of kernelcore/movablecore settings, mirrored_kernelcore creates zone overlap for no apparent reason. I did some git archaeology and I didn't find a justification for making overlapping pages absent in ZONE_NORMAL.

So I came up with this cleanup:

https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=kernelcore-mirror

I'm waiting for the bots to chew on it before positing the patches.

Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me
Signature · 2 lines
Sincerely yours,
Mike.
author
#4 lore raw
Quoted 31 lines · Mike Rapoport

Hi Wei,

Quoted 13 lines · Wei Yang
Quoted 12 lines · Mike Rapoport
Quoted 10 lines · Wei Yang

Current node_spanned_pages is got as a summation of all zone's spanned page in calculate_node_totalpages(). Generally this is good, but if we use kernelcore=mirror, it is would be wrong.

As we already passed in node_start_pfn and node_end_pfn, fix this by get it from (node_start_pfn - node_end_pfn) directly.

Fixes 342332e6a925 ("mm/page_alloc.c: introduce kernelcore=mirror option")
Cc Yuan Liu <[email protected]>
Quoted 8 lines
Quoted 3 lines

I queued it for now, will push to one of memblock branches after merge window closes.

After some investigation, I found current mirrored_kernelcore may still affect memmap_init() in some aspects.

But how to fix is not sure, will prepare an RFC for discussion.

After I applied your patch, I did some checks to see why mirrored_kernelcore causes us troubles. I found that unlike other variants of kernelcore/movablecore settings, mirrored_kernelcore creates zone overlap for no apparent reason. I did some git archaeology and I didn't find a justification for making overlapping pages absent in ZONE_NORMAL.

Quoted 6 lines

So I came up with this cleanup:

https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=kernelcore-mirror

I'm waiting for the bots to chew on it before positing the patches.

Ah, just the same as I do :-).

Quoted 7 lines
Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me
Signature · 2 lines
Sincerely yours,
Mike.
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#5 lore raw
Quoted 8 lines · Wei Yang
Quoted 7 lines · Mike Rapoport

After I applied your patch, I did some checks to see why mirrored_kernelcore causes us troubles. I found that unlike other variants of kernelcore/movablecore settings, mirrored_kernelcore creates zone overlap for no apparent reason. I did some git archaeology and I didn't find a justification for making overlapping pages absent in ZONE_NORMAL.

Quoted 8 lines
Quoted 6 lines

So I came up with this cleanup:

https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=kernelcore-mirror

I'm waiting for the bots to chew on it before positing the patches.

Ah, just the same as I do :-).

I'm going to send my version with your co-developed-by if you don't mind.

Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me
Signature · 2 lines
Sincerely yours,
Mike.
author
#6 lore raw
Quoted 11 lines · Mike Rapoport
Quoted 10 lines · Wei Yang
Quoted 9 lines · Mike Rapoport

After I applied your patch, I did some checks to see why mirrored_kernelcore causes us troubles. I found that unlike other variants of kernelcore/movablecore settings, mirrored_kernelcore creates zone overlap for no apparent reason. I did some git archaeology and I didn't find a justification for making overlapping pages absent in ZONE_NORMAL.

So I came up with this cleanup:

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=kernelcore-mirror

I'm waiting for the bots to chew on it before positing the patches.

Ah, just the same as I do :-).

I'm going to send my version with your co-developed-by if you don't mind.

My pleasure :-)

Quoted 7 lines
Quoted 3 lines
Signature · 2 lines
Wei Yang
Help you, Help me
Signature · 2 lines
Sincerely yours,
Mike.
Signature · 2 lines
Wei Yang
Help you, Help me