[RFC PATCH -v4 05/22] cpuset: introduce partition_disable()

From: Ridong Chen

Date: Sun Nov 01 2026 - 06:45:03 EST


From: Chen Ridong <chenridong@xxxxxxxxxx>

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

Key operations performed:
1. Cleaning up remote_partition
2. Removing exclusive CPUs via partition_xcpus_del()
3. Recomputing effective exclusive CPUs mask
4. Updating partition state and error status
5. Triggering required scheduler domain rebuilds
6. Sending partition change notifications

Only the CPUs actually granted by the parent are given back, as the
parent may have shrunk. An invalid partition, or a partition under an
invalid parent, has already given back its exclusive CPUs, so there is
nothing to delete. A remote partition gets its CPUs from top_cpuset,
which owns all the CPUs.

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

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 052a131731dd..c0d6dd7297f1 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1767,6 +1767,45 @@ static void partition_enable(struct cpuset *cs, struct cpuset *parent,
notify_partition_change(cs, old_prs);
}

+/**
+ * partition_disable - Disable partition root state for a cpuset
+ * @cs: The cpuset to disable partition for
+ * @parent: Parent cpuset of @cs, NULL for remote parent
+ * @new_prs: New partition root state (should be non-positive)
+ * @prs_err: Error code to set if disabling due to validation failure
+ */
+static void partition_disable(struct cpuset *cs, struct cpuset *parent,
+ int new_prs, enum prs_errcode prs_err)
+{
+ int old_prs = cs->partition_root_state;
+
+ lockdep_assert_cpuset_lock_held();
+ WARN_ON_ONCE(new_prs > 0);
+ WARN_ON_ONCE(!cpuset_v2());
+
+ spin_lock_irq(&callback_lock);
+ cs->remote_partition = false;
+ /*
+ * Disable a partition should only delete exclusive cpus, and only
+ * those actually granted by the parent as the parent may have shrunk.
+ * An invalid partition or an invalid parent has already given back
+ * its exclusive CPUs, there is nothing to delete. A remote partition
+ * gets its CPUs from top_cpuset which owns all the CPUs.
+ */
+ if (is_partition_valid(cs) && (!parent || is_partition_valid(parent))) {
+ if (parent)
+ cpumask_and(cs->effective_xcpus, cs->effective_xcpus,
+ parent->effective_xcpus);
+ partition_xcpus_del(old_prs, parent, cs->effective_xcpus);
+ }
+ /* effective_xcpus may need to be changed */
+ compute_excpus(cs, cs->effective_xcpus);
+ partition_state_update(cs, new_prs, prs_err);
+ 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
--
2.34.1