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

From: Guopeng Zhang

Date: Tue Nov 03 2026 - 06:52:01 EST




在 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.

Thanks,
Guopeng

> +{
> + 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