Skip to contentSkip to conversation

sched/cache: Ignore non-fair current in alb_break_llc()

PATCH Superseded Kayra Cizmeci 2 participants 3 messages Oct 20 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/cache: Ignore non-fair current in alb_break_llc()

Commit d6b9afab44e23 ("sched/cache: Fix
checking active load balance by only considering the CFS task")

Stopped using task_util() for non-fair tasks. Since the values of non-fair tasks can be stale.

__active_load_balance_cpu_stop() calls detach_one_task(), that only looks to cfs_tasks list. So if the rq->curr is not fair, doing a decision according to it is wrong, since we only migrate tasks that is fair.

Commit f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing") uses cur without checking if the cur is in fair class or not. Fix this.

Fixes f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing")
---
 kernel/sched/fair.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/fair.c +3 -1
index 0feec172fd37..6347ae4cb419 100644
@@ -11016,7 +11016,9 @@ alb_break_llc(struct lb_env *env)
 			return true;
 
 		cur = rcu_dereference_all(env->src_rq->curr);
-		if (cur && cur->sched_class == &fair_sched_class)
+		if (cur && cur->sched_class != &fair_sched_class)
+			cur = NULL;
+		if (cur)
 			util = task_util(cur);
 
 		if (task_misfits_asym_cpu(env, cur) ||
Signature · 1 line
2.53.0
#1 lore raw
Quoted 25 lines · Kayra Cizmeci

Commit d6b9afab44e23 ("sched/cache: Fix
checking active load balance by only considering the CFS task")

Stopped using task_util() for non-fair tasks. Since the values of non-fair tasks can be stale.

__active_load_balance_cpu_stop() calls detach_one_task(), that only looks to cfs_tasks list. So if the rq->curr is not fair, doing a decision according to it is wrong, since we only migrate tasks that is fair.

Commit f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing") uses cur without checking if the cur is in fair class or not. Fix this.

Fixes f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing")
---
 kernel/sched/fair.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 0feec172fd37..6347ae4cb419 100644

kernel/sched/fair.c alb_break_llc(struct lb_env *env) · line 11019

Quoted 5 lines
kernel/sched/fair.c +1 -1
@@ -11016,7 +11016,9 @@ alb_break_llc(struct lb_env *env)
 			return true;
 
 		cur = rcu_dereference_all(env->src_rq->curr);
-		if (cur && cur->sched_class == &fair_sched_class)
+		if (cur && cur->sched_class != &fair_sched_class)

Thanks. util was already 0 for a non-fair curr, but cur was still passed to task_misfits_asym_cpu(), which would evaluate task_fits_cpu() on a non-CFS task. Since nr_pref_llc_running and h_nr_runnable only count CFS tasks, curr can be e.g. an RT task here with a CFS task queued behind it, and active balance would only ever detach a CFS task anyway. So the fix makes sense.

Suggest that you put a comment here:

                  /*
                   * Active balance only detaches CFS tasks, so a non-fair
                   * curr is never migrated. Ignore it and avoid using its
                   * stale util in the misfit and LLC checks.
                   */
                  if (cur && cur->sched_class != &fair_sched_class)
                          cur = NULL;
                  if (cur)
                          util = task_util(cur);

Could you update the changelog to say explicitly that the issue is the non-fair curr being fed to task_misfits_asym_cpu(), not util?

Tim

Quoted 5 lines
kernel/sched/fair.c +2 -0
+			cur = NULL;
+		if (cur)
 			util = task_util(cur);
 
 		if (task_misfits_asym_cpu(env, cur) ||
#2 lore raw
Quoted 7 lines · Tim Chen
Quoted 6 lines · Kayra Cizmeci

Commit d6b9afab44e23 ("sched/cache: Fix
checking active load balance by only considering the CFS task")

Stopped using task_util() for non-fair tasks. Since the values of non-fair tasks can be stale.

Quoted 7 lines
Quoted 7 lines

__active_load_balance_cpu_stop() calls detach_one_task(), that only looks to cfs_tasks list. So if the rq->curr is not fair, doing a decision according to it is wrong, since we only migrate tasks that is fair.

Commit f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing") uses cur without checking if the cur is in fair class or not. Fix this.

I suggest rephrasing the log a bit:

Commit d6b9afab44e23 ("sched/cache: Fix checking active load balance by only considering the CFS task") stopped using task_util() of a non-fair curr in alb_break_llc(), as the util of non-fair tasks can be stale.

However, commit f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing") still passes curr to task_misfits_asym_cpu() regardless of its class, which then calls task_fits_cpu() on it. A non-fair curr is never migrated by active balance, since detach_one_task() only picks tasks from cfs_tasks. Ignore a non-fair curr so it does not affect the decision.

Tim

Quoted 47 lines
Quoted 12 lines
Fixes f0d243a96f26 ("sched/fair: Avoid creating misfits during cache-aware balancing")
---
 kernel/sched/fair.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 0feec172fd37..6347ae4cb419 100644

kernel/sched/fair.c alb_break_llc(struct lb_env *env) · line 11019

Quoted 5 lines
kernel/sched/fair.c +1 -1
@@ -11016,7 +11016,9 @@ alb_break_llc(struct lb_env *env)
 			return true;
 
 		cur = rcu_dereference_all(env->src_rq->curr);
-		if (cur && cur->sched_class == &fair_sched_class)
+		if (cur && cur->sched_class != &fair_sched_class)

Thanks. util was already 0 for a non-fair curr, but cur was still passed to task_misfits_asym_cpu(), which would evaluate task_fits_cpu() on a non-CFS task. Since nr_pref_llc_running and h_nr_runnable only count CFS tasks, curr can be e.g. an RT task here with a CFS task queued behind it, and active balance would only ever detach a CFS task anyway. So the fix makes sense.

Suggest that you put a comment here:

                  /*
                   * Active balance only detaches CFS tasks, so a non-fair
                   * curr is never migrated. Ignore it and avoid using its
                   * stale util in the misfit and LLC checks.
                   */
                  if (cur && cur->sched_class != &fair_sched_class)
                          cur = NULL;
                  if (cur)
                          util = task_util(cur);

Could you update the changelog to say explicitly that the issue is the non-fair curr being fed to task_misfits_asym_cpu(), not util?

Tim

Quoted 5 lines
kernel/sched/fair.c +2 -0
+			cur = NULL;
+		if (cur)
 			util = task_util(cur);
 
 		if (task_misfits_asym_cpu(env, cur) ||