Linux cgroups development
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: "Ridong Chen" <ridong.chen@linux.dev>,
	"Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>
Cc: Guopeng Zhang <zhangguopeng@kylinos.cn>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [PATCH v5 03/12] cpuset: introduce partition_update()
Date: Tue, 24 Nov 2026 18:06:39 +0800	[thread overview]
Message-ID: <833af431-3580-4a7d-987f-30d8d60893a3@linux.dev> (raw)
In-Reply-To: <20261114083124.1340140-4-ridong.chen@linux.dev>



在 2026/11/14 16:31, Ridong Chen 写道:
> From: Ridong Chen <chenridong@xiaomi.com>
> 
> 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@xiaomi.com>
> ---
>  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


  reply	other threads:[~2026-11-24 10:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  8:31 [PATCH v5 00/12] cpuset: rework local partition logic Ridong Chen
2026-11-14  8:31 ` [PATCH v5 01/12] cpuset: introduce partition_enable() Ridong Chen
2026-11-18  9:21   ` Guopeng Zhang
2026-11-18 10:59     ` Ridong Chen
2026-11-14  8:31 ` [PATCH v5 02/12] cpuset: introduce partition_disable() Ridong Chen
2026-11-24 10:04   ` Guopeng Zhang
2026-11-14  8:31 ` [PATCH v5 03/12] cpuset: introduce partition_update() Ridong Chen
2026-11-24 10:06   ` Guopeng Zhang [this message]
2026-11-14  8:31 ` [PATCH v5 04/12] cpuset: use partition_enable() for remote partition enablement Ridong Chen
2026-11-14  8:31 ` [PATCH v5 05/12] cpuset: use partition_disable() for remote partition disablement Ridong Chen
2026-11-14  8:31 ` [PATCH v5 06/12] cpuset: use partition_update() for remote partition update Ridong Chen
2026-11-14  8:31 ` [PATCH v5 07/12] cpuset: introduce validate_local_partition() Ridong Chen
2026-11-14  8:31 ` [PATCH v5 08/12] cpuset: introduce local_partition_enable() Ridong Chen
2026-11-14  8:31 ` [PATCH v5 09/12] cpuset: use partition_disable() for local partition disablement Ridong Chen
2026-11-14  8:31 ` [PATCH v5 10/12] cpuset: use partition_disable() to invalidate local partition Ridong Chen
2026-11-14  8:31 ` [PATCH v5 11/12] cpuset: introduce local_partition_update() Ridong Chen
2026-11-14  8:31 ` [PATCH v5 12/12] cpuset: remove update_parent_effective_cpumask Ridong Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=833af431-3580-4a7d-987f-30d8d60893a3@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@xiaomi.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=ridong.chen@linux.dev \
    --cc=tj@kernel.org \
    --cc=zhangguopeng@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox