[PATCH 09/10] sched/fair: Not goto more_balance if newly idle and has pending task when LBF_NEED_BREAK
From: Xin Zhao
Date: Sat Aug 15 2026 - 07:05:25 EST
When LBF_NEED_BREAK flag is set in env.flags, no longer unconditionally go
to more_balance. Instead, we exclude the case when it is newly idle and
there are pending tasks. This helps avoid unnecessary CPU wastage caused
by repeatedly going to more_balance when the task load is too high during
sched_balance_rq().
In another 'goto more_balance' case when LBF_DST_PINNED flag is set in
env.flags, we do not need to add the check. Because LBF_DST_PINNED flag is
only set within can_migrate_task(). Before setting LBF_DST_PINNED flag in
can_migrate_task(), there is a check to see if it is newly idle.
can_migrate_task() will exit without setting the LBF_DST_PINNED flag if it
is newly idle.
Signed-off-by: Xin Zhao <jackzxcui1989@xxxxxxx>
---
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 8a1d2763a923..1ae351ea5949 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -13561,7 +13561,9 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
if (env.flags & LBF_NEED_BREAK) {
env.flags &= ~LBF_NEED_BREAK;
- goto more_balance;
+ if (!(env.idle == CPU_NEWLY_IDLE &&
+ (env.dst_rq->nr_running > 0 || env.dst_rq->ttwu_pending)))
+ goto more_balance;
}
/*
--
2.34.1