Skip to content

Commit

Permalink
cgroup: always use cgroup_next_child() to walk the children list
Browse files Browse the repository at this point in the history
There are several places where the children list is accessed directly.
This patch converts those places to use cgroup_next_child().  This
will help updating the hierarchy iterators to use @css instead of
@cgrp.

While cgroup_next_child() can be heavy in pathological cases - e.g. a
lot of dead children, this shouldn't cause any noticeable behavior
differences.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
  • Loading branch information
Tejun Heo committed Aug 9, 2013
1 parent 3b287a5 commit f48e392
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions include/linux/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,8 @@ struct cgroup *cgroup_next_child(struct cgroup *pos, struct cgroup *cgrp);
* the start of the next iteration by, for example, bumping the css refcnt.
*/
#define cgroup_for_each_child(pos, cgrp) \
for ((pos) = list_first_or_null_rcu(&(cgrp)->children, \
struct cgroup, sibling); \
(pos); (pos) = cgroup_next_child((pos), (cgrp)))
for ((pos) = cgroup_next_child(NULL, (cgrp)); (pos); \
(pos) = cgroup_next_child((pos), (cgrp)))

struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,
struct cgroup *cgroup);
Expand Down
7 changes: 3 additions & 4 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,7 @@ struct cgroup *cgroup_next_descendant_pre(struct cgroup *pos,
pos = cgroup;

/* visit the first child if exists */
next = list_first_or_null_rcu(&pos->children, struct cgroup, sibling);
next = cgroup_next_child(NULL, pos);
if (next)
return next;

Expand Down Expand Up @@ -3151,7 +3151,7 @@ struct cgroup *cgroup_rightmost_descendant(struct cgroup *pos)
last = pos;
/* ->prev isn't RCU safe, walk ->next till the end */
pos = NULL;
list_for_each_entry_rcu(tmp, &last->children, sibling)
cgroup_for_each_child(tmp, last)
pos = tmp;
} while (pos);

Expand All @@ -3165,8 +3165,7 @@ static struct cgroup *cgroup_leftmost_descendant(struct cgroup *pos)

do {
last = pos;
pos = list_first_or_null_rcu(&pos->children, struct cgroup,
sibling);
pos = cgroup_next_child(NULL, pos);
} while (pos);

return last;
Expand Down

0 comments on commit f48e392

Please sign in to comment.