Skip to content

Commit e63da03

Browse files
Rik van RielIngo Molnar
authored andcommitted
sched/numa: Allow task switch if load imbalance improves
Currently the NUMA balancing code only allows moving tasks between NUMA nodes when the load on both nodes is in balance. This breaks down when the load was imbalanced to begin with. Allow tasks to be moved between NUMA nodes if the imbalance is small, or if the new imbalance is be smaller than the original one. Suggested-by: Peter Zijlstra <[email protected]> Signed-off-by: Rik van Riel <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Ingo Molnar <[email protected]> Link: http://lkml.kernel.org/r/[email protected]
1 parent 4027d08 commit e63da03

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

kernel/sched/fair.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,34 @@ static void task_numa_assign(struct task_numa_env *env,
10951095
env->best_cpu = env->dst_cpu;
10961096
}
10971097

1098+
static bool load_too_imbalanced(long orig_src_load, long orig_dst_load,
1099+
long src_load, long dst_load,
1100+
struct task_numa_env *env)
1101+
{
1102+
long imb, old_imb;
1103+
1104+
/* We care about the slope of the imbalance, not the direction. */
1105+
if (dst_load < src_load)
1106+
swap(dst_load, src_load);
1107+
1108+
/* Is the difference below the threshold? */
1109+
imb = dst_load * 100 - src_load * env->imbalance_pct;
1110+
if (imb <= 0)
1111+
return false;
1112+
1113+
/*
1114+
* The imbalance is above the allowed threshold.
1115+
* Compare it with the old imbalance.
1116+
*/
1117+
if (orig_dst_load < orig_src_load)
1118+
swap(orig_dst_load, orig_src_load);
1119+
1120+
old_imb = orig_dst_load * 100 - orig_src_load * env->imbalance_pct;
1121+
1122+
/* Would this change make things worse? */
1123+
return (old_imb > imb);
1124+
}
1125+
10981126
/*
10991127
* This checks if the overall compute and NUMA accesses of the system would
11001128
* be improved if the source tasks was migrated to the target dst_cpu taking
@@ -1107,7 +1135,8 @@ static void task_numa_compare(struct task_numa_env *env,
11071135
struct rq *src_rq = cpu_rq(env->src_cpu);
11081136
struct rq *dst_rq = cpu_rq(env->dst_cpu);
11091137
struct task_struct *cur;
1110-
long dst_load, src_load;
1138+
long orig_src_load, src_load;
1139+
long orig_dst_load, dst_load;
11111140
long load;
11121141
long imp = (groupimp > 0) ? groupimp : taskimp;
11131142

@@ -1181,25 +1210,22 @@ static void task_numa_compare(struct task_numa_env *env,
11811210
* In the overloaded case, try and keep the load balanced.
11821211
*/
11831212
balance:
1184-
dst_load = env->dst_stats.load;
1185-
src_load = env->src_stats.load;
1213+
orig_dst_load = env->dst_stats.load;
1214+
orig_src_load = env->src_stats.load;
11861215

11871216
/* XXX missing power terms */
11881217
load = task_h_load(env->p);
1189-
dst_load += load;
1190-
src_load -= load;
1218+
dst_load = orig_dst_load + load;
1219+
src_load = orig_src_load - load;
11911220

11921221
if (cur) {
11931222
load = task_h_load(cur);
11941223
dst_load -= load;
11951224
src_load += load;
11961225
}
11971226

1198-
/* make src_load the smaller */
1199-
if (dst_load < src_load)
1200-
swap(dst_load, src_load);
1201-
1202-
if (src_load * env->imbalance_pct < dst_load * 100)
1227+
if (load_too_imbalanced(orig_src_load, orig_dst_load,
1228+
src_load, dst_load, env))
12031229
goto unlock;
12041230

12051231
assign:

0 commit comments

Comments
 (0)