Linux cgroups development
 help / color / mirror / Atom feed
From: Waiman Long <llong@redhat.com>
To: Chen Ridong <chenridong@huaweicloud.com>,
	tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	daniel.m.jordan@oracle.com, lujialin4@huawei.com,
	chenridong@huawei.com
Subject: Re: [PATCH -next] cpuset: Remove unnecessary checks in rebuild_sched_domains_locked
Date: Tue, 25 Nov 2025 13:16:34 -0500	[thread overview]
Message-ID: <27ed2c0b-7b00-4be0-a134-3c370cf85d8e@redhat.com> (raw)
In-Reply-To: <20251118083643.1363020-1-chenridong@huaweicloud.com>

On 11/18/25 3:36 AM, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> Commit 406100f3da08 ("cpuset: fix race between hotplug work and later CPU
> offline")added a check for empty effective_cpus in partitions for cgroup
> v2. However, thischeck did not account for remote partitions, which were
> introduced later.
>
> After commit 2125c0034c5d ("cgroup/cpuset: Make cpuset hotplug processing
> synchronous"),cgroup v2's cpuset hotplug handling is now synchronous. This
> eliminates the race condition with subsequent CPU offline operations that
> the original check aimed to fix.
That is true. The original asynchronous cpuset_hotplug_workfn() is 
called after the hotplug operation finishes. So cpuset can be in a state 
where cpu_active_mask was updated, but not the effective cpumasks in 
cpuset.
>
> Instead of extending the check to support remote partitions, this patch
> removes the redundant partition effective_cpus check. Additionally, it adds
> a check and warningto verify that all generated sched domains consist of
"warningto" => "warning to"
> active CPUs, preventing partition_sched_domains from being invoked with
> offline CPUs.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
>   kernel/cgroup/cpuset.c | 29 ++++++-----------------------
>   1 file changed, 6 insertions(+), 23 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index daf813386260..1ac58e3f26b4 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1084,11 +1084,10 @@ void dl_rebuild_rd_accounting(void)
>    */
>   void rebuild_sched_domains_locked(void)
>   {
> -	struct cgroup_subsys_state *pos_css;
>   	struct sched_domain_attr *attr;
>   	cpumask_var_t *doms;
> -	struct cpuset *cs;
>   	int ndoms;
> +	int i;
>   
>   	lockdep_assert_cpus_held();
>   	lockdep_assert_held(&cpuset_mutex);

In fact, the following code and the comments above in 
rebuild_sched_domains_locked() are also no longer relevant. So you may 
remove them as well.

         if (!top_cpuset.nr_subparts_cpus &&
             !cpumask_equal(top_cpuset.effective_cpus, cpu_active_mask))
                 return;

> @@ -1107,30 +1106,14 @@ void rebuild_sched_domains_locked(void)
>   	    !cpumask_equal(top_cpuset.effective_cpus, cpu_active_mask))
>   		return;
>   
> -	/*
> -	 * With subpartition CPUs, however, the effective CPUs of a partition
> -	 * root should be only a subset of the active CPUs.  Since a CPU in any
> -	 * partition root could be offlined, all must be checked.
> -	 */
> -	if (!cpumask_empty(subpartitions_cpus)) {
> -		rcu_read_lock();
> -		cpuset_for_each_descendant_pre(cs, pos_css, &top_cpuset) {
> -			if (!is_partition_valid(cs)) {
> -				pos_css = css_rightmost_descendant(pos_css);
> -				continue;
> -			}
> -			if (!cpumask_subset(cs->effective_cpus,
> -					    cpu_active_mask)) {
> -				rcu_read_unlock();
> -				return;
> -			}
> -		}
> -		rcu_read_unlock();
> -	}
> -
>   	/* Generate domain masks and attrs */
>   	ndoms = generate_sched_domains(&doms, &attr);
>   
> +	for (i = 0; i < ndoms; ++i) {
> +		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
> +			return;
> +	}
> +

If it is not clear about the purpose of the WARN_ON_ONCE() call, we 
should add a comment to explain that cpu_active_mask will not be out of 
sync with cpuset's effective cpumasks. So the warning should not be 
triggered.

Cheers,
Longman

>   	/* Have scheduler rebuild the domains */
>   	partition_sched_domains(ndoms, doms, attr);
>   }


  parent reply	other threads:[~2025-11-25 18:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18  8:36 [PATCH -next] cpuset: Remove unnecessary checks in rebuild_sched_domains_locked Chen Ridong
2025-11-25  0:50 ` Chen Ridong
2025-11-25 18:16 ` Waiman Long [this message]
2025-11-26  1:01   ` Chen Ridong
2025-11-26  2:33     ` Waiman Long
2025-11-26  3:17       ` Chen Ridong
2025-11-26  3:26         ` Waiman Long
2025-11-26  3:34           ` Chen Ridong

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=27ed2c0b-7b00-4be0-a134-3c370cf85d8e@redhat.com \
    --to=llong@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@huawei.com \
    --cc=chenridong@huaweicloud.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lujialin4@huawei.com \
    --cc=mkoutny@suse.com \
    --cc=tj@kernel.org \
    /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