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.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 E46CEC433DF for ; Mon, 15 Jun 2020 06:11:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 758A7206DB for ; Mon, 15 Jun 2020 06:11:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="exFIMX22" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 758A7206DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CA2506B0002; Mon, 15 Jun 2020 02:11:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2AC26B0003; Mon, 15 Jun 2020 02:11:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF2486B0005; Mon, 15 Jun 2020 02:11:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 9499B6B0002 for ; Mon, 15 Jun 2020 02:11:19 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1481D181AC9BF for ; Mon, 15 Jun 2020 06:11:19 +0000 (UTC) X-FDA: 76930423878.26.rice94_5d1499926df4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id DEDCC1804B655 for ; Mon, 15 Jun 2020 06:11:18 +0000 (UTC) X-HE-Tag: rice94_5d1499926df4 X-Filterd-Recvd-Size: 5220 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Mon, 15 Jun 2020 06:11:18 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id u17so11764662qtq.1 for ; Sun, 14 Jun 2020 23:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=EifQ9y2nKmcogMn7yhF1AlOyb5UE+7aa7f+MJo/iQBc=; b=exFIMX22quM2FDLvFwfvlgv4ssHRZtyRwnNYjsvzmSwTrgfZCGYABIuZqUiApY/zDn swGPk1p915aq6f6Rmw1SwRX/Tz0c7kOcYaATVQrxM1dBM4d5J4S/c6rTc3i2QA9Ms/gW VT4lpKDH1vUPTdD3Q/IQu0I+CQJDy/ECzJRfGt7JMbRB1biFYY5Hp5Rh3qFnwpQhlRi5 95XnCnFvv1IIZD1/MZcD19M2NJNwClNdtzmyWj7gWusRF4ZwYh6hUeLKjaDiafbNfnZ6 KAOi1nJPjB4SDhDVnbQs8FE7v3ZAKywjQDH9R+yzDu3M+L1KI77stD7fSei2hzkyiDsj G1Bg== 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=EifQ9y2nKmcogMn7yhF1AlOyb5UE+7aa7f+MJo/iQBc=; b=gu6/Iyc8pWq7FvR4hIQQ0qlyzMqiYt+74Ykk1kuM/HxqWY/m2796HjtCUmntUdiYUz 6Jywge4PaYfWZSmme8cGyWyQsPpVtL+mvDU7M5YZDRP68y4kf7t6J2ZN3qes1PFlNei2 AvQdompsCCs12kSognzd35QQsZ8ceKYg1G9bxCRCModOMcwqZmD053UdzCExUEjoXaOz 4oqnVcz+dFuVp0wTsLIKZg8LQvYI9yS0NKt5NFV5G15yaUBSjdFJJYPRkmdb4G57RCtG vKiCFRevWOn19b7zzSf8y4ZDFUh45V4pBP2whBObRgyADuOMwyKTOBJ3Y3p/v65IACbz OOoQ== X-Gm-Message-State: AOAM531sLnlWs2FwLrMaq6KsYVDcwwDFHgbKm3l2f2BAR7FARFIsYaA7 FjpoYLO806r25455Gy1Rd9YV5RNlzkcqiDaTHdU= X-Google-Smtp-Source: ABdhPJxT5qk+oak2tVU7SaONyWtaqZpUJ5mXozBodU35C/opvp1oYtQHqqAMeGk9bm5qX/2ArIqfcZw2SXbXbovvjig= X-Received: by 2002:ac8:6bc1:: with SMTP id b1mr14375639qtt.65.1592201477844; Sun, 14 Jun 2020 23:11:17 -0700 (PDT) MIME-Version: 1.0 References: <20200614123923.99189-1-songmuchun@bytedance.com> <20200614123923.99189-2-songmuchun@bytedance.com> In-Reply-To: <20200614123923.99189-2-songmuchun@bytedance.com> From: Joonsoo Kim Date: Mon, 15 Jun 2020 15:11:06 +0900 Message-ID: Subject: Re: [PATCH 1/3] mm/slub: Fix slabs_node return value when CONFIG_SLUB_DEBUG disabled To: Muchun Song 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: DEDCC1804B655 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: 2020=EB=85=84 6=EC=9B=94 14=EC=9D=BC (=EC=9D=BC) =EC=98=A4=ED=9B=84 9:39, M= uchun 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. Otherwise, looks good to me. Thanks.