Skip to contentSkip to conversation

cpumask: Fall back to online CPUs when NUMA lookup fails

PATCH In review Hui Su 2 participants 2 messages Oct 21 – Oct 23

Subsystems (2)
lore
Share & tools
lore

Hui Su

author
#0 lore raw

PATCH 1/1 cpumask: Fall back to online CPUs when NUMA lookup fails

cpumask_local_spread() wraps the requested index by the number of online CPUs, but sched_numa_find_nth_cpu() can return nr_cpu_ids when NUMA ordering masks are unavailable.

This can happen after a sched_init_numa() allocation failure or while the NUMA topology is being rebuilt.

Since b1beed72b8b75, cpumask_local_spread() warns about the invalid result but still returns it to callers expecting a valid CPU number.

When the NUMA lookup fails, warn once and fall back to the corresponding entry in cpu_online_mask. This preserves a valid CPU result when the online mask is stable, at the expense of NUMA ordering while the topology information is unavailable.

Fixes b1beed72b8b75 ("lib/cpumask: reorganize cpumask_local_spread() logic")
---
 lib/cpumask.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/cpumask.c +3 -1
index 5adb9874fbd0f..f09632219b267 100644
@@ -114,7 +114,9 @@ unsigned int cpumask_local_spread(unsigned int i, int node)
 
 	cpu = sched_numa_find_nth_cpu(cpu_online_mask, i, node);
 
-	WARN_ON(cpu >= nr_cpu_ids);
+	if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
+		cpu = cpumask_nth(i, cpu_online_mask);
+
 	return cpu;
 }
 EXPORT_SYMBOL(cpumask_local_spread);

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.55.0
#1 lore raw
Quoted 7 lines · Hui Su

cpumask_local_spread() wraps the requested index by the number of online CPUs, but sched_numa_find_nth_cpu() can return nr_cpu_ids when NUMA ordering masks are unavailable.

This can happen after a sched_init_numa() allocation failure or while the NUMA topology is being rebuilt.

Quoted 8 lines

Since b1beed72b8b75, cpumask_local_spread() warns about the invalid result but still returns it to callers expecting a valid CPU number.

When the NUMA lookup fails, warn once and fall back to the corresponding entry in cpu_online_mask. This preserves a valid CPU result when the online mask is stable, at the expense of NUMA ordering while the topology information is unavailable.

When the topology is unavailable, it's wrong to call this function. If you do so, you anyways can't achieve optimal placement, so returning a no-found looks reasonable.

Can you explain, is this a real bug in your deployment? Can you share details?

Thanks,
Yury

Quoted 25 lines
Fixes b1beed72b8b75 ("lib/cpumask: reorganize cpumask_local_spread() logic")
---
 lib/cpumask.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/cpumask.c +3 -1
index 5adb9874fbd0f..f09632219b267 100644
@@ -114,7 +114,9 @@ unsigned int cpumask_local_spread(unsigned int i, int node)
 
 	cpu = sched_numa_find_nth_cpu(cpu_online_mask, i, node);
 
-	WARN_ON(cpu >= nr_cpu_ids);
+	if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
+		cpu = cpumask_nth(i, cpu_online_mask);
+
 	return cpu;
 }
 EXPORT_SYMBOL(cpumask_local_spread);

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.55.0