mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: Chuyi Zhou <zhouchuyi@bytedance.com>,
	longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org,
	mkoutny@suse.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] cgroup/cpuset: Skip sibling checks for v2 members without exclusive CPUs
Date: Tue, 1 Dec 2026 10:58:31 +0800	[thread overview]
Message-ID: <5ebec05e-5c83-48ff-a11d-cfedd840dfcb@linux.dev> (raw)
In-Reply-To: <f100fdf8-7b13-41f3-abf5-a13d22539fc6@bytedance.com>



On 12/1/2026 10:44 AM, Chuyi Zhou wrote:
> On 2026-12-01 9:49 a.m., Ridong Chen wrote:
>>
>>
>> On 11/30/2026 8:04 PM, Chuyi Zhou wrote:
>>> Changing cpuset.cpus on a cgroup v2 member calls validate_change(),
>>> which walks all siblings under cpuset_mutex to check CPU and memory
>>> exclusivity. The cost of changing one member's CPU mask grows with
>>> the number of children under its parent.
>>>
>>> Skip the walk when the member's cpuset.cpus.exclusive stays empty.
>>> An empty exclusive mask cannot intersect a sibling's exclusive mask.
>>> The check for a sibling whose allowed CPUs are all in the member's
>>> exclusive mask applies only when that mask changes. Only the top
>>> cpuset is memory-exclusive on v2, so the walk can also be skipped
>>> when changing cpuset.mems on these members.
>>>
>>> On a dual-socket Xeon Platinum 8582C with 240 online CPUs, the target
>>> cpuset contained one sleeping task. A writer pinned to CPU 1 alternated
>>> its cpuset.cpus between 2 and 2-3. Each table entry gives the median
>>> latency of 256 write() calls.
>>>
>>>       Children    Before (ns)    After (ns)
>>>              1            861           859
>>>             64           1425           856
>>>            512           5184           855
>>>           2048          24056           853
>>>
>>> Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
>>> ---
>>>    kernel/cgroup/cpuset.c | 12 +++++++++++-
>>>    1 file changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>>> index fb2c08b31b53..fb6359d72b68 100644
>>> --- a/kernel/cgroup/cpuset.c
>>> +++ b/kernel/cgroup/cpuset.c
>>> @@ -805,12 +805,21 @@ int validate_change(struct cpuset *cur, struct
>>> cpuset *trial)
>>>            !cpuset_cpumask_can_shrink(cur->effective_cpus,
>>> user_xcpus(trial)))
>>>            goto out;
>>> +    xcpus_changed = !cpumask_equal(cur->exclusive_cpus, trial-
>>>> exclusive_cpus);
>>> +
>>> +    /*
>>> +     * On v2 an unchanged, empty exclusive CPU mask cannot conflict with
>>> +     * a sibling's CPU masks. Only the top cpuset is memory-exclusive.
>>> +     */
>>> +    if (cpuset_v2() && cs_is_member(cur) && !xcpus_changed &&
>>> +        cpumask_empty(trial->exclusive_cpus))
>>> +        goto valid;
>>> +
>>>        /*
>>>         * If either I or some sibling (!= me) is exclusive, we can't
>>>         * overlap. exclusive_cpus cannot overlap with each other if set.
>>>         */
>>>        ret = -EINVAL;
>>> -    xcpus_changed = !cpumask_equal(cur->exclusive_cpus, trial-
>>>> exclusive_cpus);
>>>        cpuset_for_each_child(c, css, par) {
>>>            if (c == cur)
>>>                continue;
>>> @@ -820,6 +829,7 @@ int validate_change(struct cpuset *cur, struct
>>> cpuset *trial)
>>>                goto out;
>>>        }
>>> +valid:
>>>        ret = 0;
>>>    out:
>>>        rcu_read_unlock();
>>
>> Hi Chuyi,
>>
>> Thanks for the patch. I think the condition can be simplified, and
>> the sibling walk could be restructured a bit.
>>
>> Since commit 85ad3963de96 ("cgroup/cpuset: Remove CS_CPU_EXCLUSIVE
>> handling code from v2"), the v2 part of cpus_excl_conflict() only
>> looks at trial->exclusive_cpus:
>>
>> xcpus_changed && cpumask_subset(sibling->cpus_allowed, trial-
>>   >exclusive_cpus)
>> cpumask_intersects(trial->exclusive_cpus, sibling->exclusive_cpus)
>>
>> If trial->exclusive_cpus is empty, neither of them can be true,
>> whether or not exclusive_cpus has changed. The subset check also
>> requires a non-empty sibling->cpus_allowed, and a non-empty mask
>> cannot be a subset of an empty one. So !xcpus_changed is not needed.
>>
>> cs_is_member(cur) is not needed either. Nothing in the loop depends
>> on the partition state of @cur. For a partition root, conflicts with
>> siblings are handled by compute_trialcs_excpus() and
>> partition_cpus_change(), which invalidate the partition instead of
>> failing the write. Dropping the check would let partition roots with
>> an empty cpuset.cpus.exclusive skip the walk as well.
>>
>> On the memory side, mems_excl_conflict() never fires on v2: only
>> top_cpuset can be CS_MEM_EXCLUSIVE there, and it has no siblings.
>>
>> So the v1 and v2 sibling rules no longer share anything. How about
>> moving the walk into one helper that hands v1 off to cpuset-v1.c and
>> does the v2 checks by default, with the empty check as an early
>> return? Something like:
>>
>>
>> In cpuset.c:
>>
>> ```
>> static bool siblings_excl_conflict(struct cpuset *cur, struct cpuset
>> *trial)
>> {
>>     struct cgroup_subsys_state *css;
>>     struct cpuset *c;
>>     bool xcpus_changed;
>>
>>     if (!cpuset_v2())
>>       return cpuset1_siblings_excl_conflict(cur, trial);
>>
>>     /* An empty exclusive_cpus cannot conflict with any sibling */
>>     if (cpumask_empty(trial->exclusive_cpus))
>>             return false;
>>
>>     xcpus_changed = !cpumask_equal(cur->exclusive_cpus, trial-
>>   >exclusive_cpus);
>>     cpuset_for_each_child(c, css, parent_cs(cur)) {
>>       if (c == cur)
>>           continue;
>>       if (xcpus_changed && !cpumask_empty(c->cpus_allowed) &&
>>           cpumask_subset(c->cpus_allowed, trial->exclusive_cpus))
>>           return true;
>>       if (cpumask_intersects(trial->exclusive_cpus, c->exclusive_cpus))
>>           return true;
>>     }
>>     return false;
>> }
>> ```
>>
>> In cpuset-v1.c:
>>
>> ```
>> bool cpuset1_siblings_excl_conflict(struct cpuset *cur, struct cpuset
>> *trial)
>> {
>>     struct cgroup_subsys_state *css;
>>     struct cpuset *c;
>>
>>     cpuset_for_each_child(c, css, parent_cs(cur)) {
>>       if (c == cur)
>>           continue;
>>       if ((is_cpu_exclusive(trial) || is_cpu_exclusive(c)) &&
>>           cpumask_intersects(trial->cpus_allowed, c->cpus_allowed))
>>           return true;
>>       if ((is_mem_exclusive(trial) || is_mem_exclusive(c)) &&
>>           nodes_intersects(trial->mems_allowed, c->mems_allowed))
>>           return true;
>>     }
>>     return false;
>> }
>> ```
> 
> Hi Ridong,
> 
> Thanks for pointing this out. I agree that an empty
> trial->exclusive_cpus is enough to skip the v2 sibling walk, even when
> the mask has changed or the cpuset is a partition root.
> 
> Would you mind if I picked this up and sent follow-up patches to
> simplify the v2 check and move the v1 sibling walk into cpuset-v1.c as
> you suggested?
> 
> Since you also sketched out the implementation, would you prefer a
> Suggested-by or a Co-developed-by tag? If you prefer Co-developed-by,
> could you also send your Signed-off-by?
> 
Hi Chuyi,

Sure, please go ahead.

A Suggested-by is fine with me:

Suggested-by: Ridong Chen <ridong.chen@linux.dev>

-- 
Best regards
Ridong


  reply	other threads:[~2026-12-01  2:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 12:04 [PATCH v2 0/4] cgroup/cpuset: Speed up v2 mask updates and domain rebuilds Chuyi Zhou
2026-11-30 12:04 ` [PATCH v2 1/4] cgroup/cpuset: Skip the sched domain attribute allocation on v2 Chuyi Zhou
2026-11-30 17:32   ` Waiman Long
2026-11-30 12:04 ` [PATCH v2 2/4] cgroup/cpuset: Check v2 partition overlap in a single pass Chuyi Zhou
2026-11-30 18:02   ` Waiman Long
2026-11-30 18:04     ` Waiman Long
2026-11-30 12:04 ` [PATCH v2 3/4] cgroup/cpuset: Drop cpusets_overlap() Chuyi Zhou
2026-11-30 18:03   ` Waiman Long
2026-11-30 18:11     ` Waiman Long
2026-12-01  1:24   ` Ridong Chen
2026-11-30 12:04 ` [PATCH v2 4/4] cgroup/cpuset: Skip sibling checks for v2 members without exclusive CPUs Chuyi Zhou
2026-11-30 18:04   ` Waiman Long
2026-12-01  1:49   ` Ridong Chen
2026-12-01  2:44     ` Chuyi Zhou
2026-12-01  2:58       ` Ridong Chen [this message]
2026-12-01  1:25 ` [PATCH v2 0/4] cgroup/cpuset: Speed up v2 mask updates and domain rebuilds Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ebec05e-5c83-48ff-a11d-cfedd840dfcb@linux.dev \
    --to=ridong.chen@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=tj@kernel.org \
    --cc=zhouchuyi@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®