Skip nodes without CPUs in the sched_ext idle walk
Subsystems (8)
v2 cover Skip nodes without CPUs in the sched_ext idle walk
With numa=fake, NUMA emulation sets a CPU in cpumask_of_node() of every emulated node on its physical node, while cpu_to_node() returns only one of them. On a Raspberry Pi 5, whose firmware adds numa=fake=8, all eight nodes list CPUs 0-3 and have N_CPU set, but cpu_to_node() is 0 for every CPU. sched_ext's per-node idle walk then visits seven nodes that can't have an idle CPU.
As Tejun suggested [1], patch 1 makes NUMA emulation set a CPU only in the cpumask of its own node, and patch 2 makes sched_ext walk node_states[N_CPU] instead of N_ONLINE.
On the rpi5 under hackbench, the per-node ops.select_cpu() time goes from 484ns to 141ns, against 139ns with the global idle cpumask.
This series is based on sched_ext/for-7.5. Patch 1 also applies cleanly to memblock/for-next.
[1] https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Fix NUMA emulation and walk N_CPU instead of keeping a separate node mask in sched_ext. (Tejun)
- Link to v1:
https://lore.kernel.org/all/[email protected]/
Cheng-Yang Chou (2):
mm/fake-numa: map each CPU only to its own node
sched_ext/idle: Skip nodes without CPUs
arch/x86/mm/numa.c | 4 --- include/asm-generic/numa.h | 4 --- kernel/sched/ext/idle.c | 4 +-- mm/arch_numa.c | 26 --------------- mm/numa_emulation.c | 67 ++------------------------------------ 5 files changed, 5 insertions(+), 100 deletions(-)
base-commit: 95a4df9944cd5d57a92662269114ba99cb972394
Signature · 1 line
2.56.0
PATCH v2 1/2 mm/fake-numa: map each CPU only to its own node
With numa=fake, numa_add_cpu() sets a CPU in cpumask_of_node() of every emulated node on its physical node, while cpu_to_node() returns only one of them. On a Raspberry Pi 5, whose firmware adds numa=fake=8, all eight nodes list CPUs 0-3 and have N_CPU set, but cpu_to_node() is 0 for every CPU.
No real topology puts a CPU in more than one node, and code that walks N_CPU or cpumask_of_node() expects them to agree with cpu_to_node(). For example, sched_ext tracks idle CPUs by cpu_to_node(), so the seven other nodes can never have an idle CPU even though N_CPU says they have CPUs.
Set a CPU only in the cpumask of its own node, the same as without emulation. The other emulated nodes on the same physical node become memory-only nodes. Also drop the code this leaves unused.
On that rpi5, node 0 now lists CPUs 0-3, nodes 1-7 list none and has_cpu is 0, while the interleave policy the rpi5 kernel sets still spreads memory over all eight nodes.
--- arch/x86/mm/numa.c | 4 --- include/asm-generic/numa.h | 4 --- mm/arch_numa.c | 26 --------------- mm/numa_emulation.c | 67 ++------------------------------------ 4 files changed, 3 insertions(+), 98 deletions(-)
arch/x86/mm/numa.c +0 -4
@@ -323,7 +323,6 @@ void __init init_cpu_to_node(void)#ifndef CONFIG_DEBUG_PER_CPU_MAPS -# ifndef CONFIG_NUMA_EMUvoid numa_add_cpu (unsigned int cpu) {cpumask_set_cpu (cpu, node_to_cpumask_map[early_cpu_to_node (cpu)]);
@@ -333,7 +332,6 @@ void numa_remove_cpu(unsigned int cpu) {cpumask_clear_cpu (cpu, node_to_cpumask_map[early_cpu_to_node (cpu)]); } -# endif /* !CONFIG_NUMA_EMU */ #else /* !CONFIG_DEBUG_PER_CPU_MAPS */
@@ -393,7 +391,6 @@ void debug_cpumask_set_cpu(unsigned int cpu, int node, bool enable)return ; } -# ifndef CONFIG_NUMA_EMU static void numa_set_cpumask (int cpu,bool enable) {debug_cpumask_set_cpu (cpu,early_cpu_to_node (cpu), enable);
@@ -408,7 +405,6 @@ void numa_remove_cpu(unsigned int cpu) {numa_set_cpumask (cpu, false); } -# endif /* !CONFIG_NUMA_EMU */ /* * Returns a pointer to the bitmask of CPUs on Node 'node'.
include/asm-generic/numa.h +0 -4
@@ -49,8 +49,4 @@ static inline int early_cpu_to_node(int cpu) { return 0; }#endif /* CONFIG_NUMA */ -#ifdef CONFIG_NUMA_EMU -void debug_cpumask_set_cpu (unsigned int cpu,int node,bool enable); -#endif -#endif /* __ASM_GENERIC_NUMA_H */
mm/arch_numa.c +0 -26
@@ -59,7 +59,6 @@ EXPORT_SYMBOL(cpumask_of_node);#endif -#ifndef CONFIG_NUMA_EMU static void numa_update_cpu (unsigned int cpu,bool remove) {int nid =cpu_to_node (cpu);
@@ -82,7 +81,6 @@ void numa_remove_cpu(unsigned int cpu) {numa_update_cpu (cpu, true); } -#endif void numa_clear_node (unsigned int cpu) {
@@ -356,28 +354,4 @@ u64 __init numa_emu_dma_end(void) {return memblock_start_of_DRAM () +SZ_4G ; } - -void debug_cpumask_set_cpu (unsigned int cpu,int node,bool enable) -{ -struct cpumask *mask; - -if (node ==NUMA_NO_NODE ) -return ; - - mask = node_to_cpumask_map[node]; -if (!cpumask_available (mask)) { -pr_err ("node_to_cpumask_map[%i] NULL\n" , node); -dump_stack (); -return ; - } - -if (enable) -cpumask_set_cpu (cpu, mask); -else -cpumask_clear_cpu (cpu, mask); - -pr_debug ("%s cpu %d node %d: mask now %*pbl\n" , - enable ?"numa_add_cpu" :"numa_remove_cpu" , - cpu, node,cpumask_pr_args (mask)); -}#endif /* CONFIG_NUMA_EMU */
mm/numa_emulation.c +3 -64
78 lines not on this page · raw message
base-commit: 95a4df9944cd5d57a92662269114ba99cb972394
Signature · 1 line
2.56.0
PATCH v2 2/2 sched_ext/idle: Skip nodes without CPUs
In reply to Cheng-Yang ChouWith SCX_OPS_BUILTIN_IDLE_PER_NODE, a CPU is tracked in the idle cpumask of cpu_to_node(cpu). When the starting node has no idle CPU, pick_idle_cpu_from_online_nodes() walks the other online nodes in distance order. Nodes without CPUs, such as memory-only nodes, can't have an idle one, but the walk still visits them.
Walk only the nodes that have CPUs.
On a Raspberry Pi 5, whose firmware adds numa=fake=8, the previous patch leaves CPUs only in node 0. Five hackbench -p -g 10 -l 10000 runs under scx_simple, without and with both patches, gave these means (ops.select_cpu() time per call, run time):
global idle cpumask per-node idle cpumasks before 135ns, 7.39s 484ns, 7.49s after 139ns, 7.36s 141ns, 7.37s
--- kernel/sched/ext/idle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/ext/idle.c +2 -2
@@ -168,10 +168,10 @@ static s32 pick_idle_cpu_from_online_nodes(const struct cpumask *cpus_allowed, i unvisited =this_cpu_ptr (&per_cpu_unvisited);/* -* Restrict the search to the online nodes (excluding the current +* Restrict the search to the nodes with CPUs (excluding the current * node that has been visited already). */ -nodes_copy (*unvisited, node_states[N_ONLINE ]); +nodes_copy (*unvisited, node_states[N_CPU ]);node_clear (node, *unvisited);/*
Signature · 1 line
2.56.0
Tejun Heo
reviewerRe: [PATCH v2 mm and sched_ext/for-7.5 2/2] sched_ext/idle: Skip nodes without CPUs
Applied 2 to sched_ext/for-7.5 with the benchmark paragraph dropped from the description as the numbers depend on patch 1.
Thanks.
--
tejun