From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 548C9C433E0 for ; Mon, 15 Jun 2020 06:26:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 07FAB20707 for ; Mon, 15 Jun 2020 06:26:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="tQQvJJca" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07FAB20707 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A2A3F6B0002; Mon, 15 Jun 2020 02:26:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DB216B0005; Mon, 15 Jun 2020 02:26:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F0CC6B0006; Mon, 15 Jun 2020 02:26:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 78A6F6B0002 for ; Mon, 15 Jun 2020 02:26:56 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2D81E181AC9BF for ; Mon, 15 Jun 2020 06:26:56 +0000 (UTC) X-FDA: 76930463232.04.drink69_4d0339a26df4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 027E78006980 for ; Mon, 15 Jun 2020 06:26:55 +0000 (UTC) X-HE-Tag: drink69_4d0339a26df4 X-Filterd-Recvd-Size: 5656 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Mon, 15 Jun 2020 06:26:55 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id m81so16603235ioa.1 for ; Sun, 14 Jun 2020 23:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=GKLgxaoSXCOixJadKXn8MWDjPBoGgNrgTm/UHSFd+FA=; b=tQQvJJcaVe+YFHkEgjLnaCG6qp5L2y7hRJx0JTHc+lzyyV52w8H529HLihDYAd24mR MP6xQc9SDAghYK3UOI1qz97KhEonx9E8TaOLEDRQnsxQmBmkRdgGfVmf5B3qyWKTXDPq exUwDZuQOWPpM895dVQfRR/NJ+r/QLTgfHDSgqvXUbpAHTTowe4LokIVAcG/duMBhunm r418YMngEJDRXaAUC45ASWF5ggEyUYhOjTITXnTLcTJhsYZmrzKiYiKhzn7arKaGlVDM YiE5EVA0bb50qNteD03ZMS6B2UgeHWDUyNyIeo8eftDy/W+2NHH+F+k/438FT2SM5EWf EjTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=GKLgxaoSXCOixJadKXn8MWDjPBoGgNrgTm/UHSFd+FA=; b=ADrU3TJ2JrAZOiwb29goiw3two5zOVrrdSACv8Gpb1zHbFFPBVn2+Ug/BM+vGs3wQ/ SU0HGO7qoJ4/7z128/OPSViCEmtyOTQjUrAAHb9f4uAuXJJMEPtire35AJ5NVT681LjP bb8KTTJ+hc82HUozei8g/Q37xbaUHk1pyIY5QnHxJTEECovTNOevyZwR8Un+mQQ8SLQY sXPQ2HmKBfyfPKs+3TVSSQafyc3ro8cGKT9T7EtNZ7wZ6+BBQ/rw/qRRX+SaLCWR+qfp c8an8wL31dHMl4E3Of74BjyALsuiNAO/fOzY/tyAQQirtKmt3OHbBIy8k4fFl8Ac8VcW 6Oaw== X-Gm-Message-State: AOAM531o5HwIxWhVAsjChK7eJmajB/weOI1EewNGnTcdUHgzE/1U9oIP hmEmeB5xKbxPaMtA1ePK0d0WOG8M0ydNSpQcPSrjXw== X-Google-Smtp-Source: ABdhPJzIdiIvMl/cqPtTln0PWfC36OxZYbOPZXKH4EbsNWSwOZWNZCiGYns0bdXTR+mLAdZSb0Qvxrwaa5Hh6p03JnI= X-Received: by 2002:a05:6602:2584:: with SMTP id p4mr26788694ioo.30.1592202414537; Sun, 14 Jun 2020 23:26:54 -0700 (PDT) MIME-Version: 1.0 References: <20200614123923.99189-1-songmuchun@bytedance.com> <20200614123923.99189-2-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Mon, 15 Jun 2020 14:26:16 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 1/3] mm/slub: Fix slabs_node return value when CONFIG_SLUB_DEBUG disabled To: Joonsoo Kim Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 027E78006980 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jun 15, 2020 at 2:11 PM Joonsoo Kim wrote: > > 2020=EB=85=84 6=EC=9B=94 14=EC=9D=BC (=EC=9D=BC) =EC=98=A4=ED=9B=84 9:39,= Muchun Song =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84= =B1: > > > > 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 =3D kmem_cache_create("kmem-test", 128, 0, > > 0, 0); > > > > if (cache) { > > int i; > > > > /* Make a full slab */ > > for (i =3D 0; i < ARRAY_SIZE(objs); i++) > > objs[i] =3D 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 > > --- > > 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. --=20 Yours, Muchun