]> git.karo-electronics.de Git - linux-beck.git/commitdiff
cgroup: make cgroup_destroy_locked() test cgroup_is_populated()
authorTejun Heo <tj@kernel.org>
Thu, 15 Oct 2015 20:41:51 +0000 (16:41 -0400)
committerTejun Heo <tj@kernel.org>
Thu, 15 Oct 2015 20:41:51 +0000 (16:41 -0400)
cgroup_destroy_locked() currently tests whether any css_sets are
associated to reject removal if the cgroup contains tasks.  This works
because a css_set's refcnt converges with the number of tasks linked
to it and thus there's no css_set linked to a cgroup if it doesn't
have any live tasks.

To help tracking resource usage of zombie tasks, putting the ref of
css_set will be separated from disassociating the task from the
css_set which means that a cgroup may have css_sets linked to it even
when it doesn't have any live tasks.

This patch updates cgroup_destroy_locked() so that it tests
cgroup_is_populated(), which counts the number of populated css_sets,
instead of whether cgrp->cset_links is empty to determine whether the
cgroup is populated or not.  This ensures that rmdirs won't be
incorrectly rejected for cgroups which only contain zombie tasks.

Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup.c

index ea87340af87158d7f31de61aab8d50e8fca556c9..61ee85ded6ae18950d5a8a94d1a89a7f95d874cb 100644 (file)
@@ -4998,16 +4998,15 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
        __releases(&cgroup_mutex) __acquires(&cgroup_mutex)
 {
        struct cgroup_subsys_state *css;
-       bool empty;
        int ssid;
 
        lockdep_assert_held(&cgroup_mutex);
 
-       /* css_set_rwsem synchronizes access to ->cset_links */
-       down_read(&css_set_rwsem);
-       empty = list_empty(&cgrp->cset_links);
-       up_read(&css_set_rwsem);
-       if (!empty)
+       /*
+        * Only migration can raise populated from zero and we're already
+        * holding cgroup_mutex.
+        */
+       if (cgroup_is_populated(cgrp))
                return -EBUSY;
 
        /*