Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.39 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796089777; b=ipX5xAaqsaxNzuWD9JbfxybyfcBzlAFdINGkImtFUvDnERFHQ+orDaoqDSwgPrjTN7Bc 37aPFZW3VlFnOszKJkwhk1qrfdzlnWmT7WNJ4z5+YfdWIfsAyXeCRecEP8m3bNr92GbJB ZKVEwYeGAyjE0dABgh7MtqJwCBiUZ5FMSp/NJn0YtybxXJHEN5qp7edCFnPMqq2S5W5rK KKeWUVxmvMV9HO2Y279p5AoLPgsdxbMwOmwMUH1WB+WbFuHaTYqti4H29hmyzHTjtY/Qd SSFPR6Wx0yPhLN0wvQFIs7kd6W2kj6T9fFNzEKF/q+zR2Bm7EJarQwcIwILcnNgjiXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796089777; 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=x4o7vwPy42rki1ATgfTEsC0juLQ+QBDMm18vTMdOVI8=; b=BDs+T03VYzGFwwjE2smD3rC9Fklfx6xTRksWLowvs/Y1fgRy5/RbW874iMA2ZbX7sUXD tdXdZr1sc4xNIJLKlm9eVQP15TxPj5OcYeZpr9xBCT+WRRR1kMqs/dfSQdAcFs50Rzr8m ZEZ7GvV78WFNJdCZzMAHM5p/ZbJi9syLUmpe5x5NqiWFMJscCbIWhssv/MZSdI0QabhnO pwVTLUcAOXRwg1Ew7HhljKdhbXlpejoodIzbcJmAcwhLaa/CSjDFBOGx9dzPlqMnWofE6 ZzqQa2LEOuuZRGYyw9fIMJnUM9YUeVJTqSgrYMAM6W33/dAD2/X6Yctv+AL68NJTJxA== 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="O/lrtAyH"; arc=none smtp.remote-ip=95.215.58.39 Received: from mta1.migadu.com (out-39.mta1.migadu.com [95.215.58.39]) (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 6B30E606A31A for ; Tue, 1 Dec 2026 01:49:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B30E606A31A 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=O/lrtAyH X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=AbEoh0NKwriFsLzfSdtFjvhiLJRCI/fPwiC9EGdz7f0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796089774; v=1; x=1796694574; b=O/lrtAyH3KSCZ0p+duy41rOKtx8DYVSXy8J+YogCccJHYmbTulHIJT2ViQjwgexXq1TR5rM1 J6RjPcIu10l0Lzy2BLpOKZPZhZ08evQ8eCvtlPKod42eKSyQ6oqL8oqh4oocX/ANrtrXJAf+8VI wm0S04sptZ67/H0tnszTaKgI= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 05fffc626c996430; Tue, 01 Dec 2026 01:49:34 +0000 X-Mizu-Trace-ID: 05fffc626c996430 X-Migadu-Flow: FLOW_OUT Message-ID: <825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev> Date: Tue, 1 Dec 2026 09:49:26 +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> From: Ridong Chen In-Reply-To: <7b9ec8acd1d5fbc2e977ac08450aaf5de5952ce0.1796039668.git.zhouchuyi@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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; } ``` -- Best regards Ridong