Re: [PATCH v3 1/2] sched/fair: Don't trigger active lb if src_rq->curr is CFS and not on_rq
From: Aiqun(Maria) Yu
Date: Mon Jun 15 2026 - 23:07:04 EST
On 6/15/2026 10:09 PM, Xin Zhao wrote:
> 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.
This format looks better.
>
>> ---
>> 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)
Still have the doubt why need to do active load balance when the current
is not CFS. And busiest->curr->on_rq==0 case only.
Is it should be like:
if ((busiest->curr->sched_class == &fair_sched_class) ||
unlikely(!task_on_rq_queued(busiest->curr)));
if busiest->curr->on_rq==2 (TASK_ON_RQ_MIGRATING), it is no need to do
active_balance as well.
>> + 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
>
--
Thx and BRs,
Aiqun(Maria) Yu