Re: [RFC PATCH -v4 04/22] cpuset: introduce partition_enable()

From: Ridong Chen

Date: Tue Nov 03 2026 - 07:53:30 EST




On 11/3/2026 6:26 PM, Guopeng Zhang wrote:

在 2026/11/1 19:41, Ridong Chen 写道:
From: Chen Ridong<chenridong@xxxxxxxxxx>

Add partition_enable() to consolidate updates to key cpuset structures
during partition enablement, including:
1. remote_partition
2. effective_xcpus
3. partition_root_state
4. prs_err

Key operations performed:
1. Invokes partition_xcpus_add() to assign exclusive CPUs
2. Maintains remote partition flag
3. Syncs the effective_xcpus mask
4. Updates partition_root_state and prs_err
5. Triggers scheduler domain rebuilds
6. Sends partition change notifications

This helper also handles the transition between root and isolated
states of a valid partition. In that case the cpumasks are unchanged
and only isolated_cpus is updated.

A partition_state_update() helper is added to set partition_root_state
and prs_err, and to reset the partition data when the new state is not
a valid partition.

Signed-off-by: Chen Ridong<chenridong@xxxxxxxxxx>
Signed-off-by: Ridong Chen<chenridong@xxxxxxxxxx>
---
kernel/cgroup/cpuset.c | 51 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index df52f6e5e99f..052a131731dd 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1716,6 +1716,57 @@ static void compute_effective_nodemask(nodemask_t *new_mems,
nodes_copy(*new_mems, parent->effective_mems);
}
+static void partition_state_update(struct cpuset *cs, int new_prs,
+ enum prs_errcode prs_err)
+{
+ lockdep_assert_held(&callback_lock);
+
+ cs->partition_root_state = new_prs;
+ WRITE_ONCE(cs->prs_err, prs_err);
+ if (!is_partition_valid(cs))
+ reset_partition_data(cs);
+}
+
+/**
+ * partition_enable - Transitions a cpuset to a partition root
+ * @cs: The cpuset to enable partition for
+ * @parent: Parent cpuset of @cs, NULL for remote parent
+ * @new_prs: New partition state to set
+ * @new_excpus: New effective exclusive CPUs mask for the partition
+ *
+ * Transitions a cpuset to a partition root, only for v2.
+ * It also supports the transition between root and isolated partition.
+ */
+static void partition_enable(struct cpuset *cs, struct cpuset *parent,
+ int new_prs, struct cpumask *new_excpus)
Should we consider the bisection case here? With CONFIG_WERROR=y this
patch fails to build on its own — partition_enable() is defined but not
used.


Hi Guopeng,

Thanks for catching this. You are right, each patch should build on
its own, and with CONFIG_WERROR=y these helpers trigger
-Wunused-function until they are used in patches 7-9.

The helpers are introduced in separate patches on purpose: Waiman
suggested having them complete when introduced, and then converting
remote and local partitions to them in later patches, to make the
series easier to review [1]. To keep that and still build cleanly,
I'll mark them __maybe_unused when they are introduced, and drop it
in the patch that first uses each of them.

[1] https://lore.kernel.org/all/e8018984-96ed-49fa-8571-79a0d39cb218@xxxxxxxxxx/


+{
+ int old_prs = cs->partition_root_state;
+
+ lockdep_assert_cpuset_lock_held();
+ WARN_ON_ONCE(new_prs <= 0);
+ WARN_ON_ONCE(!cpuset_v2());
+
+ if (old_prs == new_prs)
+ return;
+
+ spin_lock_irq(&callback_lock);
+ if (old_prs > 0) {
+ /* Switch between root and isolated, cpumasks are unchanged */
+ isolated_cpus_update(old_prs, new_prs, cs->effective_xcpus);
+ } else {
+ /* enable partition should only add exclusive cpus */
+ partition_xcpus_add(new_prs, parent, new_excpus);
+ /* enable remote partition */
+ if (!parent)
+ cs->remote_partition = true;
+ cpumask_copy(cs->effective_xcpus, new_excpus);
+ }
+ partition_state_update(cs, new_prs, PERR_NONE);
+ spin_unlock_irq(&callback_lock);
+ cpuset_force_rebuild();
+ notify_partition_change(cs, old_prs);
+}
+
/*
* remote_partition_enable - Enable current cpuset as a remote partition root
* @cs: the cpuset to update


--
Best regards
Ridong