From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.233 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796093923; b=npRxV/lTuX4765noHZKag602tPbp+rzcxxi9vi2P6q9E97oXgKDdaobMWMG9vWArpH7w 6Ij/IKKZuJsbdsGnrLtJngCPRD1pGiI+l3YqxzUn2qFTEGsZWSST5nB0LAdbrBaeHEGNq +w2NE0vudIlsPz6bHiP5jUY/Kpm5U8+CiOQDNSxGSYaP4AucEfrg/2RnoweHqN+kJB3Xk A9WLxoxLk5jhbAdFJsSQPTGmBmJYPwuCxiEvaQGEBvAsJsz9xUvHDJI/6PV3LDe+C9Ytq wN88UnH1moeBPOksloNnTOb72R/ZSPKTeHAIhd1A/mTMeuofdKeUFiPEvAYMYKLy36g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093923; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=rhDr6VcZb+TlCbJ5tZXou0TgHpHPzXS/mngK2ZjtPkM=; b=XjKxXLZyHt9P1uBgorRzrTYCChxc5cKua96VBZfDrk6xeMXU6vaN0KPbhLl5n1cvrkzf 8RhYomELh9Ye+zhYK4298M9xXsNLzGjpKNzW2unvLfDzWMkwDLZpYhvNdviBjAn/Nh9DW vZkJ5jY8A2px+fkscDYXDCIflUFlbMkVYsd4h6mZ7409UI8sxj87+CPS4dBhJmnm0B8py TzJZFjvU8lmSsdg2PhQ9WRDW1UQzkSrCATompsu1rVCs0K9ivgla+80dptRd+xPl1w+AI 2v9lBChyevUsDdVKkdR2AB/RUcnQXEHycnf7b3Z971axIvi16AVTyLkYCRJIa4l6YIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MF6HoxZ6; arc=none smtp.remote-ip=91.218.175.233 Received: from mta0.migadu.com (out-233.mta0.migadu.com [91.218.175.233]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E414606A31A for ; Tue, 1 Dec 2026 02:58:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E414606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MF6HoxZ6 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=OMJwh1S9XYYrNqjuC7XMkDN586C1gQcqOlfJXSoaty8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796093920; v=1; x=1796698720; b=MF6HoxZ604owdpW3rC0/BvMYkhDBZg5isytVBZQ0U0Z819NS00kFeLCDp2Bo2wYplUsquMhV /bEYIwtUMjYtJBOmTxKFk1eCYLQ8dSm4GYwHSIqUkVMnBmDdkwKvvPVTm+oSh6u2BlA4qZ4pKRS 0IHG65m6wTGgxXeOpD0idCTM= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id a96649bc22cbf2d0; Tue, 01 Dec 2026 02:58:40 +0000 X-Mizu-Trace-ID: a96649bc22cbf2d0 X-Migadu-Flow: FLOW_OUT Message-ID: <5ebec05e-5c83-48ff-a11d-cfedd840dfcb@linux.dev> Date: Tue, 1 Dec 2026 10:58:31 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/4] cgroup/cpuset: Skip sibling checks for v2 members without exclusive CPUs To: Chuyi Zhou , longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com Cc: linux-kernel@vger.kernel.org References: <7b9ec8acd1d5fbc2e977ac08450aaf5de5952ce0.1796039668.git.zhouchuyi@bytedance.com> <825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev> From: Ridong Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 >>> --- >>>   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 -- Best regards Ridong