* [PATCH 1/2] cgroup/cpuset: Skip v2 sibling checks with an empty exclusive CPU mask
2026-12-02 10:44 [PATCH 0/2] cgroup/cpuset: Limit v2 sibling checks to nonempty exclusive masks Chuyi Zhou
@ 2026-12-02 10:44 ` Chuyi Zhou
2026-12-02 10:44 ` [PATCH 2/2] cgroup/cpuset: Separate v1 and v2 sibling exclusivity checks Chuyi Zhou
1 sibling, 0 replies; 3+ messages in thread
From: Chuyi Zhou @ 2026-12-02 10:44 UTC (permalink / raw)
To: longman, tj, hannes, mkoutny, ridong.chen; +Cc: linux-kernel, Chuyi Zhou
validate_change() skips the sibling walk on v2 only for members whose
exclusive CPU mask stays empty. It still scans siblings when a partition
root has no explicit exclusive CPUs or when a cpuset clears its mask.
An empty exclusive CPU mask can neither intersect a sibling's exclusive
CPUs nor contain a sibling's nonempty allowed CPU mask. Only the top
cpuset is memory-exclusive on v2, and it has no siblings.
Skip the walk whenever the trial exclusive CPU mask is empty. For a
partition root, compute_trialcs_excpus() still accounts for CPUs held
by siblings when computing the effective exclusive mask.
Suggested-by: Ridong Chen <ridong.chen@linux.dev>
Link: https://lore.kernel.org/r/825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev
Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
---
kernel/cgroup/cpuset.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index fb6359d72b68..d2337f817568 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -805,14 +805,11 @@ 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
+ * On v2 an 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))
+ if (cpuset_v2() && cpumask_empty(trial->exclusive_cpus))
goto valid;
/*
@@ -820,6 +817,7 @@ int validate_change(struct cpuset *cur, struct cpuset *trial)
* 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;
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] cgroup/cpuset: Separate v1 and v2 sibling exclusivity checks
2026-12-02 10:44 [PATCH 0/2] cgroup/cpuset: Limit v2 sibling checks to nonempty exclusive masks Chuyi Zhou
2026-12-02 10:44 ` [PATCH 1/2] cgroup/cpuset: Skip v2 sibling checks with an empty exclusive CPU mask Chuyi Zhou
@ 2026-12-02 10:44 ` Chuyi Zhou
1 sibling, 0 replies; 3+ messages in thread
From: Chuyi Zhou @ 2026-12-02 10:44 UTC (permalink / raw)
To: longman, tj, hannes, mkoutny, ridong.chen; +Cc: linux-kernel, Chuyi Zhou
validate_change() selects the CPU exclusivity rules for each sibling
and checks memory exclusivity on both hierarchies. On v1, exclusivity
depends on flags and the allowed CPU and memory masks. On v2, the
proposed exclusive CPU mask must be disjoint from each sibling's
exclusive CPU mask. If the proposed mask changes, it must also leave at
least one allowed CPU for each sibling with a nonempty allowed CPU mask.
Select the hierarchy once before walking the siblings. Move the v1
CPU and memory checks into cpuset-v1.c and keep the v2 CPU checks
together in cpuset.c. Use cpuset_v2() so v1 mounts with the
cpuset_v2_mode option retain their v1 exclusivity rules.
Suggested-by: Ridong Chen <ridong.chen@linux.dev>
Link: https://lore.kernel.org/r/825c0c94-8565-4c4c-82c7-9c0f5872e6a9@linux.dev
Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
---
kernel/cgroup/cpuset-internal.h | 6 +--
kernel/cgroup/cpuset-v1.c | 36 +++++++++-----
kernel/cgroup/cpuset.c | 88 +++++++++++++--------------------
3 files changed, 62 insertions(+), 68 deletions(-)
diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-internal.h
index b1c8f8fc2edf..84a67bfeae5b 100644
--- a/kernel/cgroup/cpuset-internal.h
+++ b/kernel/cgroup/cpuset-internal.h
@@ -322,7 +322,7 @@ void cpuset1_hotplug_update_tasks(struct cpuset *cs,
struct cpumask *new_cpus, nodemask_t *new_mems,
bool cpus_updated, bool mems_updated);
int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial);
-bool cpuset1_cpus_excl_conflict(struct cpuset *cs1, struct cpuset *cs2);
+bool cpuset1_siblings_excl_conflict(struct cpuset *cur, struct cpuset *trial);
void cpuset1_init(struct cpuset *cs);
void cpuset1_online_css(struct cgroup_subsys_state *css);
int cpuset1_generate_sched_domains(cpumask_var_t **domains,
@@ -337,8 +337,8 @@ static inline void cpuset1_hotplug_update_tasks(struct cpuset *cs,
bool cpus_updated, bool mems_updated) {}
static inline int cpuset1_validate_change(struct cpuset *cur,
struct cpuset *trial) { return 0; }
-static inline bool cpuset1_cpus_excl_conflict(struct cpuset *cs1,
- struct cpuset *cs2) { return false; }
+static inline bool cpuset1_siblings_excl_conflict(struct cpuset *cur,
+ struct cpuset *trial) { return false; }
static inline void cpuset1_init(struct cpuset *cs) {}
static inline void cpuset1_online_css(struct cgroup_subsys_state *css) {}
static inline int cpuset1_generate_sched_domains(cpumask_var_t **domains,
diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c
index e64bbf181faf..babea80f3927 100644
--- a/kernel/cgroup/cpuset-v1.c
+++ b/kernel/cgroup/cpuset-v1.c
@@ -382,21 +382,35 @@ int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial)
return ret;
}
-/*
- * cpuset1_cpus_excl_conflict() - Check if two cpusets have exclusive CPU conflicts
- * to legacy (v1)
- * @cs1: first cpuset to check
- * @cs2: second cpuset to check
+/**
+ * cpuset1_siblings_excl_conflict - Check v1 sibling CPU and memory exclusivity
+ * @cur: Cpuset being updated, which must have a parent
+ * @trial: Copy of @cur with the proposed changes
*
- * Returns: true if CPU exclusivity conflict exists, false otherwise
+ * If either cpuset is CPU-exclusive, their allowed CPU masks must be
+ * disjoint. If either is memory-exclusive, their allowed memory nodes
+ * must be disjoint.
*
- * If either cpuset is CPU exclusive, their allowed CPUs cannot intersect.
+ * Context: Caller holds cpuset_mutex and rcu_read_lock().
+ * Return: %true if @trial conflicts with an online sibling, %false otherwise.
*/
-bool cpuset1_cpus_excl_conflict(struct cpuset *cs1, struct cpuset *cs2)
+bool cpuset1_siblings_excl_conflict(struct cpuset *cur, struct cpuset *trial)
{
- if (is_cpu_exclusive(cs1) || is_cpu_exclusive(cs2))
- return cpumask_intersects(cs1->cpus_allowed,
- cs2->cpus_allowed);
+ struct cgroup_subsys_state *css;
+ struct cpuset *sibling;
+
+ cpuset_for_each_child(sibling, css, parent_cs(cur)) {
+ if (sibling == cur)
+ continue;
+
+ if ((is_cpu_exclusive(trial) || is_cpu_exclusive(sibling)) &&
+ cpumask_intersects(trial->cpus_allowed, sibling->cpus_allowed))
+ return true;
+
+ if ((is_mem_exclusive(trial) || is_mem_exclusive(sibling)) &&
+ nodes_intersects(trial->mems_allowed, sibling->mems_allowed))
+ return true;
+ }
return false;
}
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index d2337f817568..d9fc70f956cf 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -706,39 +706,47 @@ static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
}
/**
- * cpus_excl_conflict - Check if two cpusets have exclusive CPU conflicts
- * @trial: the trial cpuset to be checked
- * @sibling: a sibling cpuset to be checked against
- * @xcpus_changed: set if exclusive_cpus has been set
+ * siblings_excl_conflict - Check a cpuset change for sibling conflicts
+ * @cur: Cpuset being updated, which must have a parent
+ * @trial: Copy of @cur with the proposed changes
*
- * Returns: true if CPU exclusivity conflict exists, false otherwise
+ * On v2, siblings' explicit exclusive CPU masks must be disjoint. A change
+ * to the exclusive mask must also leave at least one allowed CPU for each
+ * sibling with a nonempty allowed CPU mask.
*
- * Conflict detection rules:
- * o cgroup v1
- * See cpuset1_cpus_excl_conflict()
- * o cgroup v2
- * - The exclusive_cpus values cannot overlap.
- * - New exclusive_cpus cannot be a superset of a sibling's cpus_allowed.
+ * Context: Caller holds cpuset_mutex and rcu_read_lock().
+ * Return: %true if @trial conflicts with an online sibling, %false otherwise.
*/
-static inline bool cpus_excl_conflict(struct cpuset *trial, struct cpuset *sibling,
- bool xcpus_changed)
+static bool siblings_excl_conflict(struct cpuset *cur, struct cpuset *trial)
{
+ struct cgroup_subsys_state *css;
+ struct cpuset *sibling;
+ bool xcpus_changed;
+
if (!cpuset_v2())
- return cpuset1_cpus_excl_conflict(trial, sibling);
+ return cpuset1_siblings_excl_conflict(cur, trial);
- /* The cpus_allowed of a sibling cpuset cannot be a subset of the new exclusive_cpus */
- if (xcpus_changed && !cpumask_empty(sibling->cpus_allowed) &&
- cpumask_subset(sibling->cpus_allowed, trial->exclusive_cpus))
- return true;
+ /*
+ * On v2 an empty exclusive CPU mask cannot conflict with
+ * a sibling's CPU masks. Only the top cpuset is memory-exclusive.
+ */
+ if (cpumask_empty(trial->exclusive_cpus))
+ return false;
- /* Exclusive_cpus cannot intersect */
- return cpumask_intersects(trial->exclusive_cpus, sibling->exclusive_cpus);
-}
+ xcpus_changed = !cpumask_equal(cur->exclusive_cpus, trial->exclusive_cpus);
+ cpuset_for_each_child(sibling, css, parent_cs(cur)) {
+ if (sibling == cur)
+ continue;
+
+ /* New exclusive CPUs must leave siblings with allowed CPUs. */
+ if (xcpus_changed && !cpumask_empty(sibling->cpus_allowed) &&
+ cpumask_subset(sibling->cpus_allowed, trial->exclusive_cpus))
+ return true;
+
+ if (cpumask_intersects(trial->exclusive_cpus, sibling->exclusive_cpus))
+ return true;
+ }
-static inline bool mems_excl_conflict(struct cpuset *cs1, struct cpuset *cs2)
-{
- if ((is_mem_exclusive(cs1) || is_mem_exclusive(cs2)))
- return nodes_intersects(cs1->mems_allowed, cs2->mems_allowed);
return false;
}
@@ -764,9 +772,6 @@ static inline bool mems_excl_conflict(struct cpuset *cs1, struct cpuset *cs2)
int validate_change(struct cpuset *cur, struct cpuset *trial)
{
- struct cgroup_subsys_state *css;
- struct cpuset *c, *par;
- bool xcpus_changed;
int ret = 0;
rcu_read_lock();
@@ -780,8 +785,6 @@ int validate_change(struct cpuset *cur, struct cpuset *trial)
if (cur == &top_cpuset)
goto out;
- par = parent_cs(cur);
-
/*
* We can't shrink if we won't have enough room for SCHED_DEADLINE
* tasks. This check is not done when scheduling is disabled as the
@@ -805,30 +808,7 @@ int validate_change(struct cpuset *cur, struct cpuset *trial)
!cpuset_cpumask_can_shrink(cur->effective_cpus, user_xcpus(trial)))
goto out;
- /*
- * On v2 an empty exclusive CPU mask cannot conflict with
- * a sibling's CPU masks. Only the top cpuset is memory-exclusive.
- */
- if (cpuset_v2() && 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;
- if (cpus_excl_conflict(trial, c, xcpus_changed))
- goto out;
- if (mems_excl_conflict(trial, c))
- goto out;
- }
-
-valid:
- ret = 0;
+ ret = siblings_excl_conflict(cur, trial) ? -EINVAL : 0;
out:
rcu_read_unlock();
return ret;
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread