sched/fair: Introduce priority load balance for CFS
PATCH v5 1/1 sched/fair: Introduce priority load balance for CFS
For co-location with idle and non-idle tasks, when CFS do load balance, it is reasonable to prefer migrating non-idle tasks and migrating idle tasks lastly to improve QoS of non-idle(Latency Sensitive) tasks.
Consider a simple scenario. Assume that CPU0 has two non-idle tasks whose weight is 2*1024=2048, also CPU0 has 3000 idle tasks whose weight is 3000*3 = 9000. Now CPU1 is idle and IDLE load balance is triggered. CPU1 needs to pull a certain number of tasks from CPU0.
If we do not considerate task priorities and interference between tasks, more than 1800 idle tasks on CPU0 maybe migrated to CPU1. As a result, two non-idle tasks still compete on CPU0. However CPU1 is running with a lot of idle but not non-idle tasks.
On the other hand, if we consider the interference between different task priorities, first migrate one non-idle to CPU1, the non-idle task may execute quickly on CPU1, then CPU1 is got to idle and pulls more idle tasks from CPU0, so that the non-idle task on CPU 0 can also be completed more quickly.
Although this change will cause some idle tasks imbalance between different CPUs, but the latency of non-idle tasks can be significantly reduced.
---v4->v5:
- Deleted meaningless load/utility imbalance judgment.
- Add restrictions on idle task migration.
v3->v4:
- Remove can_migrate_cfs_tasks().
- Fix calculate migration {load|util|task} imbalance for env->src_rq and env->dst_rq for non-idle cfs tasks.
v2->v3:
- Fix can_migrate_cfs_tasks() for detach_one_task.
v1->v2:
- Remove sysctl knob and add LB_PRIO sched feature.
- Migrating tasks consider non-idle migrate_{load|util|task} difference between env->src_rq and env->dst_rq, and if the difference smaller than env->imbalance, change to migrate idle tasks instead.
--- kernel/sched/core.c | 1 + kernel/sched/fair.c | 76 ++++++++++++++++++++++++++++++++++++++--- kernel/sched/features.h | 1 + kernel/sched/sched.h | 1 + 4 files changed, 75 insertions(+), 4 deletions(-)
kernel/sched/core.c +1 -0
@@ -9731,6 +9731,7 @@ void __init sched_init(void) rq->max_idle_balance_cost = sysctl_sched_migration_cost;INIT_LIST_HEAD (&rq->cfs_tasks); +INIT_LIST_HEAD (&rq->cfs_idle_tasks);rq_attach_root (rq, &def_root_domain);#ifdef CONFIG_NO_HZ_COMMON
kernel/sched/fair.c +72 -4
146 lines not on this page · raw message
kernel/sched/features.h +1 -0
@@ -85,6 +85,7 @@ SCHED_FEAT(RT_PUSH_IPI, true) SCHED_FEAT(RT_RUNTIME_SHARE, false) SCHED_FEAT(LB_MIN, false) +SCHED_FEAT(LB_PRIO, false) SCHED_FEAT(ATTACH_AGE_LOAD, true)SCHED_FEAT (WA_IDLE , true)
kernel/sched/sched.h +1 -0
@@ -1053,6 +1053,7 @@ struct rq {int online;struct list_head cfs_tasks; +struct list_head cfs_idle_tasks;struct sched_avg avg_rt;struct sched_avg avg_dl;
Signature · 1 line
2.33.0