From patchwork Sun May 29 08:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rongwei Wang X-Patchwork-Id: 12864140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 098F4C4332F for ; Sun, 29 May 2022 08:15:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B19C08D0006; Sun, 29 May 2022 04:15:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA74A8D0005; Sun, 29 May 2022 04:15:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96B3F8D0006; Sun, 29 May 2022 04:15:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 806658D0005 for ; Sun, 29 May 2022 04:15:45 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5237C33D5C for ; Sun, 29 May 2022 08:15:45 +0000 (UTC) X-FDA: 79518071850.08.B3A5816 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by imf30.hostedemail.com (Postfix) with ESMTP id AF8F480048 for ; Sun, 29 May 2022 08:15:11 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R501e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VEe4qOs_1653812139; Received: from localhost.localdomain(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0VEe4qOs_1653812139) by smtp.aliyun-inc.com(127.0.0.1); Sun, 29 May 2022 16:15:40 +0800 From: Rongwei Wang To: akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, iamjoonsoo.kim@lge.com, rientjes@google.com, penberg@kernel.org, cl@linux.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm/slub: add nr_full count for debugging slub Date: Sun, 29 May 2022 16:15:35 +0800 Message-Id: <20220529081535.69275-3-rongwei.wang@linux.alibaba.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220529081535.69275-1-rongwei.wang@linux.alibaba.com> References: <20220529081535.69275-1-rongwei.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AF8F480048 X-Stat-Signature: 33g4jwx39u8n5oe41fyi6ih5akn15hb6 Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf30.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.43 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1653812111-793005 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: The n->nr_slabs will be updated when really to allocate or free a slab, but this slab is not necessarily in full list or partial list of one node. That means the total count of slab in node's full and partial list is not necessarily equal to n->nr_slabs, even though flush_all() has been called. An example here, an error message likes below will be printed when 'slabinfo -v' is executed: SLUB: kmemleak_object 4157 slabs counted but counter=4161 SLUB: kmemleak_object 4072 slabs counted but counter=4077 SLUB: kmalloc-2k 19 slabs counted but counter=20 SLUB: kmalloc-2k 12 slabs counted but counter=13 SLUB: kmemleak_object 4205 slabs counted but counter=4209 Here, nr_full is introduced in kmem_cache_node, to replace nr_slabs and eliminate these confusing messages. Signed-off-by: Rongwei Wang --- mm/slab.h | 1 + mm/slub.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index 95eb34174c1b..b1190e41a243 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -782,6 +782,7 @@ struct kmem_cache_node { unsigned long nr_partial; struct list_head partial; #ifdef CONFIG_SLUB_DEBUG + unsigned long nr_full; atomic_long_t nr_slabs; atomic_long_t total_objects; struct list_head full; diff --git a/mm/slub.c b/mm/slub.c index bffb95bbb0ee..99e980c8295c 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1220,6 +1220,9 @@ static void add_full(struct kmem_cache *s, lockdep_assert_held(&n->list_lock); list_add(&slab->slab_list, &n->full); +#ifdef CONFIG_SLUB_DEBUG + n->nr_full++; +#endif } static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct slab *slab) @@ -1229,6 +1232,9 @@ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct lockdep_assert_held(&n->list_lock); list_del(&slab->slab_list); +#ifdef CONFIG_SLUB_DEBUG + n->nr_full--; +#endif } /* Tracking of the number of slabs for debugging purposes */ @@ -3880,6 +3886,7 @@ init_kmem_cache_node(struct kmem_cache_node *n) INIT_LIST_HEAD(&n->partial); #ifdef CONFIG_SLUB_DEBUG atomic_long_set(&n->nr_slabs, 0); + n->nr_full = 0; atomic_long_set(&n->total_objects, 0); INIT_LIST_HEAD(&n->full); #endif @@ -4994,9 +5001,30 @@ static int validate_slab_node(struct kmem_cache *s, unsigned long count = 0; struct slab *slab; unsigned long flags; + unsigned long nr_cpu_slab = 0, nr_cpu_partial = 0; + int cpu; spin_lock_irqsave(&n->list_lock, flags); + for_each_possible_cpu(cpu) { + struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu); + struct slab *slab; + + slab = READ_ONCE(c->slab); + if (slab && n == get_node(s, slab_nid(slab))) + nr_cpu_slab += 1; +#ifdef CONFIG_SLUB_CPU_PARTIAL + slab = slub_percpu_partial_read_once(c); + if (slab && n == get_node(s, slab_nid(slab))) + nr_cpu_partial += slab->slabs; +#endif + } + if (nr_cpu_slab || nr_cpu_partial) { + pr_err("SLUB %s: %ld cpu slabs and %ld cpu partial slabs counted\n", + s->name, nr_cpu_slab, nr_cpu_partial); + slab_add_kunit_errors(); + } + list_for_each_entry(slab, &n->partial, slab_list) { validate_slab(s, slab, obj_map); count++; @@ -5010,13 +5038,14 @@ static int validate_slab_node(struct kmem_cache *s, if (!(s->flags & SLAB_STORE_USER)) goto out; + count = 0; list_for_each_entry(slab, &n->full, slab_list) { validate_slab(s, slab, obj_map); count++; } - if (count != atomic_long_read(&n->nr_slabs)) { + if (count != n->nr_full) { pr_err("SLUB: %s %ld slabs counted but counter=%ld\n", - s->name, count, atomic_long_read(&n->nr_slabs)); + s->name, count, n->nr_full); slab_add_kunit_errors(); }