[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170610140351.10703-2-tj@kernel.org>
Date: Sat, 10 Jun 2017 10:03:42 -0400
From: Tejun Heo <tj@...nel.org>
To: Li Zefan <lizefan@...wei.com>, hannes@...xchg.org,
peterz@...radead.org, mingo@...hat.com, longman@...hat.com
Cc: cgroups@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel-team@...com, pjt@...gle.com, luto@...capital.net,
efault@....de, torvalds@...ux-foundation.org,
Tejun Heo <tj@...nel.org>
Subject: [PATCH 01/10] cgroup: separate out cgroup_has_tasks()
Separate out cgroup_has_tasks() test from
cgroup_subtree_control_write(). This will be used by the following
changes.
This patch doesn't cause any behavior changes.
Signed-off-by: Tejun Heo <tj@...nel.org>
---
kernel/cgroup/cgroup.c | 49 +++++++++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 8d4e85eae42c..dcd120af4084 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -581,6 +581,30 @@ static bool css_set_populated(struct css_set *cset)
return !list_empty(&cset->tasks) || !list_empty(&cset->mg_tasks);
}
+static bool cgroup_has_tasks(struct cgroup *cgrp)
+{
+ struct cgrp_cset_link *link;
+ bool has_tasks = false;
+
+ /*
+ * Because namespaces pin csets too, @cgrp->cset_links
+ * might not be empty even when @cgrp is empty. Walk and
+ * verify each cset.
+ */
+ spin_lock_irq(&css_set_lock);
+
+ list_for_each_entry(link, &cgrp->cset_links, cset_link) {
+ if (css_set_populated(link->cset)) {
+ has_tasks = true;
+ break;
+ }
+ }
+
+ spin_unlock_irq(&css_set_lock);
+
+ return has_tasks;
+}
+
/**
* cgroup_update_populated - updated populated count of a cgroup
* @cgrp: the target cgroup
@@ -2886,28 +2910,9 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
* Except for the root, subtree_control must be zero for a cgroup
* with tasks so that child cgroups don't compete against tasks.
*/
- if (enable && cgroup_parent(cgrp)) {
- struct cgrp_cset_link *link;
-
- /*
- * Because namespaces pin csets too, @cgrp->cset_links
- * might not be empty even when @cgrp is empty. Walk and
- * verify each cset.
- */
- spin_lock_irq(&css_set_lock);
-
- ret = 0;
- list_for_each_entry(link, &cgrp->cset_links, cset_link) {
- if (css_set_populated(link->cset)) {
- ret = -EBUSY;
- break;
- }
- }
-
- spin_unlock_irq(&css_set_lock);
-
- if (ret)
- goto out_unlock;
+ if (enable && cgroup_parent(cgrp) && cgroup_has_tasks(cgrp)) {
+ ret = -EBUSY;
+ goto out_unlock;
}
/* save and update control masks and prepare csses */
--
2.13.0
Powered by blists - more mailing lists