cgroup: replace cgroup_has_tasks() with cgroup_is_populated()
authorTejun Heo <tj@kernel.org>
Thu, 15 Oct 2015 20:41:50 +0000 (16:41 -0400)
committerTejun Heo <tj@kernel.org>
Thu, 15 Oct 2015 20:41:50 +0000 (16:41 -0400)
commit27bd4dbb8d51c476298e62bd088225317b7853de
treeb61ec19505113cef0053780c403945266b24589e
parent0de0942db2b36dd91c088a7950398d2e87f23b23
cgroup: replace cgroup_has_tasks() with cgroup_is_populated()

Currently, cgroup_has_tasks() tests whether the target cgroup has any
css_set linked to it.  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 replaces cgroup_has_tasks() with cgroup_is_populated()
which tests cgroup->nr_populated instead which locally counts the
number of populated css_sets.  Unlike cgroup_has_tasks(),
cgroup_is_populated() is recursive - if any of the descendants is
populated, the cgroup is populated too.  While this changes the
meaning of the test, all the existing users are okay with the change.

While at it, replace the open-coded ->populated_cnt test in
cgroup_events_show() with cgroup_is_populated().

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
include/linux/cgroup.h
kernel/cgroup.c
kernel/cpuset.c
mm/memcontrol.c