Re: [PATCH v3 1/2] sched/fair: Don't trigger active lb if src_rq->curr is CFS and not on_rq

From: Xin Zhao

Date: Mon Jun 15 2026 - 10:10:31 EST


On Mon, 15 Jun 2026 15:39:22 +0200 Valentin Schneider <vschneid@xxxxxxxxxx> wrote:

> > @@ -13436,7 +13436,9 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
> > * ->active_balance_work. Once set, it's cleared
> > * only after active load balance is finished.
> > */
> > - if (!busiest->active_balance) {
> > + if (!busiest->active_balance &&
> > + !(busiest->curr->sched_class == &fair_sched_class &&
> > + !busiest->curr->on_rq)) {
>
> This should be commented; I restructured this a little, it's one more label
> but it reads better to me, what do you think?

:) Thank you for your changes; it looks much better now, and the necessary
comments have been added.

> ---
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index d78467ec6ee13..a0ac31a3be988 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -13482,12 +13482,22 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
> * ->active_balance_work. Once set, it's cleared
> * only after active load balance is finished.
> */
> - if (!busiest->active_balance) {
> - busiest->active_balance = 1;
> - busiest->push_cpu = this_cpu;
> - active_balance = 1;
> - }
> + if (busiest->active_balance)
> + goto no_active_balance;
>
> + /*
> + * @busiest dropped its rq_lock in the middle of
> + * scheduling out its ->curr task (->on_rq := 0), no
> + * need to forcefully punt it away with active balance.
> + */
> + if ((busiest->curr->sched_class == &fair_sched_class) &&
> + !busiest->curr->on_rq)
> + goto no_active_balance;
> +
> + busiest->active_balance = 1;
> + busiest->push_cpu = this_cpu;
> + active_balance = 1;
> +no_active_balance:
> preempt_disable();
> raw_spin_rq_unlock_irqrestore(busiest, flags);
> if (active_balance) {

Thanks
Xin Zhao