Skip to contentSkip to conversation

sched: Consider capacity for certain load balancing decisions

PATCH In review Xi Wang 3 participants 6 messages Feb 1, 2023 – Feb 7, 2023

Subsystems (2)
lore
Share & tools
lore

Xi Wang

author
#0 lore raw

PATCH 1/1 sched: Consider capacity for certain load balancing decisions

After load balancing was split into different scenarios, CPU capacity is ignored for the "migrate_task" case, which means a thread can stay on a softirq heavy cpu for an extended amount of time.

By comparing nr_running/capacity instead of just nr_running we can add CPU capacity back into "migrate_task" decisions. This benefits workloads running on machines with heavy network traffic. The change is unlikely to cause serious problems for other workloads but maybe some corner cases still need to be considered.

---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +2 -1
index 0f8736991427..aad14bc04544 100644
@@ -10368,8 +10368,9 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 			break;
 
 		case migrate_task:
-			if (busiest_nr < nr_running) {
+			if (busiest_nr * capacity < nr_running * busiest_capacity) {
 				busiest_nr = nr_running;
+				busiest_capacity = capacity;
 				busiest = rq;
 			}
 			break;
Signature · 1 line
2.39.1
maintainer
#1 lore raw
Quoted 20 lines · Xi Wang

After load balancing was split into different scenarios, CPU capacity is ignored for the "migrate_task" case, which means a thread can stay on a softirq heavy cpu for an extended amount of time.

By comparing nr_running/capacity instead of just nr_running we can add CPU capacity back into "migrate_task" decisions. This benefits workloads running on machines with heavy network traffic. The change is unlikely to cause serious problems for other workloads but maybe some corner cases still need to be considered.

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

kernel/sched/fair.c static struct rq *find_busiest_queue(struct lb_env *env, · line 10376

Quoted 10 lines
kernel/sched/fair.c +2 -1
@@ -10368,8 +10368,9 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 			break;
 
 		case migrate_task:
-			if (busiest_nr < nr_running) {
+			if (busiest_nr * capacity < nr_running * busiest_capacity) {
 				busiest_nr = nr_running;
+				busiest_capacity = capacity;
 				busiest = rq;
 			}
 			break;

I don't think this is correct. The migrate_task case is work-conserving, and your change can severely break that I think.

author
#2 lore raw
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Xi Wang

After load balancing was split into different scenarios, CPU capacity is ignored for the "migrate_task" case, which means a thread can stay on a softirq heavy cpu for an extended amount of time.

By comparing nr_running/capacity instead of just nr_running we can add CPU capacity back into "migrate_task" decisions. This benefits workloads running on machines with heavy network traffic. The change is unlikely to cause serious problems for other workloads but maybe some corner cases still need to be considered.

---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 0f8736991427..aad14bc04544 100644
@@ -10368,8 +10368,9 @@ static struct rq *find_busiest_queue(struct lb_env *env,
                      break;
 
Quoted 12 lines

kernel/sched/fair.c static struct rq *find_busiest_queue(struct lb_env *env, · line 10376

Quoted 8 lines
kernel/sched/fair.c +2 -1
              case migrate_task:
-                     if (busiest_nr < nr_running) {
+                     if (busiest_nr * capacity < nr_running * busiest_capacity) {
                              busiest_nr = nr_running;
+                             busiest_capacity = capacity;
                              busiest = rq;
                      }
                      break;

I don't think this is correct. The migrate_task case is work-conserving, and your change can severely break that I think.

I think you meant this kind of scenario:
cpu 0: idle
cpu 1: 2 tasks
cpu 2: 1 task but only has 30% of capacity
Pulling from cpu 2 is good for the task but lowers the overall cpu throughput.

The problem we have is:
cpu 0: idle
cpu 1: 1 task
cpu 2: 1 task but only has 60% of capacity due to net softirq The task on cpu 2 stays there and runs slower. (This can also be considered non work-conserving if we account softirq like a task.)

Maybe the logic can be merged like this: Use capacity but pick from nr_running > 1 cpus first, then nr_running == 1 cpus if not found.

maintainer
#3 lore raw
Quoted 46 lines · Xi Wang
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Xi Wang

After load balancing was split into different scenarios, CPU capacity is ignored for the "migrate_task" case, which means a thread can stay on a softirq heavy cpu for an extended amount of time.

By comparing nr_running/capacity instead of just nr_running we can add CPU capacity back into "migrate_task" decisions. This benefits workloads running on machines with heavy network traffic. The change is unlikely to cause serious problems for other workloads but maybe some corner cases still need to be considered.

---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 0f8736991427..aad14bc04544 100644
@@ -10368,8 +10368,9 @@ static struct rq *find_busiest_queue(struct lb_env *env,
                      break;
 
Quoted 12 lines

kernel/sched/fair.c static struct rq *find_busiest_queue(struct lb_env *env, · line 10376

Quoted 8 lines
kernel/sched/fair.c +2 -1
              case migrate_task:
-                     if (busiest_nr < nr_running) {
+                     if (busiest_nr * capacity < nr_running * busiest_capacity) {
                              busiest_nr = nr_running;
+                             busiest_capacity = capacity;
                              busiest = rq;
                      }
                      break;

I don't think this is correct. The migrate_task case is work-conserving, and your change can severely break that I think.

I think you meant this kind of scenario:
cpu 0: idle
cpu 1: 2 tasks
cpu 2: 1 task but only has 30% of capacity
Pulling from cpu 2 is good for the task but lowers the overall cpu throughput.

Quoted 6 lines

The problem we have is:
cpu 0: idle
cpu 1: 1 task
cpu 2: 1 task but only has 60% of capacity due to net softirq The task on cpu 2 stays there and runs slower. (This can also be considered non work-conserving if we account softirq like a task.)

When load_balance runs for this 2 cpus, cpu2 should be tagged as misfit_task because of reduce_capacity and should be selected in priority by cpu0 to pull the task. Do you have more details on your topology ?

Quoted 3 lines

Maybe the logic can be merged like this: Use capacity but pick from nr_running > 1 cpus first, then nr_running == 1 cpus if not found.

author
#4 lore raw
Quoted 55 lines · Vincent Guittot
Quoted 46 lines · Xi Wang
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Xi Wang

After load balancing was split into different scenarios, CPU capacity is ignored for the "migrate_task" case, which means a thread can stay on a softirq heavy cpu for an extended amount of time.

By comparing nr_running/capacity instead of just nr_running we can add CPU capacity back into "migrate_task" decisions. This benefits workloads running on machines with heavy network traffic. The change is unlikely to cause serious problems for other workloads but maybe some corner cases still need to be considered.

---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 0f8736991427..aad14bc04544 100644
@@ -10368,8 +10368,9 @@ static struct rq *find_busiest_queue(struct lb_env *env,
                      break;
 
Quoted 12 lines

kernel/sched/fair.c static struct rq *find_busiest_queue(struct lb_env *env, · line 10376

Quoted 8 lines
kernel/sched/fair.c +2 -1
              case migrate_task:
-                     if (busiest_nr < nr_running) {
+                     if (busiest_nr * capacity < nr_running * busiest_capacity) {
                              busiest_nr = nr_running;
+                             busiest_capacity = capacity;
                              busiest = rq;
                      }
                      break;

I don't think this is correct. The migrate_task case is work-conserving, and your change can severely break that I think.

I think you meant this kind of scenario:
cpu 0: idle
cpu 1: 2 tasks
cpu 2: 1 task but only has 30% of capacity
Pulling from cpu 2 is good for the task but lowers the overall cpu throughput.

Quoted 6 lines

The problem we have is:
cpu 0: idle
cpu 1: 1 task
cpu 2: 1 task but only has 60% of capacity due to net softirq The task on cpu 2 stays there and runs slower. (This can also be considered non work-conserving if we account softirq like a task.)

Quoted 4 lines

When load_balance runs for this 2 cpus, cpu2 should be tagged as misfit_task because of reduce_capacity and should be selected in priority by cpu0 to pull the task. Do you have more details on your topology ?

The topology is 64 core AMD with 2 hyperthreads.

I am not familiar with the related code but I think there are cases where a task fits cpu capacity but it can still run faster elsewhere, e.g.: Bursty workloads. Thread pool threads with variable utilization because it would process more or less requests based on cpu availability (pick the next request from a shared queue when the previous one is done). A thread having enough cpu cycles but runs slower due to softirqs can also directly affect application performance.

Quoted 3 lines
Quoted 3 lines

Maybe the logic can be merged like this: Use capacity but pick from nr_running > 1 cpus first, then nr_running == 1 cpus if not found.

maintainer
#5 lore raw
Quoted 65 lines · Xi Wang
Quoted 55 lines · Vincent Guittot
Quoted 46 lines · Xi Wang
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Xi Wang

After load balancing was split into different scenarios, CPU capacity is ignored for the "migrate_task" case, which means a thread can stay on a softirq heavy cpu for an extended amount of time.

By comparing nr_running/capacity instead of just nr_running we can add CPU capacity back into "migrate_task" decisions. This benefits workloads running on machines with heavy network traffic. The change is unlikely to cause serious problems for other workloads but maybe some corner cases still need to be considered.

---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 0f8736991427..aad14bc04544 100644
@@ -10368,8 +10368,9 @@ static struct rq *find_busiest_queue(struct lb_env *env,
                      break;
 
Quoted 12 lines

kernel/sched/fair.c static struct rq *find_busiest_queue(struct lb_env *env, · line 10376

Quoted 8 lines
kernel/sched/fair.c +2 -1
              case migrate_task:
-                     if (busiest_nr < nr_running) {
+                     if (busiest_nr * capacity < nr_running * busiest_capacity) {
                              busiest_nr = nr_running;
+                             busiest_capacity = capacity;
                              busiest = rq;
                      }
                      break;

I don't think this is correct. The migrate_task case is work-conserving, and your change can severely break that I think.

I think you meant this kind of scenario:
cpu 0: idle
cpu 1: 2 tasks
cpu 2: 1 task but only has 30% of capacity
Pulling from cpu 2 is good for the task but lowers the overall cpu throughput.

Quoted 6 lines

The problem we have is:
cpu 0: idle
cpu 1: 1 task
cpu 2: 1 task but only has 60% of capacity due to net softirq The task on cpu 2 stays there and runs slower. (This can also be considered non work-conserving if we account softirq like a task.)

Quoted 4 lines

When load_balance runs for this 2 cpus, cpu2 should be tagged as misfit_task because of reduce_capacity and should be selected in priority by cpu0 to pull the task. Do you have more details on your topology ?

The topology is 64 core AMD with 2 hyperthreads.

Quoted 8 lines

I am not familiar with the related code but I think there are cases where a task fits cpu capacity but it can still run faster elsewhere, e.g.: Bursty workloads. Thread pool threads with variable utilization because it would process more or less requests based on cpu availability (pick the next request from a shared queue when the previous one is done). A thread having enough cpu cycles but runs slower due to softirqs can also directly affect application performance.

misfit_task is also used to detect CPUs with reduced capacity. We can have a look at update_sg_lb_stats(). Your use case above should fall in this case

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Maybe the logic can be merged like this: Use capacity but pick from nr_running > 1 cpus first, then nr_running == 1 cpus if not found.