Skip to content

Commit 23fb06d

Browse files
Valentin SchneiderPeter Zijlstra
authored andcommitted
sched/fair: Clean up active balance nr_balance_failed trickery
When triggering an active load balance, sd->nr_balance_failed is set to such a value that any further can_migrate_task() using said sd will ignore the output of task_hot(). This behaviour makes sense, as active load balance intentionally preempts a rq's running task to migrate it right away, but this asynchronous write is a bit shoddy, as the stopper thread might run active_load_balance_cpu_stop before the sd->nr_balance_failed write either becomes visible to the stopper's CPU or even happens on the CPU that appended the stopper work. Add a struct lb_env flag to denote active balancing, and use it in can_migrate_task(). Remove the sd->nr_balance_failed write that served the same purpose. Cleanup the LBF_DST_PINNED active balance special case. Signed-off-by: Valentin Schneider <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Dietmar Eggemann <[email protected]> Reviewed-by: Vincent Guittot <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9bcb959 commit 23fb06d

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

kernel/sched/fair.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7453,6 +7453,7 @@ enum migration_type {
74537453
#define LBF_NEED_BREAK 0x02
74547454
#define LBF_DST_PINNED 0x04
74557455
#define LBF_SOME_PINNED 0x08
7456+
#define LBF_ACTIVE_LB 0x10
74567457

74577458
struct lb_env {
74587459
struct sched_domain *sd;
@@ -7614,10 +7615,13 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
76147615
* our sched_group. We may want to revisit it if we couldn't
76157616
* meet load balance goals by pulling other tasks on src_cpu.
76167617
*
7617-
* Avoid computing new_dst_cpu for NEWLY_IDLE or if we have
7618-
* already computed one in current iteration.
7618+
* Avoid computing new_dst_cpu
7619+
* - for NEWLY_IDLE
7620+
* - if we have already computed one in current iteration
7621+
* - if it's an active balance
76197622
*/
7620-
if (env->idle == CPU_NEWLY_IDLE || (env->flags & LBF_DST_PINNED))
7623+
if (env->idle == CPU_NEWLY_IDLE ||
7624+
env->flags & (LBF_DST_PINNED | LBF_ACTIVE_LB))
76217625
return 0;
76227626

76237627
/* Prevent to re-select dst_cpu via env's CPUs: */
@@ -7642,10 +7646,14 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
76427646

76437647
/*
76447648
* Aggressive migration if:
7645-
* 1) destination numa is preferred
7646-
* 2) task is cache cold, or
7647-
* 3) too many balance attempts have failed.
7649+
* 1) active balance
7650+
* 2) destination numa is preferred
7651+
* 3) task is cache cold, or
7652+
* 4) too many balance attempts have failed.
76487653
*/
7654+
if (env->flags & LBF_ACTIVE_LB)
7655+
return 1;
7656+
76497657
tsk_cache_hot = migrate_degrades_locality(p, env);
76507658
if (tsk_cache_hot == -1)
76517659
tsk_cache_hot = task_hot(p, env);
@@ -9836,9 +9844,6 @@ static int load_balance(int this_cpu, struct rq *this_rq,
98369844
active_load_balance_cpu_stop, busiest,
98379845
&busiest->active_balance_work);
98389846
}
9839-
9840-
/* We've kicked active balancing, force task migration. */
9841-
sd->nr_balance_failed = sd->cache_nice_tries+1;
98429847
}
98439848
} else {
98449849
sd->nr_balance_failed = 0;
@@ -9988,13 +9993,7 @@ static int active_load_balance_cpu_stop(void *data)
99889993
.src_cpu = busiest_rq->cpu,
99899994
.src_rq = busiest_rq,
99909995
.idle = CPU_IDLE,
9991-
/*
9992-
* can_migrate_task() doesn't need to compute new_dst_cpu
9993-
* for active balancing. Since we have CPU_IDLE, but no
9994-
* @dst_grpmask we need to make that test go away with lying
9995-
* about DST_PINNED.
9996-
*/
9997-
.flags = LBF_DST_PINNED,
9996+
.flags = LBF_ACTIVE_LB,
99989997
};
99999998

100009999
schedstat_inc(sd->alb_count);

0 commit comments

Comments
 (0)