From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796093133; b=LEzxP7e4VpeYnjkSJ8CnhuJ7msrr1W7hBeZii6dPRI931LcMzuKgJy81NCiTVZdKIm+M t2Sqxurp6tCJTF+klpMVizlMD978lvY33TKLp/fB9oehzWdfGdEgMt4ZJXfd0E52nCb67 fkJryQHzlcVpKyZjER+sIDc2qd/jGvOqiYRQk1ZHzaF2u2wD6oXArpiBpXA+f/0y0DKZq LALs2vjiPWG3wfjlLwbfc0eViQ+G9SeId+HqYkHXUsiwxjyKGmpFdpGV2m/9+cACuX4fN +FwJiYoIwpu/a+tUfl4l3R31mdhT3SEGN6TrtHZp2Ci2btaZ1c4HePSrDB8MvNpcScA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093133; h=DMARC-Filter:DKIM-Signature:To:Date:X-Lms-Return-Path:In-Reply-To: References:User-Agent:X-Original-From:Cc:Mime-Version: Content-Transfer-Encoding:Content-Type:From:Subject:Message-Id; bh=mP+39dk+ErXAFzb8eaQDo5dL9HT0292WAADJflnKCZk=; b=QYKeLVdhIh4f+KSzvWGEMFg34q3/GnMdLIYf1NIUBcG2dj5qKSkTEwHI6yez3OyYdNJn zir3B4FuxRjUgbUOLlBfca3BUP3VDy+iDXsWRgRyE1S36SWAMu60q9L1Qkz7w23eQZ5LL IVDsSFXIk68UckjzBa9OAxiwEx+F/YndUsgSigYV/QfeZrdsK+z9l5u5q4P7QqGIHYIIm Kv0TQZvhI1QxHeWSM6iyxXJwWou1pQTIrCcdnVZQSYZOSQWDyMDzgwa/iwFm861880d3E K2iM7aSp+57X8Lp0EOvBPL7c5ZG62bkU/DXMsugG4kPqCnjb8OG82S4IV79gllC2DDA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=XSG6N+TO; arc=none smtp.remote-ip=209.127.231.113 Received: from va-2-113.ptr.blmpb.com (va-2-113.ptr.blmpb.com [209.127.231.113]) (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 D21C4606A31A for ; Tue, 1 Dec 2026 02:45:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D21C4606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=XSG6N+TO DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796093127; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=mP+39dk+ErXAFzb8eaQDo5dL9HT0292WAADJflnKCZk=; b=XSG6N+TOAGzShotZz+VhM7ok5nJjSN7/bYPeLHWhrsTtleTA0Pc9+YsffqKa0GGz2MeYre xRocO6hnfaBmk97GENmA1XqvaXlUgwUNu2LDgROqJ/PnQrGgGO8QGmh2KKz5fgcBDRjC3j enz/Ann0M8joPI0FMpfk7s01PsGo0sQA4bdYC7+YyxJiauZWFPX81YkLUF5kRB32lyeqoH +BvZfud6XRSXnSynamU+Xk9B6bLwe4SsqtjfybEjhs6Z4AF5Js0j09o4Ru47Kq+h27u140 30tO6W3Az6Df3WO+cTMm7YnOXwHpdN+nyLbDk2IdXXaf5p8JTWcFibfQjn3GUg== To: "Ridong Chen" , , , , Date: Tue, 1 Dec 2026 10:44:58 +0800 X-Lms-Return-Path: In-Reply-To: <825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev> References: <7b9ec8acd1d5fbc2e977ac08450aaf5de5952ce0.1796039668.git.zhouchuyi@bytedance.com> <825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev> User-Agent: Mozilla Thunderbird X-Original-From: Chuyi Zhou Cc: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 From: "Chuyi Zhou" Subject: Re: [PATCH v2 4/4] cgroup/cpuset: Skip sibling checks for v2 members without exclusive CPUs Message-Id: On 2026-12-01 9:49 a.m., Ridong Chen wrote: >=20 >=20 > 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. >> >> =C2=A0=C2=A0=C2=A0=C2=A0 Children=C2=A0=C2=A0=C2=A0 Before (ns)=C2=A0=C2= =A0=C2=A0 After (ns) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 1=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 861=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 859 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 64=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 1425=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 856 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 512=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 5184=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 855 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 2048=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 24056=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 853 >> >> Signed-off-by: Chuyi Zhou >> --- >> =C2=A0 kernel/cgroup/cpuset.c | 12 +++++++++++- >> =C2=A0 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=20 >> cpuset *trial) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 !cpuset_cpumask_c= an_shrink(cur->effective_cpus,=20 >> user_xcpus(trial))) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto out; >> +=C2=A0=C2=A0=C2=A0 xcpus_changed =3D !cpumask_equal(cur->exclusive_cpus= , trial-=20 >> >exclusive_cpus); >> + >> +=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0 * On v2 an unchanged, empty exclusive CPU mask= cannot conflict with >> +=C2=A0=C2=A0=C2=A0=C2=A0 * a sibling's CPU masks. Only the top cpuset i= s memory-exclusive. >> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0 if (cpuset_v2() && cs_is_member(cur) && !xcpus_chang= ed && >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cpumask_empty(trial->exclusi= ve_cpus)) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto valid; >> + >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * If either I or some sibling (!=3D= me) is exclusive, we can't >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * overlap. exclusive_cpus cannot ov= erlap with each other if set. >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D -EINVAL; >> -=C2=A0=C2=A0=C2=A0 xcpus_changed =3D !cpumask_equal(cur->exclusive_cpus= , trial-=20 >> >exclusive_cpus); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cpuset_for_each_child(c, css, par) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (c =3D=3D cur) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 continue; >> @@ -820,6 +829,7 @@ int validate_change(struct cpuset *cur, struct=20 >> cpuset *trial) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 goto out; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> +valid: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D 0; >> =C2=A0 out: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rcu_read_unlock(); >=20 > Hi Chuyi, >=20 > Thanks for the patch. I think the condition can be simplified, and > the sibling walk could be restructured a bit. >=20 > 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: >=20 > xcpus_changed && cpumask_subset(sibling->cpus_allowed, trial-=20 > >exclusive_cpus) > cpumask_intersects(trial->exclusive_cpus, sibling->exclusive_cpus) >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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: >=20 >=20 > In cpuset.c: >=20 > ``` > static bool siblings_excl_conflict(struct cpuset *cur, struct cpuset=20 > *trial) > { > =C2=A0 struct cgroup_subsys_state *css; > =C2=A0 struct cpuset *c; > =C2=A0 bool xcpus_changed; >=20 > =C2=A0 if (!cpuset_v2()) > =C2=A0=C2=A0=C2=A0=C2=A0return cpuset1_siblings_excl_conflict(cur, trial= ); >=20 > =C2=A0 /* An empty exclusive_cpus cannot conflict with any sibling */ > =C2=A0 if (cpumask_empty(trial->exclusive_cpus)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return false; >=20 > =C2=A0 xcpus_changed =3D !cpumask_equal(cur->exclusive_cpus, trial-=20 > >exclusive_cpus); > =C2=A0 cpuset_for_each_child(c, css, parent_cs(cur)) { > =C2=A0=C2=A0=C2=A0=C2=A0if (c =3D=3D cur) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 continue; > =C2=A0=C2=A0=C2=A0=C2=A0if (xcpus_changed && !cpumask_empty(c->cpus_allo= wed) && > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cpumask_subset(c->cpus_allowe= d, trial->exclusive_cpus)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return true; > =C2=A0=C2=A0=C2=A0=C2=A0if (cpumask_intersects(trial->exclusive_cpus, c-= >exclusive_cpus)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return true; > =C2=A0 } > =C2=A0 return false; > } > ``` >=20 > In cpuset-v1.c: >=20 > ``` > bool cpuset1_siblings_excl_conflict(struct cpuset *cur, struct cpuset=20 > *trial) > { > =C2=A0 struct cgroup_subsys_state *css; > =C2=A0 struct cpuset *c; >=20 > =C2=A0 cpuset_for_each_child(c, css, parent_cs(cur)) { > =C2=A0=C2=A0=C2=A0=C2=A0if (c =3D=3D cur) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 continue; > =C2=A0=C2=A0=C2=A0=C2=A0if ((is_cpu_exclusive(trial) || is_cpu_exclusive= (c)) && > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cpumask_intersects(trial->cpu= s_allowed, c->cpus_allowed)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return true; > =C2=A0=C2=A0=C2=A0=C2=A0if ((is_mem_exclusive(trial) || is_mem_exclusive= (c)) && > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nodes_intersects(trial->mems_= allowed, c->mems_allowed)) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return true; > =C2=A0 } > =C2=A0 return false; > } > ``` Hi Ridong, Thanks for pointing this out. I agree that an empty=20 trial->exclusive_cpus is enough to skip the v2 sibling walk, even when=20 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=20 simplify the v2 check and move the v1 sibling walk into cpuset-v1.c as=20 you suggested? Since you also sketched out the implementation, would you prefer a=20 Suggested-by or a Co-developed-by tag? If you prefer Co-developed-by,=20 could you also send your Signed-off-by? Thanks, Chuyi