Skip to content

Commit 873199d

Browse files
Hao JiaPeter Zijlstra
authored andcommitted
sched/core: Prioritize migrating eligible tasks in sched_balance_rq()
When the PLACE_LAG scheduling feature is enabled and dst_cfs_rq->nr_queued is greater than 1, if a task is ineligible (lag < 0) on the source cpu runqueue, it will also be ineligible when it is migrated to the destination cpu runqueue. Because we will keep the original equivalent lag of the task in place_entity(). So if the task was ineligible before, it will still be ineligible after migration. So in sched_balance_rq(), we prioritize migrating eligible tasks, and we soft-limit ineligible tasks, allowing them to migrate only when nr_balance_failed is non-zero to avoid load-balancing trying very hard to balance the load. Below are some benchmark test results. From my test results, this patch shows a slight improvement on hackbench. Benchmark ========= All of the benchmarks are done inside a normal cpu cgroup in a clean environment with cpu turbo disabled, and test machine is: Single NUMA machine model is 13th Gen Intel(R) Core(TM) i7-13700, 12 Core/24 HT. Based on master b86545e. Results ======= hackbench-process-pipes vanilla patched Amean 1 0.5837 ( 0.00%) 0.5733 ( 1.77%) Amean 4 1.4423 ( 0.00%) 1.4503 ( -0.55%) Amean 7 2.5147 ( 0.00%) 2.4773 ( 1.48%) Amean 12 3.9347 ( 0.00%) 3.8880 ( 1.19%) Amean 21 5.3943 ( 0.00%) 5.3873 ( 0.13%) Amean 30 6.7840 ( 0.00%) 6.6660 ( 1.74%) Amean 48 9.8313 ( 0.00%) 9.6100 ( 2.25%) Amean 79 15.4403 ( 0.00%) 14.9580 ( 3.12%) Amean 96 18.4970 ( 0.00%) 17.9533 ( 2.94%) hackbench-process-sockets vanilla patched Amean 1 0.6297 ( 0.00%) 0.6223 ( 1.16%) Amean 4 2.1517 ( 0.00%) 2.0887 ( 2.93%) Amean 7 3.6377 ( 0.00%) 3.5670 ( 1.94%) Amean 12 6.1277 ( 0.00%) 5.9290 ( 3.24%) Amean 21 10.0380 ( 0.00%) 9.7623 ( 2.75%) Amean 30 14.1517 ( 0.00%) 13.7513 ( 2.83%) Amean 48 24.7253 ( 0.00%) 24.2287 ( 2.01%) Amean 79 43.9523 ( 0.00%) 43.2330 ( 1.64%) Amean 96 54.5310 ( 0.00%) 53.7650 ( 1.40%) tbench4 Throughput vanilla patched Hmean 1 255.97 ( 0.00%) 275.01 ( 7.44%) Hmean 2 511.60 ( 0.00%) 544.27 ( 6.39%) Hmean 4 996.70 ( 0.00%) 1006.57 ( 0.99%) Hmean 8 1646.46 ( 0.00%) 1649.15 ( 0.16%) Hmean 16 2259.42 ( 0.00%) 2274.35 ( 0.66%) Hmean 32 4725.48 ( 0.00%) 4735.57 ( 0.21%) Hmean 64 4411.47 ( 0.00%) 4400.05 ( -0.26%) Hmean 96 4284.31 ( 0.00%) 4267.39 ( -0.39%) Suggested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Hao Jia <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 8061b9f commit 873199d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

kernel/sched/fair.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9406,6 +9406,30 @@ static inline long migrate_degrades_locality(struct task_struct *p,
94069406
}
94079407
#endif
94089408

9409+
/*
9410+
* Check whether the task is ineligible on the destination cpu
9411+
*
9412+
* When the PLACE_LAG scheduling feature is enabled and
9413+
* dst_cfs_rq->nr_queued is greater than 1, if the task
9414+
* is ineligible, it will also be ineligible when
9415+
* it is migrated to the destination cpu.
9416+
*/
9417+
static inline int task_is_ineligible_on_dst_cpu(struct task_struct *p, int dest_cpu)
9418+
{
9419+
struct cfs_rq *dst_cfs_rq;
9420+
9421+
#ifdef CONFIG_FAIR_GROUP_SCHED
9422+
dst_cfs_rq = task_group(p)->cfs_rq[dest_cpu];
9423+
#else
9424+
dst_cfs_rq = &cpu_rq(dest_cpu)->cfs;
9425+
#endif
9426+
if (sched_feat(PLACE_LAG) && dst_cfs_rq->nr_queued &&
9427+
!entity_eligible(task_cfs_rq(p), &p->se))
9428+
return 1;
9429+
9430+
return 0;
9431+
}
9432+
94099433
/*
94109434
* can_migrate_task - may task p from runqueue rq be migrated to this_cpu?
94119435
*/
@@ -9432,6 +9456,16 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
94329456
if (throttled_lb_pair(task_group(p), env->src_cpu, env->dst_cpu))
94339457
return 0;
94349458

9459+
/*
9460+
* We want to prioritize the migration of eligible tasks.
9461+
* For ineligible tasks we soft-limit them and only allow
9462+
* them to migrate when nr_balance_failed is non-zero to
9463+
* avoid load-balancing trying very hard to balance the load.
9464+
*/
9465+
if (!env->sd->nr_balance_failed &&
9466+
task_is_ineligible_on_dst_cpu(p, env->dst_cpu))
9467+
return 0;
9468+
94359469
/* Disregard percpu kthreads; they are where they need to be. */
94369470
if (kthread_is_per_cpu(p))
94379471
return 0;

0 commit comments

Comments
 (0)