Skip to contentSkip to conversation

Revert "sched/fair: Make sure to try to detach at least one movable task"

PATCH Applied Josh Don 4 participants 6 messages Jun 20, 2024 – Jul 1, 2024 Scheduler

lore
Share & tools
lore

Josh Don

author
#0 lore raw

PATCH 1/1 Revert "sched/fair: Make sure to try to detach at least one movable task"

This reverts commit b0defa7ae03ecf91b8bfd10ede430cff12fcbd06.

b0defa7ae03ec changed the load balancing logic to ignore env.max_loop if all tasks examined to that point were pinned. The goal of the patch was to make it more likely to be able to detach a task buried in a long list of pinned tasks. However, this has the unfortunate side effect of creating an O(n) iteration in detach_tasks(), as we now must fully iterate every task on a cpu if all or most are pinned. Since this load balance code is done with rq lock held, and often in softirq context, it is very easy to trigger hard lockups. We observed such hard lockups with a user who affined O(10k) threads to a single cpu.

When I discussed this with Vincent he initially suggested that we keep the limit on the number of tasks to detach, but increase the number of tasks we can search. However, after some back and forth on the mailing list, he recommended we instead revert the original patch, as it seems likely no one was actually getting hit by the original issue.

---
 kernel/sched/fair.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/sched/fair.c +3 -9
index 34fe6e9490c2..a5416798702b 100644
@@ -9043,12 +9043,8 @@ static int detach_tasks(struct lb_env *env)
 			break;
 
 		env->loop++;
-		/*
-		 * We've more or less seen every task there is, call it quits
-		 * unless we haven't found any movable task yet.
-		 */
-		if (env->loop > env->loop_max &&
-		    !(env->flags & LBF_ALL_PINNED))
+		/* We've more or less seen every task there is, call it quits */
+		if (env->loop > env->loop_max)
 			break;
 
 		/* take a breather every nr_migrate tasks */
@@ -11328,9 +11324,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
 
 		if (env.flags & LBF_NEED_BREAK) {
 			env.flags &= ~LBF_NEED_BREAK;
-			/* Stop if we tried all running tasks */
-			if (env.loop < busiest->nr_running)
-				goto more_balance;
+			goto more_balance;
 		}
 
 		/*
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Josh Don

This reverts commit b0defa7ae03ecf91b8bfd10ede430cff12fcbd06.

b0defa7ae03ec changed the load balancing logic to ignore env.max_loop if all tasks examined to that point were pinned. The goal of the patch was to make it more likely to be able to detach a task buried in a long list of pinned tasks. However, this has the unfortunate side effect of creating an O(n) iteration in detach_tasks(), as we now must fully iterate every task on a cpu if all or most are pinned. Since this load balance code is done with rq lock held, and often in softirq context, it is very easy to trigger hard lockups. We observed such hard lockups with a user who affined O(10k) threads to a single cpu.

Quoted 6 lines

When I discussed this with Vincent he initially suggested that we keep the limit on the number of tasks to detach, but increase the number of tasks we can search. However, after some back and forth on the mailing list, he recommended we instead revert the original patch, as it seems likely no one was actually getting hit by the original issue.

Maybe add a

Fixes b0defa7ae03e ("sched/fair: Make sure to try to detach at least

one movable task")

Quoted 1 line
Quoted 37 lines
---
 kernel/sched/fair.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/sched/fair.c +3 -10
index 34fe6e9490c2..a5416798702b 100644
@@ -9043,12 +9043,8 @@ static int detach_tasks(struct lb_env *env)
                        break;
 
                env->loop++;
-               /*
-                * We've more or less seen every task there is, call it quits
-                * unless we haven't found any movable task yet.
-                */
-               if (env->loop > env->loop_max &&
-                   !(env->flags & LBF_ALL_PINNED))
+               /* We've more or less seen every task there is, call it quits */
+               if (env->loop > env->loop_max)
                        break;
 
                /* take a breather every nr_migrate tasks */
