Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1662962

[PATCH 01/10] cgroup: separate out cgroup_has_tasks()

From Tejun Heo <tj@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 01/10] cgroup: separate out cgroup_has_tasks()
Date 2017-06-10 16:10 +0200
Message-ID <tQPfs-84G-15@gated-at.bofh.it> (permalink)
References <tQPfr-84G-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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@kernel.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

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH 01/10] cgroup: separate out cgroup_has_tasks() Tejun Heo <tj@kernel.org> - 2017-06-10 16:10 +0200

csiph-web