mm/page.c: move mem_init_print_info() to later place
Subsystems (4)
PATCH 1/1 mm/page.c: move mem_init_print_info() to later place
Currently if CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, only part of pages are initialized and added into buddy allocator at early stage. Then the system memory information printed by mem_init_print_info() is incorrect. The snippets of boot log are pasted here:
-----------------------------------------------------------------------
[ 0.059606] mem auto-init: stack:all(zero), heap alloc:off, heap free:off [ 0.059622] software IO TLB: area num 64. [ 0.143887] Memory: 1767888K/133954872K available (20480K kernel code, 3284K rwdata, 8972K rodata, 4572K init, 4916K bss, 2529756K reserved, 0K cma-reserved) [ 0.145111] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=64, Nodes=2
---------------------------------------------------------------------------
Here, move mem_init_print_info() to later place until page init is finished. After the fix, the printed memory information is like this:
-------------------------------------------------------------------------
[ +0.001002] smpboot: Total of 64 processors activated (293724.92 BogoMIPS) [ +0.050086] node 0 deferred pages initialised in 45ms [ +0.007309] node 1 deferred pages initialised in 53ms [ 4.035449] Memory: 131272772K/133954872K available (20480K kernel code, 3284K rwdata, 8972K rodata, 4572K init, 4916K bss, 2529700K reserved, 0K cma-reserved)
[ +0.015995] devtmpfs: initialized
[ +0.003943] x86/mm: Memory block size: 2048MB
-------------------------------------------------------------------------
--- include/linux/gfp.h | 1 + init/main.c | 1 + mm/mm_init.c | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-)
include/linux/gfp.h +1 -0
@@ -335,6 +335,7 @@ void drain_local_pages(struct zone *zone);void page_alloc_init_late (void );void setup_pcp_cacheinfo (void ); +void mem_init_print_info (void );/* * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what
init/main.c +1 -0
@@ -1547,6 +1547,7 @@ static noinline void __init kernel_init_freeable(void)workqueue_init_topology ();padata_init ();page_alloc_init_late (); +mem_init_print_info ();do_basic_setup ();
mm/mm_init.c +1 -2
@@ -2703,7 +2703,7 @@ static void __init report_meminit(void)pr_info ("mem auto-init: clearing system memory may take some time...\n" ); } -static void __init mem_init_print_info (void ) +void __init mem_init_print_info (void ) {unsigned long physpages, codesize, datasize, rosize, bss_size;unsigned long init_code_size, init_data_size;
@@ -2774,7 +2774,6 @@ void __init mm_core_init(void)kmsan_init_shadow ();stack_depot_early_init ();mem_init (); -mem_init_print_info ();kmem_cache_init ();/* * page_owner must be initialized after buddy is ready, and also after
Signature · 1 line
2.41.0
Mike Rapoport
maintainerHi Baoquan,
Quoted 1 line · Baoquan He
Subject: [PATCH]
mm/page.c: movemem_init_print_info()to later place
We don't have mm/page.c,
Quoted 10 lines
Currently if
CONFIG_DEFERRED_STRUCT_PAGE_INITis enabled, only part of pages are initialized and added into buddy allocator at early stage. Then the system memory information printed bymem_init_print_info()is incorrect. The snippets of boot log are pasted here:
-----------------------------------------------------------------------[ 0.059606] mem auto-init: stack:all(zero), heap alloc:off, heap free:off [ 0.059622] software IO TLB: area num 64. [ 0.143887] Memory: 1767888K/133954872K available (20480K kernel code, 3284K rwdata, 8972K rodata, 4572K init, 4916K bss, 2529756K reserved, 0K cma-reserved) [ 0.145111] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=64, Nodes=2---------------------------------------------------------------------------
At this point only the pages that were initialized and free are available. The message does not reflect that large part of memory is still not initialized, but it's not wrong.
Quoted 10 lines
Here, move
mem_init_print_info()to later place until page init is finished. After the fix, the printed memory information is like this:
-------------------------------------------------------------------------[ +0.001002] smpboot: Total of 64 processors activated (293724.92 BogoMIPS) [ +0.050086] node 0 deferred pages initialised in 45ms [ +0.007309] node 1 deferred pages initialised in 53ms [ 4.035449] Memory: 131272772K/133954872K available (20480K kernel code, 3284K rwdata, 8972K rodata, 4572K init, 4916K bss, 2529700K reserved, 0K cma-reserved)[ +0.015995] devtmpfs: initialized
[ +0.003943] x86/mm: Memory block size: 2048MB
-------------------------------------------------------------------------
If we print this message that late, some of the memory will be allocated from buddy and it maybe confusing.
I suggest to print how much memory is not yet initialized and leave mem_init_print_info() where it is now.
Quoted 24 lines
Signed-off-by Baoquan He <[email protected]>--- include/linux/gfp.h | 1 + init/main.c | 1 + mm/mm_init.c | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-)include/linux/gfp.h +1
-0@@ -335,6 +335,7 @@ void drain_local_pages(struct zone *zone);void page_alloc_init_late (void );void setup_pcp_cacheinfo (void ); +void mem_init_print_info (void );/* * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what init/main.c +0
-0
init/main.c static noinline void __init kernel_init_freeable(void) · line 1550
Quoted 4 lines
init/main.c +1
-0@@ -1547,6 +1547,7 @@ static noinline void __init kernel_init_freeable(void)workqueue_init_topology ();padata_init ();page_alloc_init_late (); +mem_init_print_info ();
No need to make mem_init_print_info() global and call it from main.c, you can call it from page_alloc_init_late().
Quoted 26 lines
init/main.c +0
-0do_basic_setup ();mm/mm_init.c +1
-2@@ -2703,7 +2703,7 @@ static void __init report_meminit(void)pr_info ("mem auto-init: clearing system memory may take some time...\n" ); } -static void __init mem_init_print_info (void ) +void __init mem_init_print_info (void ) {unsigned long physpages, codesize, datasize, rosize, bss_size;unsigned long init_code_size, init_data_size;@@ -2774,7 +2774,6 @@ void __init mm_core_init(void)kmsan_init_shadow ();stack_depot_early_init ();mem_init (); -mem_init_print_info ();kmem_cache_init ();/* * page_owner must be initialized after buddy is ready, and also after Signature · 1 line
2.41.0
Signature · 2 lines
Sincerely yours, Mike.
Quoted 8 lines · Mike Rapoport
Hi Baoquan,
Quoted 1 line · Baoquan He
Subject: [PATCH]
mm/page.c: movemem_init_print_info()to later placeWe don't have
mm/page.c,
Thanks for reviewing.
Yes, this was queued in my local branch long time ago, I forgot to update the file name.
Quoted 12 lines
Quoted 11 lines
Currently if
CONFIG_DEFERRED_STRUCT_PAGE_INITis enabled, only part of pages are initialized and added into buddy allocator at early stage. Then the system memory information printed bymem_init_print_info()is incorrect. The snippets of boot log are pasted here:
-----------------------------------------------------------------------[ 0.059606] mem auto-init: stack:all(zero), heap alloc:off, heap free:off [ 0.059622] software IO TLB: area num 64. [ 0.143887] Memory: 1767888K/133954872K available (20480K kernel code, 3284K rwdata, 8972K rodata, 4572K init, 4916K bss, 2529756K reserved, 0K cma-reserved) [ 0.145111] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=64, Nodes=2---------------------------------------------------------------------------
Quoted 3 lines
At this point only the pages that were initialized and free are available. The message does not reflect that large part of memory is still not initialized, but it's not wrong.
Agree. I noticed this because I often need check the memory init and memory size during kernel bootup. The current message gives people a shock at first glance because it looks like a huge reserved memory existing in system.
Quoted 12 lines
Quoted 11 lines
Here, move
mem_init_print_info()to later place until page init is finished. After the fix, the printed memory information is like this:
-------------------------------------------------------------------------[ +0.001002] smpboot: Total of 64 processors activated (293724.92 BogoMIPS) [ +0.050086] node 0 deferred pages initialised in 45ms [ +0.007309] node 1 deferred pages initialised in 53ms [ 4.035449] Memory: 131272772K/133954872K available (20480K kernel code, 3284K rwdata, 8972K rodata, 4572K init, 4916K bss, 2529700K reserved, 0K cma-reserved)[ +0.015995] devtmpfs: initialized
[ +0.003943] x86/mm: Memory block size: 2048MB
-------------------------------------------------------------------------
Quoted 2 lines
If we print this message that late, some of the memory will be allocated from buddy and it maybe confusing.
that's true.
Quoted 3 lines
I suggest to print how much memory is not yet initialized and leave
mem_init_print_info()where it is now.
Sounds great to me, will work out a new version as suggested.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Baoquan He <[email protected]>--- include/linux/gfp.h | 1 + init/main.c | 1 + mm/mm_init.c | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-)include/linux/gfp.h +1
-0@@ -335,6 +335,7 @@ void drain_local_pages(struct zone *zone);void page_alloc_init_late (void );void setup_pcp_cacheinfo (void ); +void mem_init_print_info (void );
Quoted 14 lines
init/main.c static noinline void __init kernel_init_freeable(void) · line 1550
Quoted 11 lines
include/linux/gfp.h +0
-0/* * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what init/main.c +1
-0@@ -1547,6 +1547,7 @@ static noinline void __init kernel_init_freeable(void)workqueue_init_topology ();padata_init ();page_alloc_init_late (); +mem_init_print_info ();No need to make
mem_init_print_info()global and call it frommain.c, you can call it frompage_alloc_init_late().
Agree, that's much better if we take that way.
Quoted 32 lines
Quoted 27 lines
init/main.c +0
-0do_basic_setup ();mm/mm_init.c +1
-2@@ -2703,7 +2703,7 @@ static void __init report_meminit(void)pr_info ("mem auto-init: clearing system memory may take some time...\n" ); } -static void __init mem_init_print_info (void ) +void __init mem_init_print_info (void ) {unsigned long physpages, codesize, datasize, rosize, bss_size;unsigned long init_code_size, init_data_size;@@ -2774,7 +2774,6 @@ void __init mm_core_init(void)kmsan_init_shadow ();stack_depot_early_init ();mem_init (); -mem_init_print_info ();kmem_cache_init ();/* * page_owner must be initialized after buddy is ready, and also after Signature · 1 line
2.41.0Signature · 2 lines
Sincerely yours, Mike.