* [PATCH 0/2] Fix imbalance issue when balancing fork
@ 2025-07-01 2:45 Adam Li
2025-07-01 2:45 ` [PATCH 1/2] sched/fair: Only update stats for allowed CPUs when looking for dst group Adam Li
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Adam Li @ 2025-07-01 2:45 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid, cl,
linux-kernel, patches, Adam Li
Load imbalance is observed when the workload frequently forks new threads.
Due to CPU affinity, the workload can run on CPU 0-7 in the first
group, and only on CPU 8-11 in the second group. CPU 12-15 are always idle.
{ 0 1 2 3 4 5 6 7 } {8 9 10 11 12 13 14 15}
* * * * * * * * * * * *
When looking for dst group for newly forked threads, in many times
update_sg_wakeup_stats() reports the second group has more idle CPUs
than the first group. The scheduler thinks the second group is less
busy. Then it selects least busy CPUs among CPU 8-11. So CPU 8-11 can be
crowded with newly forked threads, at the same time CPU 0-7 can be idle.
The first patch 'Only update stats of allowed CPUs when looking for dst
group' *alone* can fix this imbalance issue.
And I think the second patch also makes sense in this scenario. If group
weight includes CPUs a task cannot use, group classification can be
incorrect. Please comment.
Adam Li (2):
sched/fair: Only update stats of allowed CPUs when looking for dst
group
sched/fair: Only count group weight for allowed CPUs when looking for
dst group
kernel/sched/fair.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] sched/fair: Only update stats for allowed CPUs when looking for dst group
2025-07-01 2:45 [PATCH 0/2] Fix imbalance issue when balancing fork Adam Li
@ 2025-07-01 2:45 ` Adam Li
2025-07-01 2:45 ` [PATCH 2/2] sched/fair: Only count group weight " Adam Li
2025-07-04 9:17 ` [PATCH 0/2] Fix imbalance issue when balancing fork Peter Zijlstra
2 siblings, 0 replies; 5+ messages in thread
From: Adam Li @ 2025-07-01 2:45 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid, cl,
linux-kernel, patches, Adam Li
A task may not use all the CPUs in a schedule group due to CPU affinity.
Only update schedule group statistics for allowed CPUs.
Signed-off-by: Adam Li <adamli@os.amperecomputing.com>
---
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7a14da5396fb..78a3d9b78e07 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10693,7 +10693,7 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd,
if (sd->flags & SD_ASYM_CPUCAPACITY)
sgs->group_misfit_task_load = 1;
- for_each_cpu(i, sched_group_span(group)) {
+ for_each_cpu_and(i, sched_group_span(group), p->cpus_ptr) {
struct rq *rq = cpu_rq(i);
unsigned int local;
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] sched/fair: Only count group weight for allowed CPUs when looking for dst group
2025-07-01 2:45 [PATCH 0/2] Fix imbalance issue when balancing fork Adam Li
2025-07-01 2:45 ` [PATCH 1/2] sched/fair: Only update stats for allowed CPUs when looking for dst group Adam Li
@ 2025-07-01 2:45 ` Adam Li
2025-07-04 9:17 ` [PATCH 0/2] Fix imbalance issue when balancing fork Peter Zijlstra
2 siblings, 0 replies; 5+ messages in thread
From: Adam Li @ 2025-07-01 2:45 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid, cl,
linux-kernel, patches, Adam Li
A task may not use all the CPUs in a schedule group due to CPU affinity.
If group weight includes CPUs not allowed to run the task,
group classification may be incorrect.
Signed-off-by: Adam Li <adamli@os.amperecomputing.com>
---
kernel/sched/fair.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 78a3d9b78e07..452e2df961b9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10722,7 +10722,9 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd,
sgs->group_capacity = group->sgc->capacity;
- sgs->group_weight = group->group_weight;
+ /* Only count group_weight if p can run on these cpus */
+ sgs->group_weight = cpumask_weight_and(sched_group_span(group),
+ p->cpus_ptr);
sgs->group_type = group_classify(sd->imbalance_pct, group, sgs);
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Fix imbalance issue when balancing fork
2025-07-01 2:45 [PATCH 0/2] Fix imbalance issue when balancing fork Adam Li
2025-07-01 2:45 ` [PATCH 1/2] sched/fair: Only update stats for allowed CPUs when looking for dst group Adam Li
2025-07-01 2:45 ` [PATCH 2/2] sched/fair: Only count group weight " Adam Li
@ 2025-07-04 9:17 ` Peter Zijlstra
2025-07-08 13:27 ` Adam Li
2 siblings, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2025-07-04 9:17 UTC (permalink / raw)
To: Adam Li
Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
bsegall, mgorman, vschneid, cl, linux-kernel, patches
On Tue, Jul 01, 2025 at 02:45:47AM +0000, Adam Li wrote:
> Load imbalance is observed when the workload frequently forks new threads.
> Due to CPU affinity, the workload can run on CPU 0-7 in the first
> group, and only on CPU 8-11 in the second group. CPU 12-15 are always idle.
>
> { 0 1 2 3 4 5 6 7 } {8 9 10 11 12 13 14 15}
> * * * * * * * * * * * *
>
> When looking for dst group for newly forked threads, in many times
> update_sg_wakeup_stats() reports the second group has more idle CPUs
> than the first group. The scheduler thinks the second group is less
> busy. Then it selects least busy CPUs among CPU 8-11. So CPU 8-11 can be
> crowded with newly forked threads, at the same time CPU 0-7 can be idle.
>
> The first patch 'Only update stats of allowed CPUs when looking for dst
> group' *alone* can fix this imbalance issue.
>
> And I think the second patch also makes sense in this scenario. If group
> weight includes CPUs a task cannot use, group classification can be
> incorrect. Please comment.
>
> Adam Li (2):
> sched/fair: Only update stats of allowed CPUs when looking for dst
> group
> sched/fair: Only count group weight for allowed CPUs when looking for
> dst group
>
> kernel/sched/fair.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
Hurm... so the thing I noticed is that update_sg_wakeup_stats() and
update_sg_lb_stats() are *very* similar.
Specifically, the first patch does something to wakeup_stats that
lb_stats already does. While the second patch seems to do something that
might also apply to lb_stats.
Is there no way we can unify this?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Fix imbalance issue when balancing fork
2025-07-04 9:17 ` [PATCH 0/2] Fix imbalance issue when balancing fork Peter Zijlstra
@ 2025-07-08 13:27 ` Adam Li
0 siblings, 0 replies; 5+ messages in thread
From: Adam Li @ 2025-07-08 13:27 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
bsegall, mgorman, vschneid, cl, linux-kernel, patches
On 7/4/2025 5:17 PM, Peter Zijlstra wrote:
> On Tue, Jul 01, 2025 at 02:45:47AM +0000, Adam Li wrote:
>> Load imbalance is observed when the workload frequently forks new threads.
>> Due to CPU affinity, the workload can run on CPU 0-7 in the first
>> group, and only on CPU 8-11 in the second group. CPU 12-15 are always idle.
>>
>> { 0 1 2 3 4 5 6 7 } {8 9 10 11 12 13 14 15}
>> * * * * * * * * * * * *
>>
>> When looking for dst group for newly forked threads, in many times
>> update_sg_wakeup_stats() reports the second group has more idle CPUs
>> than the first group. The scheduler thinks the second group is less
>> busy. Then it selects least busy CPUs among CPU 8-11. So CPU 8-11 can be
>> crowded with newly forked threads, at the same time CPU 0-7 can be idle.
>>
>> The first patch 'Only update stats of allowed CPUs when looking for dst
>> group' *alone* can fix this imbalance issue.
>>
>> And I think the second patch also makes sense in this scenario. If group
>> weight includes CPUs a task cannot use, group classification can be
>> incorrect. Please comment.
>>
>> Adam Li (2):
>> sched/fair: Only update stats of allowed CPUs when looking for dst
>> group
>> sched/fair: Only count group weight for allowed CPUs when looking for
>> dst group
>>
>> kernel/sched/fair.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
Hi Peter,
>
> Hurm... so the thing I noticed is that update_sg_wakeup_stats() and
> update_sg_lb_stats() are *very* similar.
>
> Specifically, the first patch does something to wakeup_stats that
> lb_stats already does. While the second patch seems to do something that
> might also apply to lb_stats.
>
Thanks for the idea. I am testing this.
> Is there no way we can unify this?
I will try to unify the common logic in update_sg_wakeup_stats() and
update_sg_lb_stats() into a single function. It seems not easy :).
Thanks,
-adam
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-08 13:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-01 2:45 [PATCH 0/2] Fix imbalance issue when balancing fork Adam Li
2025-07-01 2:45 ` [PATCH 1/2] sched/fair: Only update stats for allowed CPUs when looking for dst group Adam Li
2025-07-01 2:45 ` [PATCH 2/2] sched/fair: Only count group weight " Adam Li
2025-07-04 9:17 ` [PATCH 0/2] Fix imbalance issue when balancing fork Peter Zijlstra
2025-07-08 13:27 ` Adam Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®