[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMZfGtUvGEzrXTUBnrGnFzxU_L2D5_YPV_n_a2VLiPN9MeJLwA@mail.gmail.com>
Date: Mon, 15 Jun 2020 14:26:16 +0800
From: Muchun Song <songmuchun@...edance.com>
To: Joonsoo Kim <js1304@...il.com>
Cc: Christoph Lameter <cl@...ux.com>,
Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
Linux Memory Management List <linux-mm@...ck.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [External] Re: [PATCH 1/3] mm/slub: Fix slabs_node return value
when CONFIG_SLUB_DEBUG disabled
On Mon, Jun 15, 2020 at 2:11 PM Joonsoo Kim <js1304@...il.com> wrote:
>
> 2020년 6월 14일 (일) 오후 9:39, Muchun Song <songmuchun@...edance.com>님이 작성:
> >
> > The slabs_node() always return zero when CONFIG_SLUB_DEBUG is disabled.
> > But some codes determine whether slab is empty by checking the return
> > value of slabs_node(). As you know, the result is not correct. This
> > problem can be reproduce by the follow code(and boot system with the
> > cmdline of "slub_nomerge"):
> >
> > void *objs[32];
> > struct kmem_cache *cache = kmem_cache_create("kmem-test", 128, 0,
> > 0, 0);
> >
> > if (cache) {
> > int i;
> >
> > /* Make a full slab */
> > for (i = 0; i < ARRAY_SIZE(objs); i++)
> > objs[i] = kmem_cache_alloc(cache, GFP_KERNEL_ACCOUNT);
> >
> > /*
> > * This really should fail because the slab cache still has
> > * objects. But we did destroy the @cache because of zero
> > * returned by slabs_node().
> > */
> > kmem_cache_destroy(cache);
> > }
> >
> > To fix it, we can move the nr_slabs of kmem_cache_node out of the
> > CONFIG_SLUB_DEBUG. So we can get the corrent value returned by the
> > slabs_node().
> >
> > With this patch applied, we will get a warning message and stack
> > trace in the dmesg.
> >
> > Signed-off-by: Muchun Song <songmuchun@...edance.com>
> > ---
> > mm/slab.h | 2 +-
> > mm/slub.c | 80 +++++++++++++++++++++++++++++++++------------------------------
> > 2 files changed, 43 insertions(+), 39 deletions(-)
> >
> > diff --git a/mm/slab.h b/mm/slab.h
> > index 0b91f2a7b033..062d4542b7e2 100644
> > --- a/mm/slab.h
> > +++ b/mm/slab.h
> > @@ -619,8 +619,8 @@ struct kmem_cache_node {
> > #ifdef CONFIG_SLUB
> > unsigned long nr_partial;
> > struct list_head partial;
> > -#ifdef CONFIG_SLUB_DEBUG
> > atomic_long_t nr_slabs;
> > +#ifdef CONFIG_SLUB_DEBUG
> > atomic_long_t total_objects;
> > struct list_head full;
> > #endif
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 49b5cb7da318..1a3e6a5b7287 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
>
> Hello,
>
> You also need to initialize nr_slabs in init_kmem_cache_node()
> on !CONFIG_SLUB_DEBUG.
Good catch, thanks! I will fix it in the next version.
>
> Otherwise, looks good to me.
>
> Thanks.
--
Yours,
Muchun
Powered by blists - more mailing lists