Skip to contentSkip to conversation

sched/fair: fix update the nohz.next_balance even if we haven't done any load balance

PATCH Superseded Wanpeng Li 3 participants 4 messages Mar 27, 2015 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 1/1 sched/fair: fix update the nohz.next_balance even if we haven't done any load balance

As Srikar pointed out (https://lkml.org/lkml/2015/3/27/26):

| With the current code when the ilb cpus are not free: 
| - We would be updating the nohz.next_balance even through we havent done
|   any load balance.
| - We might iterate thro the nohz.idle_cpus_mask()s to find balance_cpus.

This patch fix it by adding need_resched check with the idle check, and keep the need_resched check in for loop to catch ilb get busy.

---
 kernel/sched/fair.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/fair.c +2 -1
index 0576ce0..1d3e17f 100644
@@ -7639,7 +7639,8 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	int balance_cpu;
 
 	if (idle != CPU_IDLE ||
-	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
+	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)) ||
+		need_resched())
 		goto end;
 
 	for_each_cpu(balance_cpu, nohz.idle_cpus_mask) {
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Wanpeng Li

As Srikar pointed out (https://lkml.org/lkml/2015/3/27/26):

| With the current code when the ilb cpus are not free: 
| - We would be updating the nohz.next_balance even through we havent done
|   any load balance.
| - We might iterate thro the nohz.idle_cpus_mask()s to find balance_cpus.

This patch fix it by adding need_resched check with the idle check, and keep the need_resched check in for loop to catch ilb get busy.

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

kernel/sched/fair.c static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) · line 7644

Quoted 7 lines
kernel/sched/fair.c +2 -1
@@ -7639,7 +7639,8 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	int balance_cpu;
 
 	if (idle != CPU_IDLE ||
-	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
+	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)) ||
+		need_resched())
 		goto end;

How about having:

	if (idle != CPU_IDLE || need_resched() ||
	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))

which wouldn't require adding a new line.

Besides that:

author
#2 lore raw
Quoted 32 lines · Jason Low
Quoted 21 lines · Wanpeng Li

As Srikar pointed out (https://lkml.org/lkml/2015/3/27/26):

| With the current code when the ilb cpus are not free: 
| - We would be updating the nohz.next_balance even through we havent done
|   any load balance.
| - We might iterate thro the nohz.idle_cpus_mask()s to find balance_cpus.

This patch fix it by adding need_resched check with the idle check, and keep the need_resched check in for loop to catch ilb get busy.

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

kernel/sched/fair.c static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) · line 7644

Quoted 7 lines
kernel/sched/fair.c +2 -1
@@ -7639,7 +7639,8 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	int balance_cpu;
 
 	if (idle != CPU_IDLE ||
-	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
+	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)) ||
+		need_resched())
 		goto end;

How about having:

Quoted 4 lines
	if (idle != CPU_IDLE || need_resched() ||
	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))

which wouldn't require adding a new line.

Will do.

Quoted 4 lines

Besides that:

Thanks, ;)

Regards,
Wanpeng Li

#3 lore raw
In reply to Wanpeng Li

Hi Wanpeng,

Quoted 21 lines · Wanpeng Li

As Srikar pointed out (https://lkml.org/lkml/2015/3/27/26):

| With the current code when the ilb cpus are not free: 
| - We would be updating the nohz.next_balance even through we havent done
|   any load balance.
| - We might iterate thro the nohz.idle_cpus_mask()s to find balance_cpus.

This patch fix it by adding need_resched check with the idle check, and keep the need_resched check in for loop to catch ilb get busy.

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

kernel/sched/fair.c static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) · line 7646

Quoted 9 lines
kernel/sched/fair.c +2 -1
@@ -7639,7 +7639,8 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	int balance_cpu;
 
 	if (idle != CPU_IDLE ||
-	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
+	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)) ||
+		need_resched())
 		goto end;
 
 	for_each_cpu(balance_cpu, nohz.idle_cpus_mask) {

If need_resched() becomes true between this point and the test within the 'for' loop, you will end up with the original problem again. So the patch does not completely solve the said problem. Besides, are we really going to gain measurable performance with this patch?

Regards
Preeti U Murthy

Quoted 1 line