Skip to content

Commit eb95308

Browse files
Peter Zijlstraingomolnar
authored andcommitted
sched: Fix more load-balancing fallout
Commits 367456c ("sched: Ditch per cgroup task lists for load-balancing") and 5d6523e ("sched: Fix load-balance wreckage") left some more wreckage. By setting loop_max unconditionally to ->nr_running load-balancing could take a lot of time on very long runqueues (hackbench!). So keep the sysctl as max limit of the amount of tasks we'll iterate. Furthermore, the min load filter for migration completely fails with cgroups since inequality in per-cpu state can easily lead to such small loads :/ Furthermore the change to add new tasks to the tail of the queue instead of the head seems to have some effect.. not quite sure I understand why. Combined these fixes solve the huge hackbench regression reported by Tim when hackbench is ran in a cgroup. Reported-by: Tim Chen <tim.c.chen@linux.intel.com> Acked-by: Tim Chen <tim.c.chen@linux.intel.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/r/1335365763.28150.267.camel@twins [ got rid of the CONFIG_PREEMPT tuning and made small readability edits ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 2300fd6 commit eb95308

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎kernel/sched/fair.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ account_entity_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
784784
update_load_add(&rq_of(cfs_rq)->load, se->load.weight);
785785
#ifdef CONFIG_SMP
786786
if (entity_is_task(se))
787-
list_add_tail(&se->group_node, &rq_of(cfs_rq)->cfs_tasks);
787+
list_add(&se->group_node, &rq_of(cfs_rq)->cfs_tasks);
788788
#endif
789789
cfs_rq->nr_running++;
790790
}
@@ -3215,6 +3215,8 @@ static int move_one_task(struct lb_env *env)
32153215

32163216
static unsigned long task_h_load(struct task_struct *p);
32173217

3218+
static const unsigned int sched_nr_migrate_break = 32;
3219+
32183220
/*
32193221
* move_tasks tries to move up to load_move weighted load from busiest to
32203222
* this_rq, as part of a balancing operation within domain "sd".
@@ -3242,7 +3244,7 @@ static int move_tasks(struct lb_env *env)
32423244

32433245
/* take a breather every nr_migrate tasks */
32443246
if (env->loop > env->loop_break) {
3245-
env->loop_break += sysctl_sched_nr_migrate;
3247+
env->loop_break += sched_nr_migrate_break;
32463248
env->flags |= LBF_NEED_BREAK;
32473249
break;
32483250
}
@@ -3252,7 +3254,7 @@ static int move_tasks(struct lb_env *env)
32523254

32533255
load = task_h_load(p);
32543256

3255-
if (load < 16 && !env->sd->nr_balance_failed)
3257+
if (sched_feat(LB_MIN) && load < 16 && !env->sd->nr_balance_failed)
32563258
goto next;
32573259

32583260
if ((load / 2) > env->load_move)
@@ -4407,7 +4409,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
44074409
.dst_cpu = this_cpu,
44084410
.dst_rq = this_rq,
44094411
.idle = idle,
4410-
.loop_break = sysctl_sched_nr_migrate,
4412+
.loop_break = sched_nr_migrate_break,
44114413
};
44124414

44134415
cpumask_copy(cpus, cpu_active_mask);
@@ -4445,10 +4447,10 @@ static int load_balance(int this_cpu, struct rq *this_rq,
44454447
* correctly treated as an imbalance.
44464448
*/
44474449
env.flags |= LBF_ALL_PINNED;
4448-
env.load_move = imbalance;
4449-
env.src_cpu = busiest->cpu;
4450-
env.src_rq = busiest;
4451-
env.loop_max = busiest->nr_running;
4450+
env.load_move = imbalance;
4451+
env.src_cpu = busiest->cpu;
4452+
env.src_rq = busiest;
4453+
env.loop_max = min_t(unsigned long, sysctl_sched_nr_migrate, busiest->nr_running);
44524454

44534455
more_balance:
44544456
local_irq_save(flags);

‎kernel/sched/features.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ SCHED_FEAT(TTWU_QUEUE, true)
6868

6969
SCHED_FEAT(FORCE_SD_OVERLAP, false)
7070
SCHED_FEAT(RT_RUNTIME_SHARE, true)
71+
SCHED_FEAT(LB_MIN, false)

0 commit comments

Comments
 (0)