[PATCH] sched: modify move_tasks() to improve load balancing outcomes
authorPeter Williams <pwil3058@bigpond.net.au>
Tue, 27 Jun 2006 09:54:36 +0000 (02:54 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 28 Jun 2006 00:32:44 +0000 (17:32 -0700)
Problem:

The move_tasks() function is designed to move UP TO the amount of load it
is asked to move and in doing this it skips over tasks looking for ones
whose load weights are less than or equal to the remaining load to be
moved.  This is (in general) a good thing but it has the unfortunate result
of breaking one of the original load balancer's good points: namely, that
(within the limits imposed by the active/expired array model and the fact
the expired is processed first) it moves high priority tasks before low
priority ones and this means there's a good chance (see active/expired
problem for why it's only a chance) that the highest priority task on the
queue but not actually on the CPU will be moved to the other CPU where (as
a high priority task) it may preempt the current task.

Solution:

Modify move_tasks() so that high priority tasks are not skipped when moving
them will make them the highest priority task on their new run queue.

Signed-off-by: Peter Williams <pwil3058@bigpond.com.au>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "Siddha, Suresh B" <suresh.b.siddha@intel.com>
Cc: "Chen, Kenneth W" <kenneth.w.chen@intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
kernel/sched.c

index 1847a4456a2dd9df3a0eba710e4f7f4fedddd22c..b4dab63c6dbdc0f29c0e368b926a7217522148ea 100644 (file)
@@ -1955,7 +1955,7 @@ static int move_tasks(runqueue_t *this_rq, int this_cpu, runqueue_t *busiest,
 {
        prio_array_t *array, *dst_array;
        struct list_head *head, *curr;
-       int idx, pulled = 0, pinned = 0;
+       int idx, pulled = 0, pinned = 0, this_min_prio;
        long rem_load_move;
        task_t *tmp;
 
@@ -1964,6 +1964,7 @@ static int move_tasks(runqueue_t *this_rq, int this_cpu, runqueue_t *busiest,
 
        rem_load_move = max_load_move;
        pinned = 1;
+       this_min_prio = this_rq->curr->prio;
 
        /*
         * We first consider expired tasks. Those will likely not be
@@ -2003,7 +2004,12 @@ skip_queue:
 
        curr = curr->prev;
 
-       if (tmp->load_weight > rem_load_move ||
+       /*
+        * To help distribute high priority tasks accross CPUs we don't
+        * skip a task if it will be the highest priority task (i.e. smallest
+        * prio value) on its new queue regardless of its load weight
+        */
+       if ((idx >= this_min_prio && tmp->load_weight > rem_load_move) ||
            !can_migrate_task(tmp, busiest, this_cpu, sd, idle, &pinned)) {
                if (curr != head)
                        goto skip_queue;
@@ -2025,6 +2031,8 @@ skip_queue:
         * and the prescribed amount of weighted load.
         */
        if (pulled < max_nr_move && rem_load_move > 0) {
+               if (idx < this_min_prio)
+                       this_min_prio = idx;
                if (curr != head)
                        goto skip_queue;
                idx++;