From: Waiman Long <longman@redhat.com>
To: "Ridong Chen" <ridong.chen@linux.dev>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Shuah Khan" <shuah@kernel.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Guopeng Zhang <guopeng.zhang@linux.dev>,
Waiman Long <longman@redhat.com>
Subject: [PATCH-next v2 09/10] cgroup/cpuset: Relocate compute_*effective_cpumask() and compute_effective_nodemask()
Date: Fri, 23 Oct 2026 16:00:35 -0400 [thread overview]
Message-ID: <20261023200036.60560-10-longman@redhat.com> (raw)
In-Reply-To: <20261023200036.60560-1-longman@redhat.com>
Relocate compute_partition_effective_cpumask(),
compute_effective_cpumask(), and compute_effective_nodemask() together so
that compute_effective_cpumask() and compute_partition_effective_cpumask()
can be further integrated together. There is no functional change.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/cgroup/cpuset.c | 212 ++++++++++++++++++++---------------------
1 file changed, 106 insertions(+), 106 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 03c666f658e4..f9ba711e1e1a 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1135,43 +1135,6 @@ void cpuset_update_tasks_cpumask(struct cpuset *cs, struct cpumask *new_cpus)
css_task_iter_end(&it);
}
-/**
- * compute_effective_cpumask - Compute the effective cpumask of the cpuset
- * @new_cpus: the temp variable for the new effective_cpus mask
- * @cs: the cpuset the need to recompute the new effective_cpus mask
- * @parent: the parent cpuset
- *
- * For v2, the parent's effective_cpus is inherited if cpumask is empty.
- * The result is valid only if the given cpuset isn't a partition root.
- */
-static void compute_effective_cpumask(struct cpumask *new_cpus,
- struct cpuset *cs, struct cpuset *parent)
-{
- bool has_cpus;
-
- has_cpus = cpumask_and(new_cpus, cs->cpus_allowed, parent->effective_cpus);
- if (!has_cpus && is_in_v2_mode())
- cpumask_copy(new_cpus, parent->effective_cpus);
-}
-
-/**
- * compute_effective_nodemask - Compute the effective nodemask of the cpuset
- * @new_mems: the temp variable for the new effective_mems mask
- * @cs: the cpuset the need to recompute the new effective_mems mask
- * @parent: the parent cpuset
- *
- * For v2, the parent's effective_mems is inherited if nodemask is empty.
- */
-static void compute_effective_nodemask(nodemask_t *new_mems,
- struct cpuset *cs, struct cpuset *parent)
-{
- bool has_mems;
-
- has_mems = nodes_and(*new_mems, cs->mems_allowed, parent->effective_mems);
- if (!has_mems && is_in_v2_mode())
- nodes_copy(*new_mems, parent->effective_mems);
-}
-
/*
* Commands for update_parent_effective_cpumask
*/
@@ -1583,6 +1546,112 @@ static inline bool is_local_partition(struct cpuset *cs)
return is_partition_valid(cs) && !is_remote_partition(cs);
}
+/**
+ * compute_partition_effective_cpumask - compute effective_cpus for partition
+ * @cs: partition root cpuset
+ * @new_ecpus: previously computed effective_cpus to be updated
+ *
+ * Compute the effective_cpus of a partition root by scanning effective_xcpus
+ * of child partition roots and excluding their effective_xcpus.
+ *
+ * This has the side effect of invalidating valid child partition roots,
+ * if necessary. Since it is called from either cpuset_hotplug_update_tasks()
+ * or update_cpumasks_hier() where parent and children are modified
+ * successively, we don't need to call update_parent_effective_cpumask()
+ * and the child's effective_cpus will be updated in later iterations.
+ */
+static void compute_partition_effective_cpumask(struct cpuset *cs,
+ struct cpumask *new_ecpus)
+{
+ struct cgroup_subsys_state *css;
+ struct cpuset *child;
+ bool populated = partition_is_populated(cs, NULL);
+
+ WARN_ON_ONCE(!is_partition_valid(cs));
+
+ /*
+ * Check child partition roots to see if they should be invalidated
+ * when all the effective_cpus will be used up and cs is populated.
+ * It is better to sacrifice a child partition root than invalidating
+ * the whole subtree.
+ *
+ * Return early if the effective_cpus is already empty.
+ */
+ compute_excpus(cs, new_ecpus);
+ if (!cpumask_and(new_ecpus, new_ecpus, cpu_active_mask))
+ return;
+
+ rcu_read_lock();
+ cpuset_for_each_child(child, css, cs) {
+ if (!is_partition_valid(child))
+ continue;
+
+ /*
+ * There shouldn't be a remote partition underneath another
+ * partition root.
+ */
+ WARN_ON_ONCE(is_remote_partition(child));
+ if (populated && cpumask_subset(new_ecpus, child->effective_xcpus)) {
+ int old_prs = child->partition_root_state;
+ int parent_prs = cs->partition_root_state;
+
+ /*
+ * Invalidate child partition and update isolated_cpus
+ * if necessary.
+ */
+ spin_lock_irq(&callback_lock);
+ WRITE_ONCE(child->prs_err, PERR_NOCPUS);
+ if ((old_prs == PRS_ISOLATED) && (parent_prs == PRS_ROOT))
+ isolated_cpus_update(old_prs, parent_prs,
+ child->effective_xcpus);
+ child->partition_root_state = -old_prs;
+ spin_unlock_irq(&callback_lock);
+ notify_partition_change(child, old_prs);
+ continue;
+ }
+ cpumask_andnot(new_ecpus, new_ecpus,
+ child->effective_xcpus);
+ }
+ rcu_read_unlock();
+}
+
+/**
+ * compute_effective_cpumask - Compute the effective cpumask of the cpuset
+ * @new_cpus: the temp variable for the new effective_cpus mask
+ * @cs: the cpuset the need to recompute the new effective_cpus mask
+ * @parent: the parent cpuset
+ *
+ * For v2, the parent's effective_cpus is inherited if cpumask is empty.
+ * The result is valid only if the given cpuset isn't a partition root.
+ */
+static void compute_effective_cpumask(struct cpumask *new_cpus,
+ struct cpuset *cs, struct cpuset *parent)
+{
+ bool has_cpus;
+
+ has_cpus = cpumask_and(new_cpus, cs->cpus_allowed, parent->effective_cpus);
+ if (!has_cpus && is_in_v2_mode())
+ cpumask_copy(new_cpus, parent->effective_cpus);
+}
+
+/**
+ * compute_effective_nodemask - Compute the effective nodemask of the cpuset
+ * @new_mems: the temp variable for the new effective_mems mask
+ * @cs: the cpuset the need to recompute the new effective_mems mask
+ * @parent: the parent cpuset
+ *
+ * For v2, the parent's effective_mems is inherited if nodemask is empty.
+ */
+static void compute_effective_nodemask(nodemask_t *new_mems,
+ struct cpuset *cs, struct cpuset *parent)
+{
+ bool has_mems;
+
+ has_mems = nodes_and(*new_mems, cs->mems_allowed, parent->effective_mems);
+ if (!has_mems && is_in_v2_mode())
+ nodes_copy(*new_mems, parent->effective_mems);
+}
+
/*
* remote_partition_enable - Enable current cpuset as a remote partition root
* @cs: the cpuset to update
@@ -2084,75 +2153,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
return 0;
}
-/**
- * compute_partition_effective_cpumask - compute effective_cpus for partition
- * @cs: partition root cpuset
- * @new_ecpus: previously computed effective_cpus to be updated
- *
- * Compute the effective_cpus of a partition root by scanning effective_xcpus
- * of child partition roots and excluding their effective_xcpus.
- *
- * This has the side effect of invalidating valid child partition roots,
- * if necessary. Since it is called from either cpuset_hotplug_update_tasks()
- * or update_cpumasks_hier() where parent and children are modified
- * successively, we don't need to call update_parent_effective_cpumask()
- * and the child's effective_cpus will be updated in later iterations.
- */
-static void compute_partition_effective_cpumask(struct cpuset *cs,
- struct cpumask *new_ecpus)
-{
- struct cgroup_subsys_state *css;
- struct cpuset *child;
- bool populated = partition_is_populated(cs, NULL);
-
- WARN_ON_ONCE(!is_partition_valid(cs));
-
- /*
- * Check child partition roots to see if they should be invalidated
- * when all the effective_cpus will be used up and cs is populated.
- * It is better to sacrifice a child partition root than invalidating
- * the whole subtree.
- *
- * Return early if the effective_cpus is already empty.
- */
- compute_excpus(cs, new_ecpus);
- if (!cpumask_and(new_ecpus, new_ecpus, cpu_active_mask))
- return;
-
- rcu_read_lock();
- cpuset_for_each_child(child, css, cs) {
- if (!is_partition_valid(child))
- continue;
-
- /*
- * There shouldn't be a remote partition underneath another
- * partition root.
- */
- WARN_ON_ONCE(is_remote_partition(child));
- if (populated && cpumask_subset(new_ecpus, child->effective_xcpus)) {
- int old_prs = child->partition_root_state;
- int parent_prs = cs->partition_root_state;
-
- /*
- * Invalidate child partition and update isolated_cpus
- * if necessary.
- */
- spin_lock_irq(&callback_lock);
- WRITE_ONCE(child->prs_err, PERR_NOCPUS);
- if ((old_prs == PRS_ISOLATED) && (parent_prs == PRS_ROOT))
- isolated_cpus_update(old_prs, parent_prs,
- child->effective_xcpus);
- child->partition_root_state = -old_prs;
- spin_unlock_irq(&callback_lock);
- notify_partition_change(child, old_prs);
- continue;
- }
- cpumask_andnot(new_ecpus, new_ecpus,
- child->effective_xcpus);
- }
- rcu_read_unlock();
-}
-
/*
* furthest isolated_ancestor - Return furthest isolated partition root ancestor available
* @cs: the current cpuset
--
2.56.0
next prev parent reply other threads:[~2026-10-23 20:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 20:00 [PATCH-next v2 00/10] cgroup/cpuset: Miscellaneous bug fixes & cleanup Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 01/10] cgroup/cpuset: Find furthest isolated ancestor for invalidated isolated partition Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 02/10] cgroup/cpuset: Properly compute effective xcpus in update_parent_effective_cpumask() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 03/10] cgroup/cpuset: Fix incorrect effective_cpus bug in update_cpumasks_hier() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 04/10] cgroup/cpuset: Minor fixes to prstate_housekeeping_conflict() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 05/10] selftests/cgroup: Check for a single range nohz_full CPUs before running test matrix Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 06/10] cgroup/cpuset: Prevent recursive call of remote_cpus_update() via update_cpumasks_hier() Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 07/10] cgroup/cpuset: Make sure compute_partition_effective_cpumask() is only called for valid partition Waiman Long
2026-10-23 20:00 ` [PATCH-next v2 08/10] cgroup/cpuset: Update isolated_cpus if necessary in compute_partition_effective_cpumask() Waiman Long
2026-10-23 20:00 ` Waiman Long [this message]
2026-10-23 20:00 ` [PATCH-next v2 10/10] cgroup/cpuset: Integrate compute_partition_effective_cpumask() into compute_effective_cpumask() Waiman Long
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=20261023200036.60560-10-longman@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=guopeng.zhang@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=ridong.chen@linux.dev \
--cc=shuah@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
all inboxes | Powered by JetHome®