Re: [PATCH 1/3] cgroup/cpuset: Skip the sched domain attribute allocation on v2
From: Chuyi Zhou
Date: Thu Nov 26 2026 - 00:11:41 EST
On 2026-11-26 10:49 a.m., Ridong Chen wrote:
>
>
> On 11/23/2026 8:45 PM, Chuyi Zhou wrote:
>> Cgroup v2 cpusets use the default scheduling domain attributes for every
>> partition. The scheduler treats a NULL attribute pointer as the default
>> both when matching existing domains and when building new ones.
>>
>> generate_sched_domains() allocates an attribute array for v2 and fills
>> each entry with SD_ATTR_INIT, even in the single-partition case.
>>
>> Return NULL for the v2 attributes. For N > 0 partitions, this saves one
>> memory allocation and N attribute initializations per rebuild.
>>
>> Signed-off-by: Chuyi Zhou <zhouchuyi@xxxxxxxxxxxxx>
>> ---
>> kernel/cgroup/cpuset.c | 21 +++++++--------------
>> 1 file changed, 7 insertions(+), 14 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index c7b3a734cda8..633fd05f513e 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -867,7 +867,6 @@ static int generate_sched_domains(cpumask_var_t
>> **domains,
>> struct cpuset **csa; /* array of all cpuset ptrs */
>> int i, j; /* indices for partition finding loops */
>> cpumask_var_t *doms; /* resulting partition; i.e. sched
>> domains */
>> - struct sched_domain_attr *dattr; /* attributes for custom
>> domains */
>> int ndoms = 0; /* number of sched domains in result */
>> struct cgroup_subsys_state *pos_css;
>> @@ -875,7 +874,6 @@ static int generate_sched_domains(cpumask_var_t
>> **domains,
>> return cpuset1_generate_sched_domains(domains, attributes);
>> doms = NULL;
>> - dattr = NULL;
>> csa = NULL;
>> /* Special case for the 99% of systems with one, full, sched
>> domain */
>> @@ -926,15 +924,8 @@ generate_doms:
>> goto done;
>> /*
>> - * The rest of the code, including the scheduler, can deal with
>> - * dattr==NULL case. No need to abort if alloc fails.
>> - */
>> - dattr = kmalloc_objs(struct sched_domain_attr, ndoms);
>> -
>> - /*
>> - * Cgroup v2 doesn't support domain attributes, just set all of them
>> - * to SD_ATTR_INIT. Also non-isolating partition root CPUs are a
>> - * subset of HK_TYPE_DOMAIN_BOOT housekeeping CPUs.
>> + * Non-isolating child partition root CPUs are a subset of
>> + * HK_TYPE_DOMAIN_BOOT housekeeping CPUs.
>> */
>> for (i = 0; i < ndoms; i++) {
>> /*
>> @@ -946,8 +937,6 @@ generate_doms:
>> housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT));
>> else
>> cpumask_copy(doms[i], csa[i]->effective_cpus);
>> - if (dattr)
>> - dattr[i] = SD_ATTR_INIT;
>> }
>> done:
>> @@ -960,8 +949,12 @@ done:
>> if (doms == NULL)
>> ndoms = 1;
>> + /*
>> + * Cgroup v2 uses the default domain attributes. The scheduler
>> treats
>> + * a NULL attribute array as SD_ATTR_INIT for every partition.
>> + */
>> *domains = doms;
>> - *attributes = dattr;
>> + *attributes = NULL;
>> return ndoms;
>> }
>
> LGTM.
>
> Reviewed-by: Ridong Chen <ridong.chen@xxxxxxxxx>
> Thanks.
>
Thanks for the review!
I'll add Reviewed-by tag if I need to send v2.