Re: [PATCH 3/3] mm, oom: introduce memory.oom.group

From: Johannes Weiner
Date: Wed Aug 01 2018 - 13:45:23 EST


On Wed, Aug 01, 2018 at 07:55:03AM +0200, Michal Hocko wrote:
> On Tue 31-07-18 18:14:48, Roman Gushchin wrote:
> > On Tue, Jul 31, 2018 at 11:07:00AM +0200, Michal Hocko wrote:
> > > On Mon 30-07-18 11:01:00, Roman Gushchin wrote:
> > > > +struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim,
> > > > + struct mem_cgroup *oom_domain)
> > > > +{
> > > > + struct mem_cgroup *oom_group = NULL;
> > > > + struct mem_cgroup *memcg;
> > > > +
> > > > + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> > > > + return NULL;
> > > > +
> > > > + if (!oom_domain)
> > > > + oom_domain = root_mem_cgroup;
> > > > +
> > > > + rcu_read_lock();
> > > > +
> > > > + memcg = mem_cgroup_from_task(victim);
> > > > + if (!memcg || memcg == root_mem_cgroup)
> > > > + goto out;
> > >
> > > When can we have memcg == NULL? victim should be always non-NULL.
> > > Also why do you need to special case the root_mem_cgroup here. The loop
> > > below should handle that just fine no?
> >
> > Idk, I prefer to keep an explicit root_mem_cgroup check,
> > rather than traversing the tree and relying on an inability
> > to set oom_group on the root.
>
> I will not insist but this just makes the code harder to read.

Just FYI, I'd prefer the explicit check. The loop would do the right
thing, but it's a little too implicit and subtle for my taste...