Skip to content

Commit 7af632d

Browse files
sixtakuExactExampl
authored andcommitted
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> (cherry picked from commit fc61703628de002e2a5bf88e09933dbc3552d156)
1 parent 5fbd9ea commit 7af632d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

kernel/sched/fair.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10013,8 +10013,10 @@ static int need_active_balance(struct lb_env *env)
1001310013
* It's worth migrating the task if the src_cpu's capacity is reduced
1001410014
* because of other sched_class or IRQs if more capacity stays
1001510015
* available on dst_cpu.
10016+
* Avoid pulling the CFS task if it is the only task running.
1001610017
*/
1001710018
if ((env->idle != CPU_NOT_IDLE) &&
10019+
(env->src_rq->nr_running > 1) &&
1001810020
(env->src_rq->cfs.h_nr_running == 1)) {
1001910021
if ((check_cpu_capacity(env->src_rq, sd)) &&
1002010022
(capacity_of(env->src_cpu)*sd->imbalance_pct < capacity_of(env->dst_cpu)*100))

0 commit comments

Comments
 (0)