Skip to contentSkip to conversation

sched/fair: Don't migrate with src_cpu == dst_cpu

PATCH In review Scott Wood 2 participants 3 messages Dec 3, 2020 – Dec 7, 2020 Scheduler

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 1/1 sched/fair: Don't migrate with src_cpu == dst_cpu

Besides being a waste of time to try to move tasks to where they already are, this avoids triggering the WARN_ON_ONCE(is_migration_disabled(p)) in set_task_cpu().

---
Patch is against tip/master. Assertion was seen by running rteval on the RT tree.

 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +2 -1
index e7e21ac479a2..f443626164d4 100644
@@ -7574,7 +7574,8 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
 
 		/* Prevent to re-select dst_cpu via env's CPUs: */
 		for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) {
-			if (cpumask_test_cpu(cpu, p->cpus_ptr)) {
+			if (cpu != env->src_cpu &&
+			    cpumask_test_cpu(cpu, p->cpus_ptr)) {
 				env->flags |= LBF_DST_PINNED;
 				env->new_dst_cpu = cpu;
 				break;
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 17 lines · Scott Wood

Besides being a waste of time to try to move tasks to where they already are, this avoids triggering the WARN_ON_ONCE(is_migration_disabled(p)) in set_task_cpu().

---
Patch is against tip/master. Assertion was seen by running rteval on the RT tree.

 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index e7e21ac479a2..f443626164d4 100644

kernel/sched/fair.c int can_migrate_task(struct task_struct *p, struct lb_env *env) · line 7581

Quoted 9 lines
kernel/sched/fair.c +2 -1
@@ -7574,7 +7574,8 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
 
 		/* Prevent to re-select dst_cpu via env's CPUs: */
 		for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) {
-			if (cpumask_test_cpu(cpu, p->cpus_ptr)) {
+			if (cpu != env->src_cpu &&
+			    cpumask_test_cpu(cpu, p->cpus_ptr)) {
 				env->flags |= LBF_DST_PINNED;
 				env->new_dst_cpu = cpu;
 				break;

Do we have _any_ clue as to how we ended up in that situation? The above sounds like it should be a WARN and we should avoid getting here in the first place.

author
#2 lore raw
Quoted 21 lines · Peter Zijlstra
Quoted 20 lines · Scott Wood

Besides being a waste of time to try to move tasks to where they already are, this avoids triggering the WARN_ON_ONCE(is_migration_disabled(p)) in set_task_cpu().

---
Patch is against tip/master. Assertion was seen by running rteval on the
RT tree.

 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index e7e21ac479a2..f443626164d4 100644
@@ -7574,7 +7574,8 @@ int can_migrate_task(struct task_struct *p, struct
 lb_env *env)
 
Quoted 12 lines
Quoted 8 lines
kernel/sched/fair.c +2 -1
 		/* Prevent to re-select dst_cpu via env's CPUs: */
 		for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) {
-			if (cpumask_test_cpu(cpu, p->cpus_ptr)) {
+			if (cpu != env->src_cpu &&
+			    cpumask_test_cpu(cpu, p->cpus_ptr)) {
 				env->flags |= LBF_DST_PINNED;
 				env->new_dst_cpu = cpu;

break;

Do we have _any_ clue as to how we ended up in that situation? The above sounds like it should be a WARN and we should avoid getting here in the first place.

My initial impression was that there simply wasn't anything stopping it from happening, but digging deeper it looks like it's specific to NUMA domains with overlapping CPUs.

-Scott