summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMaria Yu <aiquny@codeaurora.org>2019-04-26 15:20:18 +0800
committerGeorg Veichtlbauer <georg@vware.at>2023-07-16 12:47:43 +0200
commiteccc8acbe705a20e0911ea776371d84eba53cc8e (patch)
treed04a1bd51f4395e14c17eb96f9bffb53e3348937 /kernel
parent0ffdb886996b66e1eb9bbda6e9605bf7dbca0cd1 (diff)
sched/fair: Avoid unnecessary active load balance
When find busiest group, it will avoid load balance if it is only 1 task running on src cpu. Consider race when different cpus do newly idle load balance at the same time, check src cpu nr_running to avoid unnecessary active load balance again. See the race condition example here: 1) cpu2 have 2 tasks, so cpu2 rq->nr_running == 2 and cfs.h_nr_running ==2. 2) cpu4 and cpu5 doing newly idle load balance at the same time. 3) cpu4 and cpu5 both see cpu2 sched_load_balance_sg_stats sum_nr_run=2 so they are both see cpu2 as the busiest rq. 4) cpu5 did a success migration task from cpu2, so cpu2 only have 1 task left, cpu2 rq->nr_running == 1 and cfs.h_nr_running ==1. 5) cpu4 surely goes to no_move because currently cpu4 only have 1 task which is currently running. 6) and then cpu4 goes here to check if cpu2 need active load balance. Change-Id: Ia9539a43e9769c4936f06ecfcc11864984c50c29 Signed-off-by: Maria Yu <aiquny@codeaurora.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/fair.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 941424604fdd..42f05c742846 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10456,8 +10456,10 @@ static int need_active_balance(struct lb_env *env)
* It's worth migrating the task if the src_cpu's capacity is reduced
* because of other sched_class or IRQs if more capacity stays
* available on dst_cpu.
+ * Avoid pulling the CFS task if it is the only task running.
*/
if ((env->idle != CPU_NOT_IDLE) &&
+ (env->src_rq->nr_running > 1) &&
(env->src_rq->cfs.h_nr_running == 1)) {
if ((check_cpu_capacity(env->src_rq, sd)) &&
(capacity_of(env->src_cpu)*sd->imbalance_pct < capacity_of(env->dst_cpu)*100))