Re: [RFC 2/5] memcg: rework mem_cgroup_iter to use cgroup iterators

From: Michal Hocko
Date: Mon Nov 19 2012 - 10:11:24 EST


On Tue 13-11-12 16:30:36, Michal Hocko wrote:
[...]
> + /*
> + * Root is not visited by cgroup iterators so it needs a special
> + * treatment.
> + */
> + if (!last_visited) {
> + css = &root->css;
> + } else {
> + struct cgroup *next_cgroup;
> +
> + next_cgroup = cgroup_next_descendant_pre(
> + last_visited->css.cgroup,
> + root->css.cgroup);
> + if (next_cgroup)
> + css = cgroup_subsys_state(next_cgroup,
> + mem_cgroup_subsys_id);

This is not correct because cgroup_next_descendant_pre expects pos to be
NULL for the first iteration but the way we do iterate (visit the root
first) means that the second iteration will have last_visited != NULL
and if root doesn't have any children the iteration would go unleashed
to to the endless loop. We need something like:
struct cgroup *prev_cgroup = (last_visited == root) ? NULL
: last_visited->css.cgroup;
next_cgroup = cgroup_next_descendant_pre(prev_cgroup,
root->css.gtoup);

--
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/