@@ -11328,9 +11324,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
 
                if (env.flags & LBF_NEED_BREAK) {
                        env.flags &= ~LBF_NEED_BREAK;
-                       /* Stop if we tried all running tasks */
-                       if (env.loop < busiest->nr_running)
-                               goto more_balance;
+                       goto more_balance;
                }
 
                /*
--

2.45.2.741.gdbec12cfda-goog

author
#2 lore raw
Quoted 22 lines · Vincent Guittot
Quoted 13 lines · Josh Don

This reverts commit b0defa7ae03ecf91b8bfd10ede430cff12fcbd06.

b0defa7ae03ec changed the load balancing logic to ignore env.max_loop if all tasks examined to that point were pinned. The goal of the patch was to make it more likely to be able to detach a task buried in a long list of pinned tasks. However, this has the unfortunate side effect of creating an O(n) iteration in detach_tasks(), as we now must fully iterate every task on a cpu if all or most are pinned. Since this load balance code is done with rq lock held, and often in softirq context, it is very easy to trigger hard lockups. We observed such hard lockups with a user who affined O(10k) threads to a single cpu.

Quoted 6 lines

When I discussed this with Vincent he initially suggested that we keep the limit on the number of tasks to detach, but increase the number of tasks we can search. However, after some back and forth on the mailing list, he recommended we instead revert the original patch, as it seems likely no one was actually getting hit by the original issue.

Quoted 3 lines

Maybe add a

Fixes b0defa7ae03e ("sched/fair: Make sure to try to detach at least

one movable task")

Ack

Quoted 4 lines
Quoted 2 lines

Thanks Vincent!

maintainer
#3 lore raw
In reply to Vincent Guittot
Quoted 21 lines · Vincent Guittot
Quoted 13 lines · Josh Don

This reverts commit b0defa7ae03ecf91b8bfd10ede430cff12fcbd06.

b0defa7ae03ec changed the load balancing logic to ignore env.max_loop if all tasks examined to that point were pinned. The goal of the patch was to make it more likely to be able to detach a task buried in a long list of pinned tasks. However, this has the unfortunate side effect of creating an O(n) iteration in detach_tasks(), as we now must fully iterate every task on a cpu if all or most are pinned. Since this load balance code is done with rq lock held, and often in softirq context, it is very easy to trigger hard lockups. We observed such hard lockups with a user who affined O(10k) threads to a single cpu.

Quoted 6 lines

When I discussed this with Vincent he initially suggested that we keep the limit on the number of tasks to detach, but increase the number of tasks we can search. However, after some back and forth on the mailing list, he recommended we instead revert the original patch, as it seems likely no one was actually getting hit by the original issue.

Quoted 7 lines

Maybe add a

Fixes b0defa7ae03e ("sched/fair: Make sure to try to detach at least

one movable task")

Quoted 1 line

Thanks guys, queued it for sched/urgent

merge bot Applied
#4 lore raw
In reply to Josh Don
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     05f8404bcdf31822874bff41992336150240c109
Gitweb:        https://git.kernel.org/tip/05f8404bcdf31822874bff41992336150240c109
Author:        Josh Don <[email protected]>
AuthorDate:    Thu, 20 Jun 2024 14:44:50 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 25 Jun 2024 10:43:41 +02:00

Revert "sched/fair: Make sure to try to detach at least one movable task"

This reverts commit b0defa7ae03ecf91b8bfd10ede430cff12fcbd06.

b0defa7ae03ec changed the load balancing logic to ignore env.max_loop if all tasks examined to that point were pinned. The goal of the patch was to make it more likely to be able to detach a task buried in a long list of pinned tasks. However, this has the unfortunate side effect of creating an O(n) iteration in detach_tasks(), as we now must fully iterate every task on a cpu if all or most are pinned. Since this load balance code is done with rq lock held, and often in softirq context, it is very easy to trigger hard lockups. We observed such hard lockups with a user who affined O(10k) threads to a single cpu.

When I discussed this with Vincent he initially suggested that we keep the limit on the number of tasks to detach, but increase the number of tasks we can search. However, after some back and forth on the mailing list, he recommended we instead revert the original patch, as it seems likely no one was actually getting hit by the original issue.

Fixes b0defa7ae03e ("sched/fair: Make sure to try to detach at least one movable task")
---
 kernel/sched/fair.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/sched/fair.c +3 -9
index 8a5b1ae..24dda70 100644
@@ -9149,12 +9149,8 @@ static int detach_tasks(struct lb_env *env)
 			break;
 
 		env->loop++;
-		/*
-		 * We've more or less seen every task there is, call it quits
-		 * unless we haven't found any movable task yet.
-		 */
-		if (env->loop > env->loop_max &&
-		    !(env->flags & LBF_ALL_PINNED))
+		/* We've more or less seen every task there is, call it quits */
+		if (env->loop > env->loop_max)
 			break;
 
 		/* take a breather every nr_migrate tasks */
