Re: [PATCH v5 03/12] cpuset: introduce partition_update()

From: Guopeng Zhang

Date: Tue Nov 24 2026 - 05:07:02 EST




在 2026/11/14 16:31, Ridong Chen 写道:
> From: Ridong Chen <chenridong@xxxxxxxxxx>
>
> Introduce partition_update() to centralize updates to key cpuset structures
> during a partition update, including:
> 1. effective_xcpus
> 2. exclusive_cpus
>
> Key operations performed:
> 1. Adding and removing exclusive CPUs via partition_xcpus_add()/del()
> 2. Synchronizing the effective exclusive CPUs mask
> 3. Updating the exclusive CPUs mask when modification is required
> 4. Triggering scheduler domain rebuilds
>
> For a local partition, the CPUs to be added or deleted are restricted to
> those in the parent's effective_xcpus, as the parent may have shrunk.
> The function returns early if nothing is to be changed.
>
> The partition root state is unchanged by this function, so no partition
> change notification is sent.
>
> Signed-off-by: Ridong Chen <chenridong@xxxxxxxxxx>
> ---
> kernel/cgroup/cpuset.c | 52 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 12bdcaeb8ae5..c66864faab32 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1824,6 +1824,58 @@ static void __maybe_unused partition_disable(struct cpuset *cs, int new_prs,
> update_sibling_cpumasks(parent, cs, tmp);
> }
>
> +/**
> + * partition_update - Update an existing partition configuration
> + * @cs: The cpuset to update
> + * @prs: Partition root state (must be positive)
> + * @xcpus: New exclusive CPUs mask for the partition (NULL to keep current)
> + * @excpus: New effective exclusive CPUs mask
> + * @tmp: Temporary masks
> + *
> + * Updates partition-related fields. The tmp->addmask is the CPU mask that
> + * will be added to the subpartitions_cpus and removed from parent's
> + * effective_cpus, and the tmp->delmask vice versa.
> + */

My understanding is that tmp->addmask is added to subpartitions_cpus
only when the resource parent is top_cpuset. For remote partitions,
NULL represents that resource parent.

For a nested local partition, this helper updates the parent's
effective_cpus without changing subpartitions_cpus.

Is my understanding correct? Please correct me if I'm missing something.

Thanks,
Guopeng

> +static void __maybe_unused partition_update(struct cpuset *cs, int prs, struct cpumask *xcpus,
> + struct cpumask *excpus, struct tmpmasks *tmp)
> +{
> + struct cpuset *parent;
> +
> + lockdep_assert_cpuset_lock_held();
> + WARN_ON_ONCE(!cpuset_v2());
> + WARN_ON_ONCE(prs <= 0);
> +
> + parent = is_remote_partition(cs) ? NULL : parent_cs(cs);
> +
> + /*
> + * Only CPUs owned by the parent can be taken from or given back to
> + * it, the parent may have shrunk. A remote partition gets its CPUs
> + * from top_cpuset which owns all the CPUs.
> + */
> + if (parent) {
> + cpumask_and(tmp->addmask, tmp->addmask, parent->effective_xcpus);
> + cpumask_and(tmp->delmask, tmp->delmask, parent->effective_xcpus);
> + }
> + if (cpumask_empty(tmp->addmask) &&
> + cpumask_empty(tmp->delmask) &&
> + cpumask_equal(cs->effective_xcpus, excpus))
> + return;
> +
> + spin_lock_irq(&callback_lock);
> + partition_xcpus_add(prs, parent, tmp->addmask);
> + partition_xcpus_del(prs, parent, tmp->delmask);
> + /*
> + * Need to update effective_xcpus and exclusive_cpus now as
> + * update_sibling_cpumasks() called by the callers afterwards may
> + * iterate back to the same cs.
> + */
> + cpumask_copy(cs->effective_xcpus, excpus);
> + if (xcpus)
> + cpumask_copy(cs->exclusive_cpus, xcpus);
> + spin_unlock_irq(&callback_lock);
> + cpuset_force_rebuild();
> +}
> +
> /*
> * remote_partition_enable - Enable current cpuset as a remote partition root
> * @cs: the cpuset to update