All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: "Guopeng Zhang" <guopeng.zhang@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 02/12] cpuset: introduce partition_disable()
Date: Wed, 25 Nov 2026 15:47:33 +0800	[thread overview]
Message-ID: <5e5c33c4-221d-4e52-b2f0-9dcc8b7935ef@linux.dev> (raw)
In-Reply-To: <71e4954b-b50f-455f-9f5c-5e053ccd6870@linux.dev>



On 11/24/2026 6:04 PM, Guopeng Zhang wrote:
> 
> 
> 在 2026/11/14 16:31, Ridong Chen 写道:
>> From: Ridong Chen <chenridong@xiaomi.com>
>>
>> Add partition_disable() to consolidate updates to key cpuset structures
>> during partition disablement, including:
>> 1. remote_partition
>> 2. effective_xcpus
>> 3. partition_root_state
>> 4. prs_err
>>
>> Key operations performed:
>> 1. Cleaning up remote_partition
>> 2. Removing exclusive CPUs via partition_xcpus_del()
>> 3. Recomputing effective exclusive CPUs mask
>> 4. Updating partition state and error status
>> 5. Triggering required scheduler domain rebuilds
>> 6. Sending partition change notifications
>> 7. Propagating the change of the parent's effective_cpus
>>
>> Only the CPUs actually granted by the parent are given back, as the
>> parent may have shrunk. An invalid partition, or a partition under an
>> invalid parent, has already given back its exclusive CPUs, so there is
>> nothing to delete. A remote partition gets its CPUs from top_cpuset,
>> which owns all the CPUs.
>>
>> The parent is derived from @cs, top_cpuset for a remote partition.
>> When a valid partition gives back its CPUs, the change of the parent's
>> effective_cpus is propagated to the tasks of the parent and to its
>> other children. A member or an invalid partition only has its state
>> updated, so that all the callers can call partition_disable()
>> directly.
>>
>> Signed-off-by: Ridong Chen <chenridong@xiaomi.com>
>> ---
>>   kernel/cgroup/cpuset.c | 66 ++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 66 insertions(+)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 860cb7ea3efb..12bdcaeb8ae5 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -1758,6 +1758,72 @@ static void __maybe_unused partition_enable(struct cpuset *cs, struct cpuset *pa
>>   	notify_partition_change(cs, old_prs);
>>   }
>>   
>> +/**
>> + * partition_disable - Disable partition root state for a cpuset
>> + * @cs: The cpuset to disable partition for
>> + * @new_prs: New partition root state (should be non-positive)
>> + * @prs_err: Error code to set if disabling due to validation failure
>> + * @tmp: Temporary masks
>> + *
>> + * A valid partition gives its CPUs back to its parent, or to top_cpuset
>> + * for a remote partition, and the change is propagated to the tasks and
>> + * the other children of the parent. A member or an invalid partition only
>> + * has its state updated. A valid partition under an invalid parent has
>> + * already given back its CPUs, so only the propagation is done.
>> + */
>> +static void __maybe_unused partition_disable(struct cpuset *cs, int new_prs,
>> +					     enum prs_errcode prs_err,
>> +					     struct tmpmasks *tmp)
>> +{
>> +	struct cpuset *parent = is_remote_partition(cs) ? NULL : parent_cs(cs);
>> +	int old_prs = cs->partition_root_state;
>> +
>> +	lockdep_assert_cpuset_lock_held();
>> +	WARN_ON_ONCE(new_prs > 0);
>> +	WARN_ON_ONCE(!cpuset_v2());
>> +	/*
>> +	 * When a CPU is offlined, top_cpuset may end up with no available CPUs,
>> +	 * which should clear subpartitions_cpus. We should not emit a warning for this
>> +	 * scenario: the hierarchy is updated from top to bottom, so subpartitions_cpus
>> +	 * may already be cleared when disabling a remote partition.
>> +	 */
>> +	if (!parent)
>> +		WARN_ON_ONCE(!cpumask_subset(cs->effective_xcpus, subpartitions_cpus) &&
>> +			     !cpumask_empty(subpartitions_cpus));
>> +
>> +	spin_lock_irq(&callback_lock);
>> +	cs->remote_partition = false;
>> +	/*
>> +	 * Disabling a partition should only delete exclusive CPUs, and only
>> +	 * those actually granted by the parent as the parent may have shrunk.
>> +	 * An invalid partition or an invalid parent has already given back
>> +	 * its exclusive CPUs, there is nothing to delete. A remote partition
>> +	 * gets its CPUs from top_cpuset which owns all the CPUs.
>> +	 */
>> +	if (is_partition_valid(cs) && (!parent || is_partition_valid(parent))) {
>> +		if (parent)
>> +			cpumask_and(cs->effective_xcpus, cs->effective_xcpus,
>> +				    parent->effective_xcpus);
>> +		partition_xcpus_del(old_prs, parent, cs->effective_xcpus);
>> +	}
>> +	/* effective_xcpus may need to be changed */
>> +	compute_excpus(cs, cs->effective_xcpus);
> 
> Hi Ridong,
> 
> Nit:
> 
> When cs->exclusive_cpus is empty, the current sequence is:
> compute_excpus()-> partition_state_update() -> reset_partition_data()-> effective_xcpus is cleared
> 
> In other words, the effective_xcpus just computed by compute_excpus() is immediately cleared by reset_partition_data().
> For this implicit exclusive CPU case, could we simply skip the computation?
> 
> if (!cpumask_empty(cs->exclusive_cpus))
>      compute_excpus(cs, cs->effective_xcpus);
> 
> If there are many sibling cpusets, the unnecessary scan could increase the time spent holding callback_lock. Of course, I haven't measured the actual overhead in practice.
> 

Good catch, thanks. new_prs is never positive here, so
reset_partition_data() always runs and clears effective_xcpus when
exclusive_cpus is empty. The sibling scan in compute_excpus() only
happens in that case, so it is wasted work under callback_lock. I'll
skip it in v6, with a comment on why.

> 
>> +	partition_state_update(cs, new_prs, prs_err);
>> +	spin_unlock_irq(&callback_lock);
>> +	cpuset_force_rebuild();
>> +	notify_partition_change(cs, old_prs);
>> +
>> +	/* A member or an invalid partition owns no CPU, nothing to propagate */
>> +	if (old_prs <= 0)
>> +		return;
>> +
>> +	/* Propagate changes in the parent's effective_cpus down the hierarchy */
>> +	if (!parent)
>> +		parent = &top_cpuset;
>> +	cpuset_update_tasks_cpumask(parent, tmp->new_cpus);
>> +	update_sibling_cpumasks(parent, cs, tmp);
>> +}
>> +
>>   /*
>>    * remote_partition_enable - Enable current cpuset as a remote partition root
>>    * @cs: the cpuset to update
> 

-- 
Best regards
Ridong


  reply	other threads:[~2026-11-25  7:47 UTC|newest]

Thread overview: 22+ 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-25  7:47     ` Ridong Chen [this message]
2026-11-14  8:31 ` [PATCH v5 03/12] cpuset: introduce partition_update() Ridong Chen
2026-11-24 10:06   ` Guopeng Zhang
2026-11-25  7:53     ` 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-24 10:34   ` Guopeng Zhang
2026-11-25  8:01     ` 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
2026-11-25  8:11 ` [PATCH v5 00/12] cpuset: rework local partition logic 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=5e5c33c4-221d-4e52-b2f0-9dcc8b7935ef@linux.dev \
    --to=ridong.chen@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@xiaomi.com \
    --cc=guopeng.zhang@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.