[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CALvZod5kXRY0LV6VOnctTYVhdHu+=yqzsQzKYa2_6_Jg+cOWfQ@mail.gmail.com>
Date: Thu, 19 Oct 2023 09:36:44 -0700
From: Shakeel Butt <shakeelb@...gle.com>
To: Roman Gushchin <roman.gushchin@...ux.dev>
Cc: Vlastimil Babka <vbabka@...e.cz>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, cgroups@...r.kernel.org,
Johannes Weiner <hannes@...xchg.org>,
Michal Hocko <mhocko@...nel.org>,
Muchun Song <muchun.song@...ux.dev>,
Dennis Zhou <dennis@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Naresh Kamboju <naresh.kamboju@...aro.org>
Subject: Re: [PATCH v3 2/5] mm: kmem: add direct objcg pointer to task_struct
On Wed, Oct 18, 2023 at 3:38 PM Roman Gushchin <roman.gushchin@...ux.dev> wrote:
>
> On Wed, Oct 18, 2023 at 11:26:59AM -0700, Shakeel Butt wrote:
> > On Wed, Oct 18, 2023 at 10:22 AM Roman Gushchin
> > <roman.gushchin@...ux.dev> wrote:
> > >
> > [...]
> > > > > struct mem_cgroup *memcg;
> > > > > @@ -3008,19 +3054,26 @@ __always_inline struct obj_cgroup *get_obj_cgroup_from_current(void)
> > > > >
> > > > > if (in_task()) {
> > > > > memcg = current->active_memcg;
> > > > > + if (unlikely(memcg))
> > > > > + goto from_memcg;
> > > > >
> > > > > - /* Memcg to charge can't be determined. */
> > > > > - if (likely(!memcg) && (!current->mm || (current->flags & PF_KTHREAD)))
> > > >
> > > > The checks for current->mm and PF_KTHREAD seem to be gone completely after
> > > > the patch, was that intended and why?
> > >
> > > There is no need for those anymore because it's as cheap or cheaper
> > > to check task->objcg for being NULL. Those were primarily used to rule out
> > > kernel threads allocations early.
> > >
> >
> > I have the same understanding but please correct my suspicions here.
> > We can echo the kernel thread's pid to cgroup.procs which have
> > PF_NO_SETAFFINITY and thus this will cause the lower bit of the kernel
> > thread's task->objcg to be set. Please correct me if I am missing
> > something.
>
> Yes, you seem to be right. It's a gray zone because moving kernel threads out of
> the root cgroup doesn't sound like a good idea, but I agree it's better to keep
> the old behavior in place.
>
> Does this fixlet look good to you?
>
This looks fine. Another option is not to set the bit for such
task_structs in fork/attach.
> Thanks!
>
> --
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 1a2835448028..0b0d2dc7a7d4 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3021,6 +3021,10 @@ static struct obj_cgroup *current_objcg_update(void)
> old = NULL;
> }
>
> + /* If new objcg is NULL, no reason for the second atomic update. */
> + if (!current->mm || (current->flags & PF_KTHREAD))
> + return NULL;
> +
> /*
> * Release the objcg pointer from the previous iteration,
> * if try_cmpxcg() below fails.
Powered by blists - more mailing lists