mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: Waiman Long <longman@redhat.com>, Ridong Chen <ridong.chen@linux.dev>
Cc: "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Guopeng Zhang" <zhangguopeng@kylinos.cn>
Subject: [PATCH v4 1/7] cgroup/cpuset: Factor out child partition validation
Date: Thu, 10 Sep 2026 17:45:40 +0800	[thread overview]
Message-ID: <20260910094546.5852-2-guopeng.zhang@linux.dev> (raw)
In-Reply-To: <20260910094546.5852-1-guopeng.zhang@linux.dev>

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

compute_partition_effective_cpumask() checks whether each valid child
partition remains covered by the parent exclusive CPU mask and whether it
would consume all remaining active CPUs of a populated parent.

Factor these two checks into cs_partition_error() so the same rules can be
reused when evaluating a proposed parent configuration. This is a
preparatory refactoring with no intended functional change.

Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
 kernel/cgroup/cpuset.c | 47 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 8f24171b6055..a2514fcb1144 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2085,6 +2085,37 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
 	return 0;
 }
 
+/**
+ * cs_partition_error - Return a cpuset partition invalidation error
+ * @cs: Partition being evaluated
+ * @parent_xcpus: Parent's complete effective exclusive CPU mask, including
+ *                offline CPUs
+ * @remaining_ecpus: Parent's active effective CPUs remaining before @cs is
+ *                   evaluated
+ * @parent_populated: Whether the parent partition contains tasks
+ *
+ * @remaining_ecpus may still contain active CPUs assigned to @cs and to
+ * children that have not yet been evaluated. It excludes only CPUs assigned
+ * to previously evaluated children that remain valid.
+ *
+ * Return: The error that would invalidate @cs, or PERR_NONE
+ */
+static enum prs_errcode
+cs_partition_error(struct cpuset *cs,
+		   const struct cpumask *parent_xcpus,
+		   const struct cpumask *remaining_ecpus,
+		   bool parent_populated)
+{
+	if (!cpumask_subset(cs->effective_xcpus, parent_xcpus))
+		return PERR_INVCPUS;
+
+	if (parent_populated &&
+	    cpumask_subset(remaining_ecpus, cs->effective_xcpus))
+		return PERR_NOCPUS;
+
+	return PERR_NONE;
+}
+
 /**
  * compute_partition_effective_cpumask - compute effective_cpus for partition
  * @cs: partition root cpuset
@@ -2121,6 +2152,8 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
 
 	rcu_read_lock();
 	cpuset_for_each_child(child, css, cs) {
+		enum prs_errcode child_err;
+
 		if (!is_partition_valid(child))
 			continue;
 
@@ -2129,15 +2162,11 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
 		 * partition root.
 		 */
 		WARN_ON_ONCE(is_remote_partition(child));
-		WRITE_ONCE(child->prs_err, 0);
-		if (!cpumask_subset(child->effective_xcpus,
-				    cs->effective_xcpus))
-			WRITE_ONCE(child->prs_err, PERR_INVCPUS);
-		else if (populated &&
-			 cpumask_subset(new_ecpus, child->effective_xcpus))
-			WRITE_ONCE(child->prs_err, PERR_NOCPUS);
-
-		if (child->prs_err) {
+		child_err = cs_partition_error(child, cs->effective_xcpus,
+					       new_ecpus, populated);
+		WRITE_ONCE(child->prs_err, child_err);
+
+		if (child_err) {
 			int old_prs = child->partition_root_state;
 
 			/*
-- 
2.43.0


  reply	other threads:[~2026-09-10  9:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  9:45 [PATCH v4 0/7] cgroup/cpuset: Fix partition transitions and invalidation Guopeng Zhang
2026-09-10  9:45 ` Guopeng Zhang [this message]
2026-09-10  9:45 ` [PATCH v4 2/7] cgroup/cpuset: Account for child CPU ownership in partition changes Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 3/7] cgroup/cpuset: Release CPUs when type-change validation fails Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 4/7] cgroup/cpuset: Fix child invalidation after parent CPU changes Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 5/7] cgroup/cpuset: Fix isolation accounting on propagated invalidation Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 6/7] cgroup/cpuset: Publish cpus_allowed before partition updates Guopeng Zhang
2026-09-10  9:45 ` [PATCH v4 7/7] cgroup/cpuset: Publish exclusive_cpus " Guopeng Zhang

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=20260910094546.5852-2-guopeng.zhang@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®