Skip to contentSkip to conversation

sched/fair: simplify task_numa_find_cpu()

PATCH Superseded Yury Norov 3 participants 3 messages Sep 11, 2025 – Sep 12, 2025 Scheduler

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH 1/1 sched/fair: simplify task_numa_find_cpu()

From: Yury Norov (NVIDIA) <[email protected]>

Use for_each_cpu_and() and drop some housekeeping code.

---
 kernel/sched/fair.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/sched/fair.c +2 -5
index 0990ed90c14e..c48c0975fe7a 100644
@@ -2474,11 +2474,8 @@ static void task_numa_find_cpu(struct task_numa_env *env,
 		maymove = !load_too_imbalanced(src_load, dst_load, env);
 	}
 
-	for_each_cpu(cpu, cpumask_of_node(env->dst_nid)) {
-		/* Skip this CPU if the source task cannot migrate */
-		if (!cpumask_test_cpu(cpu, env->p->cpus_ptr))
-			continue;
-
+	/* Skip CPUs if the source task cannot migrate */
+	for_each_cpu_and(cpu, cpumask_of_node(env->dst_nid), env->p->cpus_ptr) {
 		env->dst_cpu = cpu;
 		if (task_numa_compare(env, taskimp, groupimp, maymove))
 			break;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Thu, Sep 11, 2025 at 04:31:35PM -0400 Yury Norov wrote:

From: Yury Norov (NVIDIA) <[email protected]>

Use for_each_cpu_and() and drop some housekeeping code.

The "housekeeping" part threw me off for a second. I was looking for isolation related code being dropped :)

Quoted 26 lines
---
 kernel/sched/fair.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/sched/fair.c +2 -5
index 0990ed90c14e..c48c0975fe7a 100644
@@ -2474,11 +2474,8 @@ static void task_numa_find_cpu(struct task_numa_env *env,
 		maymove = !load_too_imbalanced(src_load, dst_load, env);
 	}
 
-	for_each_cpu(cpu, cpumask_of_node(env->dst_nid)) {
-		/* Skip this CPU if the source task cannot migrate */
-		if (!cpumask_test_cpu(cpu, env->p->cpus_ptr))
-			continue;
-
+	/* Skip CPUs if the source task cannot migrate */
+	for_each_cpu_and(cpu, cpumask_of_node(env->dst_nid), env->p->cpus_ptr) {
 		env->dst_cpu = cpu;
 		if (task_numa_compare(env, taskimp, groupimp, maymove))
 			break;
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Yury Norov

Hello Yury,

Quoted 3 lines · Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

Use for_each_cpu_and() and drop some housekeeping code.

Please feel free to include:

Quoted 24 lines
---
 kernel/sched/fair.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/sched/fair.c +2 -5
index 0990ed90c14e..c48c0975fe7a 100644
@@ -2474,11 +2474,8 @@ static void task_numa_find_cpu(struct task_numa_env *env,
 		maymove = !load_too_imbalanced(src_load, dst_load, env);
 	}
 
-	for_each_cpu(cpu, cpumask_of_node(env->dst_nid)) {
-		/* Skip this CPU if the source task cannot migrate */
-		if (!cpumask_test_cpu(cpu, env->p->cpus_ptr))
-			continue;
-
+	/* Skip CPUs if the source task cannot migrate */
+	for_each_cpu_and(cpu, cpumask_of_node(env->dst_nid), env->p->cpus_ptr) {
 		env->dst_cpu = cpu;
 		if (task_numa_compare(env, taskimp, groupimp, maymove))
 			break;
Signature · 2 lines
Thanks and Regards,
Prateek