Skip to contentSkip to conversation

sched: fix off-by-one bug in balance_tasks()

PATCH In review Miao Xie 2 participants 3 messages Apr 15, 2009 – Apr 16, 2009

lore
Share & tools
lore

Miao Xie

author
#0 lore raw

PATCH 1/1 sched: fix off-by-one bug in balance_tasks()

If the load that need be moved equals the half weight of a task, I think it is unnecessary to move this task. Or this task will be moved back and forth.

---
 kernel/sched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
index 5724508..44926c8 100644
@@ -3085,7 +3085,7 @@ next:
 	if (!p || loops++ > sysctl_sched_nr_migrate)
 		goto out;
 
-	if ((p->se.load.weight >> 1) > rem_load_move ||
+	if ((p->se.load.weight >> 1) >= rem_load_move ||
 	    !can_migrate_task(p, busiest, this_cpu, sd, idle, &pinned)) {
 		p = iterator->next(iterator->arg);
 		goto next;
Signature · 1 line
1.6.0.3
#1 lore raw
Quoted 3 lines · Miao Xie

If the load that need be moved equals the half weight of a task, I think it is unnecessary to move this task. Or this task will be moved back and forth.

That's actually desirable. Consider the 3 tasks on 2 cpus statically infeasible scenario. There you'd want the tasks to bounce around a bit in order to provide fairness.

Quoted 18 lines
---
 kernel/sched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
index 5724508..44926c8 100644
@@ -3085,7 +3085,7 @@ next:
 	if (!p || loops++ > sysctl_sched_nr_migrate)
 		goto out;
 
-	if ((p->se.load.weight >> 1) > rem_load_move ||
+	if ((p->se.load.weight >> 1) >= rem_load_move ||
 	    !can_migrate_task(p, busiest, this_cpu, sd, idle, &pinned)) {
 		p = iterator->next(iterator->arg);
 		goto next;
author
#2 lore raw
Quoted 8 lines · on 2009-4-15 19:41 Peter Zijlstra wrote:
Quoted 3 lines · Miao Xie

If the load that need be moved equals the half weight of a task, I think it is unnecessary to move this task. Or this task will be moved back and forth.

That's actually desirable. Consider the 3 tasks on 2 cpus statically infeasible scenario. There you'd want the tasks to bounce around a bit in order to provide fairness.

I see. Thanks for your explanation.

Miao Xie

Quoted 23 lines
Quoted 19 lines
---
 kernel/sched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
index 5724508..44926c8 100644
@@ -3085,7 +3085,7 @@ next:
 	if (!p || loops++ > sysctl_sched_nr_migrate)
 		goto out;
 
-	if ((p->se.load.weight >> 1) > rem_load_move ||
+	if ((p->se.load.weight >> 1) >= rem_load_move ||
 	    !can_migrate_task(p, busiest, this_cpu, sd, idle, &pinned)) {
 		p = iterator->next(iterator->arg);
 		goto next;