sched/fair: Return the busiest group only if imbalance is meaningful
PATCH 1/1 sched/fair: Return the busiest group only if imbalance is meaningful
When calculate_imbalance function calculate the imbalance, it may actually get a negative number. In this case, it is meaningless to return the so-called busiest group and continue to search for the busiest cpu later. Therefore, only when the imbalance is greater than 0 should return the busiest group, otherwise return NULL.
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -9639,7 +9639,7 @@ static struct sched_group *find_busiest_group(struct lb_env *env) force_balance:/* Looks like there is an imbalance. Compute it */ calculate_imbalance (env, &sds); -return env->imbalance ? sds.busiest :NULL ; +return env->imbalance >0 ? sds.busiest :NULL ; out_balanced: env->imbalance =0 ;
Signature · 1 line
2.9.5
Vincent Guittot
maintainerQuoted 3 lines · zgpeng
When
calculate_imbalancefunction calculate the imbalance, it may actually get a negative number. In this case, it is meaningless to
We should not return a negative imbalance but I suppose this can happen when we are using the avg_load metrics to calculate imbalance. Have you faced a use case where imbalance is negative ?
Quoted 26 lines
return the so-called busiest group and continue to search for the busiest cpu later. Therefore, only when the imbalance is greater than 0 should return the busiest group, otherwise return NULL.
Signed-off-by zgpeng <[email protected]>Reviewed-by Samuel Liao <[email protected]>--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/fair.c +1
-2@@ -9639,7 +9639,7 @@ static struct sched_group *find_busiest_group(struct lb_env *env) force_balance:/* Looks like there is an imbalance. Compute it */ calculate_imbalance (env, &sds); -return env->imbalance ? sds.busiest :NULL ; +return env->imbalance >0 ? sds.busiest :NULL ; out_balanced: env->imbalance =0 ; --2.9.5
A message that is not in the archive (sent off-list or not yet received): CAE5vP3=ZPGV=PuYb-WJsoQ8tX4yDAjajT_WRU+7gAiW54XgX_g@mail.gmail.com
Vincent Guittot
maintainerQuoted 25 lines · 彭志刚
YES. The following are specific scenarios where negative values occur:
The scheduler domain contains four groups, namely groupA, groupB, groupC, and groupD;
The types and
avg_loadconditions of the four groups are as followsGroupA TYPE=
group_fully_busyavg_load=10 [local group]GroupB TYPE=
group_has_spareavg_load=1GroupC TYPE=
group_has_spareavg_load=1GroupD TYPE=
group_overloadedavg_load=20 [busiest group]The CPU that calls
load_balanceis located in groupA, andupdate_sd_lb_statswill select the busiest group in GroupB, groupC, and
Quoted 7 lines
groupD, that is, gorupD. Under this condition, other judgments in the
find_busiest_groupfunction will be bypassed and the
calculate_imbalancefunction will be called. The judgment in the middle of thecalculate_imbalancefunction cannot stop thissituation, and it will go to the imbalance calculate logic at the end of the function.At this time, the domain's avg_load=8, but
the local_groupthe's avg_load=10; The negative value is therefore generated.
I think that this case should be covered by an additional test in calculate_imbalance because we should not try to pull load in groupA if it's already above the average load. Something like below should cover this
kernel/sched/fair.c +0 -0
@@ -9469,6 +9469,16 @@ static inline void calculate_imbalance(struct
lb_env *env, struct sd_lb_stats *s
sds->avg_load = (sds->total_load * SCHED_CAPACITY_SCALE) /
sds->total_capacity;
+
+ /*
+ * Don't pull any tasks if this group is already above the
+ * domain average load.
+ */+ if (local->avg_load >= sds->avg_load) {
+ env->imbalance = 0;
+ return;
+ }
+
/*
* If the local group is more loaded than the selected
* busiest group don't try to pull any tasks.
Quoted 39 lines
Quoted 36 lines · Vincent Guittot <[email protected]> 于2022年4月6日周三 20:59写道:
Quoted 3 lines · zgpeng
When
calculate_imbalancefunction calculate the imbalance, it may actually get a negative number. In this case, it is meaningless toWe should not return a negative imbalance but I suppose this can happen when we are using the
avg_loadmetrics to calculate imbalance. Have you faced a use case where imbalance is negative ?Quoted 26 lines
return the so-called busiest group and continue to search for the busiest cpu later. Therefore, only when the imbalance is greater than 0 should return the busiest group, otherwise return NULL.
Signed-off-by zgpeng <[email protected]>Reviewed-by Samuel Liao <[email protected]>--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/fair.c +1
-2@@ -9639,7 +9639,7 @@ static struct sched_group *find_busiest_group(struct lb_env *env) force_balance:/* Looks like there is an imbalance. Compute it */ calculate_imbalance (env, &sds); -return env->imbalance ? sds.busiest :NULL ; +return env->imbalance >0 ? sds.busiest :NULL ; out_balanced: env->imbalance =0 ; --2.9.5
Dietmar Eggemann
reviewerQuoted 1 line · Vincent Guittot
On Wed, 6 Apr 2022 at 17:07, 彭志刚 <[email protected]> wrote:
[...]
Quoted 12 lines
I think that this case should be covered by an additional test in
calculate_imbalancebecause we should not try to pull load in groupA if it's already above the average load. Something like below should cover thiskernel/sched/fair.c +0
-0@@ -9469,6 +9469,16 @@ static inline void calculate_imbalance(struct
lb_env*env, structsd_lb_stats*ssds->avg_load = (sds->total_load * SCHED_CAPACITY_SCALE) / sds->total_capacity;
kernel/sched/fair.c
Quoted 10 lines
kernel/sched/fair.c +10
-0+ +/* +* Don't pull any tasks if this group is already above the +* domain average load. +*/ +if (local->avg_load >= sds->avg_load) { + env->imbalance =0 ; +return ; + } +
LGTM. Like for the local->group_type == group_overloaded case in find_busiest_group() where we force goto out_balanced.
[...]