Skip to content

Commit

Permalink
mm/memcg: iteration skip memcgs not yet fully initialized
Browse files Browse the repository at this point in the history
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 <hughd@google.com>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: <stable@vger.kernel.org>	[3.12+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Jan 24, 2014
1 parent d2ab70a commit d8ad305
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d8ad305

Please sign in to comment.