sched/fair: Introduce priority load balance to reduce interference from IDLE tasks
PATCH v3 1/1 sched/fair: Introduce priority load balance to reduce interference from IDLE tasks
For co-location with NORMAL and IDLE tasks, when CFS trigger load balance, it is reasonable to prefer migrating NORMAL(Latency Sensitive) tasks from the busy src CPU to dst CPU, and migrating IDLE tasks lastly.
Consider the situation that CPU A has several normal tasks and hundreds of idle tasks while CPU B is idle, and CPU B needs to pull some tasks from CPU A, but the cfs_tasks in CPU A are not in order of priority, and the max number of pulling tasks depends on env->loop_max, which value is sysctl_sched_nr_migrate, i.e. 32. We now cannot guarantee that CPU B can pull a certain number of normal tasks instead of idle tasks from the waiting queue of CPU A. So it is necessary to divide cfs_tasks into two different lists and ensure that tasks in none-idle list can be migrated firstly.
This is very important for reducing interference from IDLE tasks. So the CFS load balance can be optimized to below:
1.cfs_tasks list of CPU rq is owned by NORMAL tasks. 2.cfs_idle_tasks list of CPU rq which is owned by IDLE tasks. 3.Prefer to migrate NORMAL tasks of cfs_tasks to dst CPU. 4.Lastly migrate IDLE tasks of cfs_idle_tasks to dst CPU.
This was tested with the following reproduction:
- small number of NORMAL tasks colocated with a large number of IDLE tasks
With this patch, NORMAL tasks latency can be reduced about 5~10% compared with current.
---V2->V3:
- rename variable loop(int) to has_detach_cfs_idle(bool) and make it more readable
- add more description for priority load balance
--- kernel/sched/core.c | 1 + kernel/sched/fair.c | 47 ++++++++++++++++++++++++++++++++++++++++---- kernel/sched/sched.h | 1 + 3 files changed, 45 insertions(+), 4 deletions(-)
kernel/sched/core.c +1 -0
@@ -9733,6 +9733,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 +43 -4
117 lines not on this page · raw message
kernel/sched/sched.h +1 -0
@@ -1068,6 +1068,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.27.0