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 01/12] cpuset: introduce partition_enable()
Date: Wed, 18 Nov 2026 17:21:53 +0800	[thread overview]
Message-ID: <58a7a7fa-500d-467a-840f-fedb59a73e52@linux.dev> (raw)
In-Reply-To: <20261114083124.1340140-2-ridong.chen@linux.dev>



在 2026/11/14 16:31, Ridong Chen 写道:
> From: Ridong Chen <chenridong@xiaomi.com>
> 
> 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 the isolation state of the CPUs in @new_excpus is updated. The
> caller passes the CPUs used by the partition itself, as the CPUs of its
> valid child partitions keep their own state.
> 
> 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: Ridong Chen <chenridong@xiaomi.com>
> ---
>  kernel/cgroup/cpuset.c | 56 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 7e374210c123..860cb7ea3efb 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1702,6 +1702,62 @@ 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, or the
> + *              CPUs whose isolation state changes when switching between
> + *              root and isolated
> + *
> + * Transitions a cpuset to a partition root, only for v2.
> + * It also supports the transition between root and isolated partition.
> + */
> +static void __maybe_unused partition_enable(struct cpuset *cs, struct cpuset *parent,
> +					    int new_prs, struct cpumask *new_excpus)
> +{
> +	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.
> +		 * @new_excpus holds the CPUs whose isolation state changes.
> +		 */
> +		isolated_cpus_update(new_prs, new_excpus);
> +	} 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);
> +}
> +

Hi Ridong,

I haven't found any functional issues with this patch, and I think the overall direction of the refactoring is good. I just had a thought of my own and wanted to hear what you think.

Currently, partition_enable() handles two different operations: enabling a partition and switching a valid partition between root and isolated. As a result, new_excpus has two different meanings depending on old_prs. Looking at the callers introduced in patches 4/12, 8/12, and 11/12, they all use partition_enable() to enable a previously non-valid partition. None of them seems to need the old_prs > 0 branch.

I understand that this branch may be intended for the follow-up refactoring of update_prstate(), since partition_switch() introduced in v4 also calls partition_enable().

However, could we consider keeping partition_enable() focused solely on enabling partitions, so that new_excpus always has a single meaning? The root/isolated transition could remain in update_prstate() for now and be handled separately when update_prstate() is simplified later, perhaps through partition_switch(), or by introducing another function such as partition_set_isolation(), or some other more suitable approach.

If I've misunderstood anything or overlooked a reason for keeping these two operations together, please let me know.

Thanks, and all the best!

Best regards,
Guopeng

>  /*
>   * remote_partition_enable - Enable current cpuset as a remote partition root
>   * @cs: the cpuset to update


  reply	other threads:[~2026-11-18  9:22 UTC|newest]

Thread overview: 14+ 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 [this message]
2026-11-14  8:31 ` [PATCH v5 02/12] cpuset: introduce partition_disable() Ridong Chen
2026-11-14  8:31 ` [PATCH v5 03/12] cpuset: introduce partition_update() Ridong Chen
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=58a7a7fa-500d-467a-840f-fedb59a73e52@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