Re: [PATCH v6 03/12] cpuset: introduce partition_update()
From: Guopeng Zhang
Date: Fri Dec 04 2026 - 23:21:04 EST
在 2026/11/29 10:44, 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 | 53 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index cfad92cf89d6..7efec768f212 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1825,6 +1825,59 @@ 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 CPUs in tmp->addmask are taken
> + * from the effective_cpus of the parent, or of top_cpuset for a remote
> + * partition, and the CPUs in tmp->delmask are given back to it. If that
> + * parent is top_cpuset, subpartitions_cpus is updated accordingly.
> + */
> +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
Reviewed-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
Thanks,
Guopeng