[PATCH] memcg: fix __mem_cgroup_same_or_subtree

From: Michal Hocko
Date: Mon Apr 08 2013 - 13:46:34 EST


__mem_cgroup_same_or_subtree relies on css_is_ancestor if hierarchy is
enabled for ages. This, however, is not correct because use_hierarchy
doesn't need to be true all the way up the cgroup hierarchy. Consider
the following example:
root (use_hierarchy=0)
\
A (use_hierarchy=0)
\
B (use_hierarchy=1)
\
C (use_hierarchy=1)

__mem_cgroup_same_or_subtree(A, C) would return true even though C is
not from the same hierarchy subtree. The bug shouldn't be critical but
at least dump_tasks might print unrelated tasks (via
task_in_mem_cgroup).

Signed-off-by: Michal Hocko <mhocko@xxxxxxx>
---
mm/memcontrol.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f608546..177bec2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1470,9 +1470,12 @@ bool __mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
{
if (root_memcg == memcg)
return true;
- if (!root_memcg->use_hierarchy || !memcg)
+ if (!memcg)
return false;
- return css_is_ancestor(&memcg->css, &root_memcg->css);
+ while ((memcg = parent_mem_cgroup(memcg)))
+ if (memcg == root_memcg)
+ return true;
+ return false;
}

static bool mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
--
1.7.10.4

--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/