[PATCH 3/3] cgroup/cpuset: Skip sibling checks for v2 members without exclusive CPUs
From: Chuyi Zhou
Date: Mon Nov 23 2026 - 07:46:31 EST
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@xxxxxxxxxxxxx>
---
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