From: Waiman Long <longman@redhat.com>
To: "Shaojie Sun" <sunshaojie@kylinos.cn>,
"Tejun Heo" <tj@kernel.org>, "Michal Koutný" <mkoutny@suse.com>,
"Ridong Chen" <ridong.chen@linux.dev>,
"Johannes Weiner" <hannes@cmpxchg.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup/cpuset: Drop redundant no-cpu check in partcmd_update with newmask
Date: Fri, 30 Oct 2026 15:29:34 -0400 [thread overview]
Message-ID: <6904bcf6-6a6a-46fe-83f3-09880d45873f@redhat.com> (raw)
In-Reply-To: <20261030131408.1054507-1-sunshaojie@kylinos.cn>
On 10/30/26 9:14 AM, Shaojie Sun wrote:
> update_parent_effective_cpumask() with a non-NULL newmask is only ever
> reached from partition_cpus_change(), and only after validate_partition()
> has checked the very same condition with the very same arguments:
>
> tasks_nocpu_error(parent_cs(cs), cs, trialcs->effective_xcpus)
>
> since newmask is exactly trialcs->effective_xcpus and both functions use
> parent_cs(cs) as the parent. cs, parent and cpu_active_mask cannot change
> in between either, as cpuset_mutex and cpu_read_lock are held for the
> whole operation. Hence
>
> nocpu = tasks_nocpu_error(parent, cs, newmask);
>
> is always false here and the block that turns a "nocpu" condition into
> PERR_NOCPUS is dead code. A new CPU list that would drain the parent is
> fully handled by validate_partition(), which routes the write to
> partcmd_invalidate and hands the partition's CPUs back to the parent.
>
> The "!adding || !cpumask_intersects(addmask, cpu_active_mask)" test that
> guards the block does not change this: the block can only be entered when
> nocpu is true, and that never happens here.
>
> Drop the redundant check and the dead PERR_NOCPUS block, and leave a
> comment pointing at where the "parent could be drained" case is handled.
> The empty-newmask check in the same branch is left alone: it validates
> the newmask argument of this function, while what is removed here is a
> decision that belongs to validate_partition().
>
> No functional change.
>
> Signed-off-by: Shaojie Sun <sunshaojie@kylinos.cn>
> ---
> kernel/cgroup/cpuset.c | 20 +++++---------------
> 1 file changed, 5 insertions(+), 15 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 3219f927c35e..c7b3a734cda8 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -2016,9 +2016,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> goto write_error;
> }
>
> - /* Check newmask whether cpus are available for parent/cs */
> - nocpu = tasks_nocpu_error(parent, cs, newmask);
> -
> /*
> * partcmd_update with newmask:
> *
> @@ -2033,6 +2030,11 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> * For invalid partition:
> * delmask = newmask & parent->effective_xcpus
> * The partition may become valid soon.
> + *
> + * Note that the no-cpu check is not repeated here:
> + * validate_partition() has already evaluated
> + * tasks_nocpu_error() with this very mask, and a failing
> + * write is routed to partcmd_invalidate instead.
> */
> if (is_partition_invalid(cs)) {
> adding = false;
> @@ -2056,18 +2058,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> cpumask_and(tmp->new_cpus, tmp->delmask, cpu_active_mask);
> WARN_ON_ONCE(!cpumask_subset(tmp->new_cpus, parent->effective_cpus));
> }
> -
> - /*
> - * Make partition invalid if parent's effective_cpus could
> - * become empty and there are tasks in the parent.
> - */
> - if (nocpu && (!adding ||
> - !cpumask_intersects(tmp->addmask, cpu_active_mask))) {
> - part_error = PERR_NOCPUS;
> - deleting = false;
> - adding = cpumask_and(tmp->addmask,
> - cs->effective_xcpus, parent->effective_xcpus);
> - }
> } else {
> /*
> * partcmd_update w/o newmask
LKTM
Reviewed-by: Waiman Long <longman@redhat.com>
next prev parent reply other threads:[~2026-10-30 19:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 13:14 Shaojie Sun
2026-10-30 19:29 ` Waiman Long [this message]
2026-10-31 1:38 ` Tejun Heo
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=6904bcf6-6a6a-46fe-83f3-09880d45873f@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=ridong.chen@linux.dev \
--cc=sunshaojie@kylinos.cn \
--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
all inboxes | Powered by JetHome®