From 9247953114c84003b64c3a10dce683e5acadfe99 Mon Sep 17 00:00:00 2001 From: Cruz Zhao Date: Mon, 15 Apr 2024 15:52:37 +0800 Subject: [PATCH] anolis: sched/fair: optimize ID_LOAD_BALANCE to rescue underclass ANBZ: #8759 ID_LOAD_BALANCE tends to migrate highclass and normal tasks first to prevent cpu competition among them, which will result that underclass tasks lose the migration opportunity with a high probability, even when they are expelled. To optimize ID_LOAD_BALANCE, we will redo load balance if there is still imbalance, and in the second loop we will allow migrating underclass tasks. Fixes: b940b7619193("anolis: sched/fair: introduce sched_feat ID_LOAD_BALANCE") Signed-off-by: Cruz Zhao --- kernel/sched/fair.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c9bc0689f790..612348dcffb3 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9952,6 +9952,9 @@ struct lb_env { enum fbq_type fbq_type; enum migration_type migration_type; struct list_head tasks; +#ifdef CONFIG_GROUP_IDENTITY + bool id_need_redo; +#endif }; /* @@ -10244,10 +10247,12 @@ static int detach_tasks(struct lb_env *env) #ifdef CONFIG_GROUP_IDENTITY /* For migrate_identity, we wanna pull highclass or normal tasks. */ case migrate_identity: - if (id_regard_as_idle(env->src_rq)) - break; - if (is_underclass_task(p)) - goto next; + if (env->id_need_redo) { + if (id_regard_as_idle(env->src_rq)) + break; + if (is_underclass_task(p)) + goto next; + } /* If there is highclass or normal tasks, we pull tasks as migrate_load. */ fallthrough; #endif @@ -12165,6 +12170,7 @@ static int load_balance(int this_cpu, struct rq *this_rq, .tasks = LIST_HEAD_INIT(env.tasks), #ifdef CONFIG_GROUP_IDENTITY .migration_type = type, + .id_need_redo = true, #endif }; @@ -12307,6 +12313,13 @@ static int load_balance(int this_cpu, struct rq *this_rq, } } +#ifdef CONFIG_GROUP_IDENTITY + if (id_load_balance() && env.imbalance > 0 && env.id_need_redo) { + env.id_need_redo = false; + goto redo; + } +#endif + if (!ld_moved) { schedstat_inc(sd->lb_failed[idle]); /* -- Gitee