cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Ridong <chenridong@huaweicloud.com>
To: longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	lujialin4@huawei.com, chenridong@huawei.com
Subject: [PATCH -next RFC 06/11] cpuset: introduce cpus_excl_conflict and mems_excl_conflict helpers
Date: Thu, 28 Aug 2025 12:56:26 +0000	[thread overview]
Message-ID: <20250828125631.1978176-7-chenridong@huaweicloud.com> (raw)
In-Reply-To: <20250828125631.1978176-1-chenridong@huaweicloud.com>

From: Chen Ridong <chenridong@huawei.com>

This patch adds cpus_excl_conflict() and mems_excl_conflict() helper
functions to improve code readability and maintainability. The exclusive
conflict checking follows these rules:

1. If either cpuset has the 'exclusive' flag set, their user_xcpus must
   not have any overlap.
2. If both cpusets are non-exclusive, their 'cpuset.cpus.exclusive' values
   must not intersect.
3. The 'cpuset.cpus' of one cpuset must not form a subset of another
   cpuset's 'cpuset.cpus.exclusive'.

Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
 kernel/cgroup/cpuset.c | 62 ++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 5dd1e9552000..5cfc53fe717c 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -584,6 +584,35 @@ static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
 	return true;
 }
 
+static inline bool cpus_excl_conflict(struct cpuset *cs1, struct cpuset *cs2)
+{
+	/* One is exclusive, they must be exclusive */
+	if (is_cpu_exclusive(cs1) || is_cpu_exclusive(cs2))
+		return !cpusets_are_exclusive(cs1, cs2);
+
+	/* Exclusive_cpus can not have intersects*/
+	if (cpumask_intersects(cs1->exclusive_cpus, cs2->exclusive_cpus))
+		return true;
+
+	/* One cpus_allowed can not be a subset of another's cpuset.effective_cpus */
+	if (!cpumask_empty(cs1->cpus_allowed) &&
+	    cpumask_subset(cs1->cpus_allowed, cs2->exclusive_cpus))
+		return true;
+
+	if (!cpumask_empty(cs2->cpus_allowed) &&
+	    cpumask_subset(cs2->cpus_allowed, cs1->exclusive_cpus))
+		return true;
+
+	return false;
+}
+
+static inline bool mems_excl_conflict(struct cpuset *cs1, struct cpuset *cs2)
+{
+	if ((is_mem_exclusive(cs1) || is_mem_exclusive(cs2)))
+		return nodes_intersects(cs1->mems_allowed, cs2->mems_allowed);
+	return false;
+}
+
 /*
  * validate_change() - Used to validate that any proposed cpuset change
  *		       follows the structural rules for cpusets.
@@ -665,38 +694,11 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
 	 */
 	ret = -EINVAL;
 	cpuset_for_each_child(c, css, par) {
-		bool txset, cxset;	/* Are exclusive_cpus set? */
-
 		if (c == cur)
 			continue;
-
-		txset = !cpumask_empty(trial->exclusive_cpus);
-		cxset = !cpumask_empty(c->exclusive_cpus);
-		if (is_cpu_exclusive(trial) || is_cpu_exclusive(c) ||
-		    (txset && cxset)) {
-			if (!cpusets_are_exclusive(trial, c))
-				goto out;
-		} else if (txset || cxset) {
-			struct cpumask *xcpus, *acpus;
-
-			/*
-			 * When just one of the exclusive_cpus's is set,
-			 * cpus_allowed of the other cpuset, if set, cannot be
-			 * a subset of it or none of those CPUs will be
-			 * available if these exclusive CPUs are activated.
-			 */
-			if (txset) {
-				xcpus = trial->exclusive_cpus;
-				acpus = c->cpus_allowed;
-			} else {
-				xcpus = c->exclusive_cpus;
-				acpus = trial->cpus_allowed;
-			}
-			if (!cpumask_empty(acpus) && cpumask_subset(acpus, xcpus))
-				goto out;
-		}
-		if ((is_mem_exclusive(trial) || is_mem_exclusive(c)) &&
-		    nodes_intersects(trial->mems_allowed, c->mems_allowed))
+		if (cpus_excl_conflict(trial, c))
+			goto out;
+		if (mems_excl_conflict(trial, c))
 			goto out;
 	}
 
-- 
2.34.1


  parent reply	other threads:[~2025-08-28 13:11 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28 12:56 [PATCH -next RFC 00/11] Refactor cpus mask setting Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 01/11] cpuset: move the root cpuset write check earlier Chen Ridong
2025-08-29 19:21   ` Waiman Long
2025-08-30  1:11     ` Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 02/11] cpuset: remove unused assignment to trialcs->partition_root_state Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 03/11] cpuset: change return type of is_partition_[in]valid to bool Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 04/11] cpuset: Refactor exclusive CPU mask computation logic Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 05/11] cpuset: refactor CPU mask buffer parsing logic Chen Ridong
2025-08-28 12:56 ` Chen Ridong [this message]
2025-08-29 19:29   ` [PATCH -next RFC 06/11] cpuset: introduce cpus_excl_conflict and mems_excl_conflict helpers Waiman Long
2025-08-30  1:27     ` Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 07/11] cpuset: refactor out invalidate_cs_partition Chen Ridong
2025-08-29 19:56   ` Waiman Long
2025-08-30  1:33     ` Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 08/11] cpuset: refactor acpus_validate_change Chen Ridong
2025-08-29 20:12   ` Waiman Long
2025-08-30  1:42     ` Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 09/11] cpuset: refactor partition_cpus_change Chen Ridong
2025-08-29 20:32   ` Waiman Long
2025-08-30  2:01     ` Chen Ridong
2025-09-02 13:30       ` Waiman Long
2025-09-03  0:51         ` Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 10/11] cpuset: use parse_cpulist for setting cpus.exclusive Chen Ridong
2025-08-28 12:56 ` [PATCH -next RFC 11/11] cpuset: use partition_cpus_change for setting exclusive cpus 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=20250828125631.1978176-7-chenridong@huaweicloud.com \
    --to=chenridong@huaweicloud.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@huawei.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --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;
as well as URLs for NNTP newsgroup(s).