From: "Chuyi Zhou" <zhouchuyi@bytedance.com>
To: <longman@redhat.com>, <tj@kernel.org>, <hannes@cmpxchg.org>,
<mkoutny@suse.com>, <ridong.chen@linux.dev>
Cc: <linux-kernel@vger.kernel.org>, "Chuyi Zhou" <zhouchuyi@bytedance.com>
Subject: [PATCH 3/3] cgroup/cpuset: Skip sibling checks for v2 members without exclusive CPUs
Date: Mon, 23 Nov 2026 20:45:24 +0800 [thread overview]
Message-ID: <f4cec0e13d65fd60c6345dd63c2db1f5138bf532.1795436486.git.zhouchuyi@bytedance.com> (raw)
In-Reply-To: <cover.1795436486.git.zhouchuyi@bytedance.com>
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 2e09abb9e864..6c47cdb4a244 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -804,12 +804,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;
@@ -819,6 +828,7 @@ int validate_change(struct cpuset *cur, struct cpuset *trial)
goto out;
}
+valid:
ret = 0;
out:
rcu_read_unlock();
--
2.20.1
prev parent reply other threads:[~2026-11-23 12:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 12:45 [PATCH 0/3] cgroup/cpuset: Speed up v2 mask updates and domain rebuilds Chuyi Zhou
2026-11-23 12:45 ` [PATCH 1/3] cgroup/cpuset: Skip the sched domain attribute allocation on v2 Chuyi Zhou
2026-11-23 12:45 ` [PATCH 2/3] cgroup/cpuset: Check v2 partition overlap in a single pass Chuyi Zhou
2026-11-23 12:45 ` Chuyi Zhou [this message]
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=f4cec0e13d65fd60c6345dd63c2db1f5138bf532.1795436486.git.zhouchuyi@bytedance.com \
--to=zhouchuyi@bytedance.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=ridong.chen@linux.dev \
--cc=tj@kernel.org \
/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®