diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8233032a2f01b..5a349fcb634e8 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6561,7 +6561,15 @@ static int detach_tasks(struct lb_env *env) if (!can_migrate_task(p, env)) goto next; - load = task_h_load(p); + /* + * Depending of the number of CPUs and tasks and the + * cgroup hierarchy, task_h_load() can return a null + * value. Make sure that env->imbalance decreases + * otherwise detach_tasks() will stop only after + * detaching up to loop_max tasks. + */ + load = max_t(unsigned long, task_h_load(p), 1); + if (sched_feat(LB_MIN) && load < 16 && !env->sd->nr_balance_failed) goto next;