@@ -11393,9 +11389,7 @@ more_balance:
 
 		if (env.flags & LBF_NEED_BREAK) {
 			env.flags &= ~LBF_NEED_BREAK;
-			/* Stop if we tried all running tasks */
-			if (env.loop < busiest->nr_running)
-				goto more_balance;
+			goto more_balance;
 		}
 
 		/*
merge bot Applied
#5 lore raw
In reply to Josh Don
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     2feab2492deb2f14f9675dd6388e9e2bf669c27a
Gitweb:        https://git.kernel.org/tip/2feab2492deb2f14f9675dd6388e9e2bf669c27a
Author:        Josh Don <[email protected]>
AuthorDate:    Thu, 20 Jun 2024 14:44:50 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 01 Jul 2024 13:01:43 +02:00

Revert "sched/fair: Make sure to try to detach at least one movable task"

This reverts commit b0defa7ae03ecf91b8bfd10ede430cff12fcbd06.

b0defa7ae03ec changed the load balancing logic to ignore env.max_loop if all tasks examined to that point were pinned. The goal of the patch was to make it more likely to be able to detach a task buried in a long list of pinned tasks. However, this has the unfortunate side effect of creating an O(n) iteration in detach_tasks(), as we now must fully iterate every task on a cpu if all or most are pinned. Since this load balance code is done with rq lock held, and often in softirq context, it is very easy to trigger hard lockups. We observed such hard lockups with a user who affined O(10k) threads to a single cpu.

When I discussed this with Vincent he initially suggested that we keep the limit on the number of tasks to detach, but increase the number of tasks we can search. However, after some back and forth on the mailing list, he recommended we instead revert the original patch, as it seems likely no one was actually getting hit by the original issue.

Fixes b0defa7ae03e ("sched/fair: Make sure to try to detach at least one movable task")
---
 kernel/sched/fair.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/sched/fair.c +3 -9
index 8a5b1ae..24dda70 100644
@@ -9149,12 +9149,8 @@ static int detach_tasks(struct lb_env *env)
 			break;
 
 		env->loop++;
-		/*
-		 * We've more or less seen every task there is, call it quits
-		 * unless we haven't found any movable task yet.
-		 */
-		if (env->loop > env->loop_max &&
-		    !(env->flags & LBF_ALL_PINNED))
+		/* We've more or less seen every task there is, call it quits */
+		if (env->loop > env->loop_max)
 			break;
 
 		/* take a breather every nr_migrate tasks */
@@ -11393,9 +11389,7 @@ more_balance:
 
 		if (env.flags & LBF_NEED_BREAK) {
 			env.flags &= ~LBF_NEED_BREAK;
-			/* Stop if we tried all running tasks */
-			if (env.loop < busiest->nr_running)
-				goto more_balance;
+			goto more_balance;
 		}
 
 		/*