lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMZfGtWJeov9XD_MEkDJwTK5b73OKPYxJBQi=D5-NSyNSSKLCw@mail.gmail.com>
Date:   Tue, 18 Jan 2022 20:05:44 +0800
From:   Muchun Song <songmuchun@...edance.com>
To:     Michal Koutný <mkoutny@...e.com>
Cc:     Matthew Wilcox <willy@...radead.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Johannes Weiner <hannes@...xchg.org>,
        Michal Hocko <mhocko@...nel.org>,
        Vladimir Davydov <vdavydov.dev@...il.com>,
        Shakeel Butt <shakeelb@...gle.com>,
        Roman Gushchin <guro@...com>, Yang Shi <shy828301@...il.com>,
        Alex Shi <alexs@...nel.org>,
        Wei Yang <richard.weiyang@...il.com>,
        Dave Chinner <david@...morbit.com>,
        trond.myklebust@...merspace.com, anna.schumaker@...app.com,
        jaegeuk@...nel.org, chao@...nel.org,
        Kari Argillander <kari.argillander@...il.com>,
        linux-fsdevel <linux-fsdevel@...r.kernel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Linux Memory Management List <linux-mm@...ck.org>,
        linux-nfs@...r.kernel.org, Qi Zheng <zhengqi.arch@...edance.com>,
        Xiongchun duan <duanxiongchun@...edance.com>,
        Fam Zheng <fam.zheng@...edance.com>,
        Muchun Song <smuchun@...il.com>
Subject: Re: [PATCH v5 10/16] mm: list_lru: allocate list_lru_one only when needed

On Thu, Jan 13, 2022 at 9:32 PM Michal Koutný <mkoutny@...e.com> wrote:
>
> On Wed, Jan 12, 2022 at 09:22:36PM +0800, Muchun Song <songmuchun@...edance.com> wrote:
> >   root(-1) -> A(0) -> B(1) -> C(2)
> >
> > CPU0:                                   CPU1:
> > memcg_list_lru_alloc(C)
> >                                         memcg_drain_all_list_lrus(C)
> >                                         memcg_drain_all_list_lrus(B)
> >                                         // Now C and B are offline. The
> >                                         // kmemcg_id becomes the following if
> >                                         // we do not the kmemcg_id of its
> >                                         // descendants in
> >                                         // memcg_drain_all_list_lrus().
> >                                         //
> >                                         // root(-1) -> A(0) -> B(0) -> C(1)
> >
> >   for (i = 0; memcg; memcg = parent_mem_cgroup(memcg), i++) {
> >       // allocate struct list_lru_per_memcg for memcg C
> >       table[i].mlru = memcg_init_list_lru_one(gfp);
> >   }
> >
> >   spin_lock_irqsave(&lru->lock, flags);
> >   while (i--) {
> >       // here index = 1
> >       int index = table[i].memcg->kmemcg_id;
> >
> >       struct list_lru_per_memcg *mlru = table[i].mlru;
> >       if (index < 0 || rcu_dereference_protected(mlrus->mlru[index], true))
> >           kfree(mlru);
> >       else
> >           // mlrus->mlru[index] will be assigned a new value regardless
> >           // memcg C is already offline.
> >           rcu_assign_pointer(mlrus->mlru[index], mlru);
> >   }
> >   spin_unlock_irqrestore(&lru->lock, flags);
> >
>
> > So changing ->kmemcg_id of all its descendants can prevent
> > memcg_list_lru_alloc() from allocating list lrus for the offlined
> > cgroup after memcg_list_lru_free() calling.
>
> Thanks for the illustrative example. I can see how this can be a problem
> in a general call of memcg_list_lru_alloc(C).
>
> However, the code, as I understand it, resolves the memcg to which lru
> allocation should be associated via get_mem_cgroup_from_objcg() and
> memcg_reparent_list_lrus(C) comes after memcg_reparent_objcgs(C, B),
> i.e. the allocation would target B (or even A if after
> memcg_reparent_objcgs(B, A))?
>
> It seems to me like "wasting" the existing objcg reparenting mechanism.
> Or what do you think could be a problem relying on it?
>

I have thought about this. It's a little different to rely on objcg
reparenting since the user can get memcg from objcg and
then does not realize the memcg has reparented. Although it
can check memcg->objcg to know whether the memcg is
reparented, it should also prevent this memcg from being
reparented throughout memcg_list_lru_alloc(). Maybe
holding css_set_lock can do that. I do not think this
is a good choice. Do you have any thoughts about this?

Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