Re: [PATCH v3 08/20] sched/fair: load balance only among preferred CPUs
From: K Prateek Nayak
Date: Thu Jun 04 2026 - 02:10:03 EST
Hello Shrikanth,
On 6/4/2026 11:15 AM, Shrikanth Hegde wrote:
> Hi Prateek.
> Thanks for reviewing the patchset and tags.
>
> On 6/4/26 10:50 AM, K Prateek Nayak wrote:
>> Hello Shrikanth,
>>
>> On 5/14/2026 8:51 PM, Shrikanth Hegde wrote:
>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>>> index a704285ac55a..0a851d4b0d7e 100644
>>> --- a/kernel/sched/fair.c
>>> +++ b/kernel/sched/fair.c
>>> @@ -12087,6 +12087,9 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
>>> cpumask_and(cpus, sched_domain_span(sd), cpu_active_mask);
>>> + /* Spread load among preferred CPUs */
>>> + cpumask_and(cpus, cpus, cpu_preferred_mask);
>>
>> nit.
>>
>> Instead of the onine_mask, can we keep the cpu_preferred_mask closer in sync
>> with the active_mask?
>
> I tried to make it active_mask. When there is high steal time,
> a CPU marked as not-active isn't available for workload which pins
> them. That would break user affinities.
Ack! Sorry for the confusion. More details below ...
>
>>
>> That way, if we can ensure that a preferred CPU is always a subset of the
>> active_mask, we can save on a couple of cpumask_and() operations by just
>> looking at preferred_mask instead of both the active_mask and the
>> preferred_mask.
>>
>
> active mask used heavily today. I didn't want to merge the two.
I didn't suggest merging the two - simply clearing the CPU as preferred
before it is transitioned out of the active mask ...
>
>> Are there any complications in that approach to track it via
>> sched_cpu_activate() / sched_cpu_deactivate()?
>
> Sorry i didn;t get this part. You mean track preferred mask with it?
... just moving set_cpu_preferred() into sched_cpu_activate() and
sched_cpu_deactivate() instead of doing it at set_cpu_online().
>
> We end up calling sched domain rebuild too if we go via sched_cpu_activate
> build_sched_domains+8
> partition_sched_domains_locked+1316
> partition_sched_domains+80
> rebuild_sched_domains_locked+332
> cpuset_handle_hotplug+1456
> sched_cpu_deactivate+608
> cpuhp_invoke_callback+504
> cpuhp_thread_fun+324
> smpboot_thread_fn+556
>
>
>>
>
> What is active_mask guaranteed to provide today? Are there any ABI for it
> or we are free to change it?
I thin it is just a transition mask between the CPU being marked
online -> active and inactive -> offline. Simply suggests the CPU is
available for the scheduler to run tasks on it.
--
Thanks and Regards,
Prateek