Re: [patch 01/11] mm: memcg: consolidate hierarchy iterationprimitives

From: Johannes Weiner
Date: Tue Sep 13 2011 - 01:41:07 EST


On Tue, Sep 13, 2011 at 01:37:46AM +0300, Kirill A. Shutemov wrote:
> On Mon, Sep 12, 2011 at 12:57:18PM +0200, Johannes Weiner wrote:
> > -static struct mem_cgroup *mem_cgroup_get_next(struct mem_cgroup *iter,
> > - struct mem_cgroup *root,
> > - bool cond)
> > -{
> > - int nextid = css_id(&iter->css) + 1;
> > - int found;
> > - int hierarchy_used;
> > - struct cgroup_subsys_state *css;
> > + if (prev && !remember)
> > + id = css_id(&prev->css);
> >
> > - hierarchy_used = iter->use_hierarchy;
> > + if (prev && prev != root)
> > + css_put(&prev->css);
> >
> > - css_put(&iter->css);
> > - /* If no ROOT, walk all, ignore hierarchy */
> > - if (!cond || (root && !hierarchy_used))
> > - return NULL;
> > + if (!root->use_hierarchy && root != root_mem_cgroup) {
> > + if (prev)
> > + return NULL;
> > + return root;
> > + }
> >
> > - if (!root)
> > - root = root_mem_cgroup;
> > + while (!mem) {
> > + struct cgroup_subsys_state *css;
> >
> > - do {
> > - iter = NULL;
> > - rcu_read_lock();
> > + if (remember)
> > + id = root->last_scanned_child;
> >
> > - css = css_get_next(&mem_cgroup_subsys, nextid,
> > - &root->css, &found);
> > - if (css && css_tryget(css))
> > - iter = container_of(css, struct mem_cgroup, css);
> > + rcu_read_lock();
> > + css = css_get_next(&mem_cgroup_subsys, id + 1, &root->css, &id);
> > + if (css) {
> > + if (css == &root->css || css_tryget(css))
>
> When does css != &root->css here?

It does not grab an extra reference to the passed hierarchy root, as
all callsites must already hold one to guarantee it's not going away.

> > +static void mem_cgroup_iter_break(struct mem_cgroup *root,
> > + struct mem_cgroup *prev)
> > +{
> > + if (!root)
> > + root = root_mem_cgroup;
> > + if (prev && prev != root)
> > + css_put(&prev->css);
> > +}
--
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/