diff mbox series

[v2,06/14] init: fold build_all_zonelists() and page_alloc_init_cpuhp() to mm_init()

Message ID 20230321170513.2401534-7-rppt@kernel.org (mailing list archive)
State Handled Elsewhere
Headers show
Series mm: move core MM initialization to mm/mm_init.c | expand

Commit Message

Mike Rapoport March 21, 2023, 5:05 p.m. UTC
From: "Mike Rapoport (IBM)" <rppt@kernel.org>

Both build_all_zonelists() and page_alloc_init_cpuhp() must be called
after SMP setup is complete but before the page allocator is set up.

Still, they both are a part of memory management initialization, so move
them to mm_init().

Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
---
 init/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Vlastimil Babka March 22, 2023, 4:10 p.m. UTC | #1
On 3/21/23 18:05, Mike Rapoport wrote:
> From: "Mike Rapoport (IBM)" <rppt@kernel.org>
> 
> Both build_all_zonelists() and page_alloc_init_cpuhp() must be called
> after SMP setup is complete but before the page allocator is set up.
> 
> Still, they both are a part of memory management initialization, so move
> them to mm_init().

Well, logic grouping is one thing, but not breaking a functional order is
more important. So this moves both calls to happen later than theyw ere. I
guess it could only matter for page_alloc_init_cpuhp() in case cpu hotplugs
would be processed in some of the calls we "skipped" over by moving this
later. And one of them is setup_arch()... so are we sure no arch does some
cpu hotplug for non-boot cpus there?

> Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
> Acked-by: David Hildenbrand <david@redhat.com>
> ---
>  init/main.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/init/main.c b/init/main.c
> index b2499bee7a3c..4423906177c1 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -833,6 +833,10 @@ static void __init report_meminit(void)
>   */
>  static void __init mm_init(void)
>  {
> +	/* Initializations relying on SMP setup */
> +	build_all_zonelists(NULL);
> +	page_alloc_init_cpuhp();
> +
>  	/*
>  	 * page_ext requires contiguous pages,
>  	 * bigger than MAX_ORDER unless SPARSEMEM.
> @@ -968,9 +972,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
>  	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */
>  	boot_cpu_hotplug_init();
>  
> -	build_all_zonelists(NULL);
> -	page_alloc_init_cpuhp();
> -
>  	pr_notice("Kernel command line: %s\n", saved_command_line);
>  	/* parameters may set static keys */
>  	jump_label_init();
Mike Rapoport March 22, 2023, 8:26 p.m. UTC | #2
On Wed, Mar 22, 2023 at 05:10:10PM +0100, Vlastimil Babka wrote:
> On 3/21/23 18:05, Mike Rapoport wrote:
> > From: "Mike Rapoport (IBM)" <rppt@kernel.org>
> > 
> > Both build_all_zonelists() and page_alloc_init_cpuhp() must be called
> > after SMP setup is complete but before the page allocator is set up.
> > 
> > Still, they both are a part of memory management initialization, so move
> > them to mm_init().
> 
> Well, logic grouping is one thing, but not breaking a functional order is
> more important. So this moves both calls to happen later than theyw ere. I
> guess it could only matter for page_alloc_init_cpuhp() in case cpu hotplugs
> would be processed in some of the calls we "skipped" over by moving this
> later. And one of them is setup_arch()... so are we sure no arch does some
> cpu hotplug for non-boot cpus there?

mm_init() happens after the point build_all_zonelists() and
page_alloc_init_cpuhp() were originally, so they are essentially moved
later in the init sequence and in either case called after setup_arch().

We skip the code below and it does not do neither cpu hotplug nor
non-memblock allocations.

	jump_label_init();
	parse_early_param();
	after_dashes = parse_args("Booting kernel",
				  static_command_line, __start___param,
				  __stop___param - __start___param,
				  -1, -1, NULL, &unknown_bootoption);
	print_unknown_bootoptions();
	if (!IS_ERR_OR_NULL(after_dashes))
		parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
			   NULL, set_init_arg);
	if (extra_init_args)
		parse_args("Setting extra init args", extra_init_args,
			   NULL, 0, -1, -1, NULL, set_init_arg);

	/* Architectural and non-timekeeping rng init, before allocator init */
	random_init_early(command_line);

	/*
	 * These use large bootmem allocations and must precede
	 * kmem_cache_init()
	 */
	setup_log_buf(0);
	vfs_caches_init_early();
	sort_main_extable();
	trap_init();

 
> > Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
> > Acked-by: David Hildenbrand <david@redhat.com>
> > ---
> >  init/main.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/init/main.c b/init/main.c
> > index b2499bee7a3c..4423906177c1 100644
> > --- a/init/main.c
> > +++ b/init/main.c
> > @@ -833,6 +833,10 @@ static void __init report_meminit(void)
> >   */
> >  static void __init mm_init(void)
> >  {
> > +	/* Initializations relying on SMP setup */
> > +	build_all_zonelists(NULL);
> > +	page_alloc_init_cpuhp();
> > +
> >  	/*
> >  	 * page_ext requires contiguous pages,
> >  	 * bigger than MAX_ORDER unless SPARSEMEM.
> > @@ -968,9 +972,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
> >  	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */
> >  	boot_cpu_hotplug_init();
> >  
> > -	build_all_zonelists(NULL);
> > -	page_alloc_init_cpuhp();
> > -
> >  	pr_notice("Kernel command line: %s\n", saved_command_line);
> >  	/* parameters may set static keys */
> >  	jump_label_init();
>
Vlastimil Babka March 23, 2023, 7:09 a.m. UTC | #3
On 3/22/23 21:26, Mike Rapoport wrote:
> On Wed, Mar 22, 2023 at 05:10:10PM +0100, Vlastimil Babka wrote:
>> On 3/21/23 18:05, Mike Rapoport wrote:
>> > From: "Mike Rapoport (IBM)" <rppt@kernel.org>
>> > 
>> > Both build_all_zonelists() and page_alloc_init_cpuhp() must be called
>> > after SMP setup is complete but before the page allocator is set up.
>> > 
>> > Still, they both are a part of memory management initialization, so move
>> > them to mm_init().
>> 
>> Well, logic grouping is one thing, but not breaking a functional order is
>> more important. So this moves both calls to happen later than theyw ere. I
>> guess it could only matter for page_alloc_init_cpuhp() in case cpu hotplugs
>> would be processed in some of the calls we "skipped" over by moving this
>> later. And one of them is setup_arch()... so are we sure no arch does some
>> cpu hotplug for non-boot cpus there?
> 
> mm_init() happens after the point build_all_zonelists() and
> page_alloc_init_cpuhp() were originally, so they are essentially moved
> later in the init sequence and in either case called after setup_arch().

Right, I looked at a wrong place in start_kernel() for the original location
of the calls, sorry for the noise.

> We skip the code below and it does not do neither cpu hotplug nor
> non-memblock allocations.
> 
> 	jump_label_init();
> 	parse_early_param();
> 	after_dashes = parse_args("Booting kernel",
> 				  static_command_line, __start___param,
> 				  __stop___param - __start___param,
> 				  -1, -1, NULL, &unknown_bootoption);
> 	print_unknown_bootoptions();
> 	if (!IS_ERR_OR_NULL(after_dashes))
> 		parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
> 			   NULL, set_init_arg);
> 	if (extra_init_args)
> 		parse_args("Setting extra init args", extra_init_args,
> 			   NULL, 0, -1, -1, NULL, set_init_arg);
> 
> 	/* Architectural and non-timekeeping rng init, before allocator init */
> 	random_init_early(command_line);
> 
> 	/*
> 	 * These use large bootmem allocations and must precede
> 	 * kmem_cache_init()
> 	 */
> 	setup_log_buf(0);
> 	vfs_caches_init_early();
> 	sort_main_extable();
> 	trap_init();
> 

Yeah, that looks safe.

>> > Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
>> > Acked-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
diff mbox series

Patch

diff --git a/init/main.c b/init/main.c
index b2499bee7a3c..4423906177c1 100644
--- a/init/main.c
+++ b/init/main.c
@@ -833,6 +833,10 @@  static void __init report_meminit(void)
  */
 static void __init mm_init(void)
 {
+	/* Initializations relying on SMP setup */
+	build_all_zonelists(NULL);
+	page_alloc_init_cpuhp();
+
 	/*
 	 * page_ext requires contiguous pages,
 	 * bigger than MAX_ORDER unless SPARSEMEM.
@@ -968,9 +972,6 @@  asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */
 	boot_cpu_hotplug_init();
 
-	build_all_zonelists(NULL);
-	page_alloc_init_cpuhp();
-
 	pr_notice("Kernel command line: %s\n", saved_command_line);
 	/* parameters may set static keys */
 	jump_label_init();