From: Ridong Chen <ridong.chen@linux.dev>
To: Hang Zhengyang <hang.zhengyang1010@gmail.com>,
Waiman Long <longman@redhat.com>, Tejun Heo <tj@kernel.org>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs
Date: Fri, 4 Dec 2026 11:35:23 +0800 [thread overview]
Message-ID: <f8bc8937-46d8-4f20-9c1b-460f579a5c6c@linux.dev> (raw)
In-Reply-To: <20261203195843.187930-2-hang.zhengyang1010@gmail.com>
On 12/4/2026 3:58 AM, Hang Zhengyang wrote:
> When a valid partition is switched between "root" and "isolated",
> update_prstate() updates isolated_cpus with the CPUs the partition has
> and then calls update_cpumasks_hier(). That recomputes the exclusive
> CPUs of the partition with compute_excpus(), which leaves out the
> exclusive CPUs of its siblings. If the partition has no
> cpuset.cpus.exclusive and a sibling has released exclusive CPUs since
> the partition was created, the partition gets them, but they are not
> taken from the parent, or from the top cpuset for a remote partition.
> update_cpumasks_hier() does that for child partitions, but not for the
> cpuset it starts from.
>
> Example on an 8-CPU system:
>
> cd /sys/fs/cgroup
> echo +cpuset > cgroup.subtree_control
> mkdir A1 B1
> echo 3-4 > A1/cpuset.cpus.exclusive
> echo 2-5 > B1/cpuset.cpus
> echo root > B1/cpuset.cpus.partition # B1: 2,5, root: 0-1,3-4,6-7
> echo > A1/cpuset.cpus.exclusive # B1 is still 2,5
> echo isolated > B1/cpuset.cpus.partition
>
> B1 now has CPUs 2-5, the root cpuset still has 0-1,3-4,6-7, and
> cpuset.cpus.isolated shows only 2,5. Switching from isolated to root
> instead makes two load balancing partitions overlap:
>
> WARNING: kernel/cgroup/cpuset.c:919 at rebuild_sched_domains_locked+0x4f8/0x890
>
> The same happens when the sibling was a partition root that became a
> member or was removed. A remote partition also triggers a warning in
> remote_partition_disable() when it becomes a member later.
>
> Take the new CPUs after the new state is set, as update_cpumasks_hier()
> does for child partitions: with update_parent_effective_cpumask() for a
> local partition and with remote_cpus_update() for a remote one. If the
> parent can't give them up, for example because it has tasks and no
> other CPUs, the partition becomes invalid.
>
> With this patch, B1 gets CPUs 2-5 in both directions, the root cpuset
> keeps 0-1,6-7, and cpuset.cpus.isolated shows 2-5 when B1 is isolated.
>
> Fixes: 2a3602030d80 ("cgroup/cpuset: Don't invalidate sibling partitions on cpuset.cpus conflict")
> Cc: stable@vger.kernel.org # v7.0+
> Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
> ---
> kernel/cgroup/cpuset.c | 41 +++++++++++++++++++++++++++++++----------
> 1 file changed, 31 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index aa82080dd1fa..bc5b0fa5199b 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1909,11 +1909,11 @@ static void remote_cpus_update(struct cpuset *cs, struct cpumask *xcpus,
> * update_prstate(). An error code may be returned and the caller will check
> * for error.
> *
> - * The partcmd_update command is used by update_cpumasks_hier() with newmask
> - * NULL and update_cpumask() with newmask set. The partcmd_invalidate is used
> - * by update_cpumask() with NULL newmask. In both cases, the callers won't
> - * check for error and so partition_root_state and prs_err will be updated
> - * directly.
> + * The partcmd_update command is used by update_cpumasks_hier() and
> + * update_prstate() with newmask NULL and update_cpumask() with newmask set.
> + * The partcmd_invalidate is used by update_cpumask() with NULL newmask. In
> + * both cases, the callers won't check for error and so partition_root_state
> + * and prs_err will be updated directly.
> */
> static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> struct cpumask *newmask,
> @@ -2081,6 +2081,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> * This can be called from:
> * 1) update_cpumasks_hier()
> * 2) cpuset_hotplug_update_tasks()
> + * 3) update_prstate()
> *
> * Check to see if it can be transitioned from valid to
> * invalid partition or vice versa.
> @@ -2213,9 +2214,8 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
> }
>
> /*
> - * For partcmd_update without newmask, it is being called from
> - * cpuset_handle_hotplug(). Update the load balance flag and
> - * scheduling domain accordingly.
> + * For partcmd_update without newmask, update the load balance flag
> + * and scheduling domain accordingly.
> */
> if ((cmd == partcmd_update) && !newmask)
> update_partition_sd_lb(cs, old_prs);
> @@ -3008,8 +3008,9 @@ static int update_prstate(struct cpuset *cs, int new_prs)
> ? PRS_ROOT : parent->partition_root_state;
>
> /*
> - * A change in load balance state only, no change in cpumasks.
> - * Need to update isolated_cpus.
> + * A change in load balance state. Need to update isolated_cpus.
> + * The cpumasks change only if a sibling has released exclusive
> + * CPUs, see below.
> */
> if (prstate_housekeeping_conflict(new_prs, parent_prs,
> cs->effective_xcpus, NULL))
> @@ -3077,6 +3078,26 @@ static int update_prstate(struct cpuset *cs, int new_prs)
> isolated_cpus_update(new_prs, tmpmask.new_cpus);
> spin_unlock_irq(&callback_lock);
>
> + /*
> + * A sibling may have released exclusive CPUs since cs became a
> + * partition. update_cpumasks_hier() recomputes the effective CPUs of
> + * cs and would include them, so take them from the parent, or from
> + * the top cpuset for a remote partition, first. This has to come
> + * after the new partition state is set so that the new CPUs are
> + * accounted with it. If the CPUs can't be given, cs becomes invalid.
> + */
> + if (isolcpus_updated) {
> + if (is_remote_partition(cs)) {
> + compute_excpus(cs, tmpmask.new_cpus);
> + if (!cpumask_equal(cs->effective_xcpus, tmpmask.new_cpus))
> + remote_cpus_update(cs, NULL, tmpmask.new_cpus,
> + &tmpmask);
> + } else {
> + update_parent_effective_cpumask(cs, partcmd_update,
> + NULL, &tmpmask);
> + }
> + }
> +
> /* Force update if partition is disabled & update effective_xcpus */
> update_cpumasks_hier(cs, &tmpmask, disable_partition);
>
The fix looks correct to me, but it also makes the code more
complex. update_prstate() now needs separate local and remote handling
for the switch, and update_parent_effective_cpumask() gets one more
caller with special cases to document.
This would be much simpler to fix on top of my rework series [1]. There
the switch is done in partition_switch(), and the fix is just calling
local_partition_update(), or remote_cpus_update() for a remote
partition, at its beginning. Those helpers already take the new CPUs
from the parent and invalidate the partition on failure.
[1] https://lore.kernel.org/cgroups/20261101114206.2434398-1-ridong.chen@linux.dev/
--
Best regards
Ridong
next prev parent reply other threads:[~2026-12-04 3:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:58 [PATCH 0/2] cgroup/cpuset: Fix partition switch after a sibling releases CPUs Hang Zhengyang
2026-12-03 19:58 ` [PATCH 1/2] cgroup/cpuset: Update the parent when a partition switch adds CPUs Hang Zhengyang
2026-12-04 3:35 ` Ridong Chen [this message]
2026-12-03 19:58 ` [PATCH 2/2] selftests/cgroup: Test partition switches after a sibling releases CPUs Hang Zhengyang
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=f8bc8937-46d8-4f20-9c1b-460f579a5c6c@linux.dev \
--to=ridong.chen@linux.dev \
--cc=cgroups@vger.kernel.org \
--cc=hang.zhengyang1010@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--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