From 875ee1e15641e6662264f9279b12cba1f1d3c4fc Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 21 Sep 2003 01:38:16 -0700 Subject: [PATCH] [PATCH] CPU scheduler balancing fix From: Nick Piggin The patch changes the imbalance required before a balance to 25% from 50% - as the comments intend. It also changes a case where the balancing wouldn't be done if the imbalance was >= 25% but only 1 task difference. The downside of the second change is that one task may bounce from one cpu to another for some loads. This will only bounce once every 200ms, so it shouldn't be a big problem. (Benchmarking results are basically a wash - SDET is increased maybe 0.5%) --- kernel/sched.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/sched.c b/kernel/sched.c index 966dfe516ec5e..38fa1ac0f82b4 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -995,10 +995,10 @@ static inline runqueue_t *find_busiest_queue(runqueue_t *this_rq, int this_cpu, if (likely(!busiest)) goto out; - *imbalance = (max_load - nr_running) / 2; + *imbalance = max_load - nr_running; /* It needs an at least ~25% imbalance to trigger balancing. */ - if (!idle && (*imbalance < (max_load + 3)/4)) { + if (!idle && ((*imbalance)*4 < max_load)) { busiest = NULL; goto out; } @@ -1008,7 +1008,7 @@ static inline runqueue_t *find_busiest_queue(runqueue_t *this_rq, int this_cpu, * Make sure nothing changed since we checked the * runqueue length. */ - if (busiest->nr_running <= nr_running + 1) { + if (busiest->nr_running <= nr_running) { spin_unlock(&busiest->lock); busiest = NULL; } @@ -1057,6 +1057,12 @@ static void load_balance(runqueue_t *this_rq, int idle, cpumask_t cpumask) goto out; now = sched_clock(); + /* + * We only want to steal a number of tasks equal to 1/2 the imbalance, + * otherwise we'll just shift the imbalance to the new queue: + */ + imbalance /= 2; + /* * We first consider expired tasks. Those will likely not be * executed in the near future, and they are most likely to -- 2.53.0