From: Hugh Dickins Date: Thu, 23 Jan 2014 23:53:32 +0000 (-0800) Subject: mm/memcg: iteration skip memcgs not yet fully initialized X-Git-Tag: v3.14-rc1~108^2~158 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=d8ad30559715ce97afb7d1a93a12fd90e8fff312;p=linux.git mm/memcg: iteration skip memcgs not yet fully initialized It is surprising that the mem_cgroup iterator can return memcgs which have not yet been fully initialized. By accident (or trial and error?) this appears not to present an actual problem; but it may be better to prevent such surprises, by skipping memcgs not yet online. Signed-off-by: Hugh Dickins Cc: Tejun Heo Acked-by: Michal Hocko Cc: Johannes Weiner Cc: [3.12+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/memcontrol.c b/mm/memcontrol.c index aa66cc4c9e79..9537e1389ee6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1119,10 +1119,8 @@ static struct mem_cgroup *__mem_cgroup_iter_next(struct mem_cgroup *root, * protected by css_get and the tree walk is rcu safe. */ if (next_css) { - struct mem_cgroup *mem = mem_cgroup_from_css(next_css); - - if (css_tryget(&mem->css)) - return mem; + if ((next_css->flags & CSS_ONLINE) && css_tryget(next_css)) + return mem_cgroup_from_css(next_css); else { prev_css = next_css; goto skip_node;