Skip to content

Commit f9899c0

Browse files
HuangShijie2024akpm00
authored andcommitted
NUMA: early use of cpu_to_node() returns 0 instead of the correct node id
During the kernel booting, the generic cpu_to_node() is called too early in arm64, powerpc and riscv when CONFIG_NUMA is enabled. There are at least four places in the common code where the generic cpu_to_node() is called before it is initialized: 1.) early_trace_init() in kernel/trace/trace.c 2.) sched_init() in kernel/sched/core.c 3.) init_sched_fair_class() in kernel/sched/fair.c 4.) workqueue_init_early() in kernel/workqueue.c This will harm performance since there is an increase in off node accesses. In order to fix the bug, the patch introduces early_numa_node_init() which is called after smp_prepare_boot_cpu() in start_kernel. early_numa_node_init will initialize the "numa_node" as soon as the early_cpu_to_node() is ready, before the cpu_to_node() is called at the first time. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Huang Shijie <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> [RISC-V] Cc: Albert Ou <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Jiaxun Yang <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michael Kelley (LINUX) <[email protected]> Cc: "Mike Rapoport (IBM)" <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Valentin Schneider <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yury Norov <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4d9784c commit f9899c0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

init/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,19 @@ static void __init print_unknown_bootoptions(void)
882882
memblock_free(unknown_options, len);
883883
}
884884

885+
static void __init early_numa_node_init(void)
886+
{
887+
#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
888+
#ifndef cpu_to_node
889+
int cpu;
890+
891+
/* The early_cpu_to_node() should be ready here. */
892+
for_each_possible_cpu(cpu)
893+
set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
894+
#endif
895+
#endif
896+
}
897+
885898
asmlinkage __visible __init __no_sanitize_address __noreturn __no_stack_protector
886899
void start_kernel(void)
887900
{
@@ -912,6 +925,7 @@ void start_kernel(void)
912925
setup_nr_cpu_ids();
913926
setup_per_cpu_areas();
914927
smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
928+
early_numa_node_init();
915929
boot_cpu_hotplug_init();
916930

917931
pr_notice("Kernel command line: %s\n", saved_command_line);

0 commit comments

Comments
 (0)