From patchwork Wed Mar 2 17:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12766416 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 17576C433EF for ; Wed, 2 Mar 2022 17:31:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D471F8D0006; Wed, 2 Mar 2022 12:31:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD2E38D0007; Wed, 2 Mar 2022 12:31:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A84AC8D0006; Wed, 2 Mar 2022 12:31:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 71EA98D0003 for ; Wed, 2 Mar 2022 12:31:39 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 41CC71D2B for ; Wed, 2 Mar 2022 17:31:39 +0000 (UTC) X-FDA: 79200138318.05.4A33AC8 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf12.hostedemail.com (Postfix) with ESMTP id 8B9504001A for ; Wed, 2 Mar 2022 17:31:38 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EE40C1F8A8; Wed, 2 Mar 2022 17:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1646242296; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LQnHXhrO7on2owbSpKE5n1md35S3c5ELU5Z9yrYqevE=; b=pGtPuEgrk5zRWMLCylIQqL/l5kwpBUKLLwQw+/Nv36eFxoT56EUcD44bCY77kbRWNRxjO7 0MviCuveY2snGyyOS6++DZvGY3GDWxRBA8bSTYyJpj9twCLQrpbwZBdjSQiVwVDAY27ZBr doHMwNTSu1zvA9yQ79eVAO4O8N8V/o0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1646242296; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LQnHXhrO7on2owbSpKE5n1md35S3c5ELU5Z9yrYqevE=; b=EtbnYSUXQ8iCWjGO9SRXOrH2uy/pJIQHgf7+YT2dM+RIqmxlnlP+aUZ4wnGbXsPaIOw8WC 3JKikr+weZdjYNAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BA77413A89; Wed, 2 Mar 2022 17:31:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8EnuLPipH2LPTAAAMHmgww (envelope-from ); Wed, 02 Mar 2022 17:31:36 +0000 From: Vlastimil Babka To: David Rientjes , Christoph Lameter , Joonsoo Kim , Pekka Enberg , Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, Oliver Glitta , Faiyaz Mohammed , Marco Elver , Mike Rapoport , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Imran Khan , Vlastimil Babka Subject: [PATCH v2 4/6] mm/slub: distinguish and print stack traces in debugfs files Date: Wed, 2 Mar 2022 18:31:20 +0100 Message-Id: <20220302173122.11939-5-vbabka@suse.cz> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220302173122.11939-1-vbabka@suse.cz> References: <20220302173122.11939-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2691; i=vbabka@suse.cz; h=from:subject; bh=i+vTj/bLGNkS06QEkNuKLLTXKRcpqAmsd8AhSKRmP/4=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBiH6noW6mVlFyLbj1aJzDiTKdnm9vD+CY6DbeO2YmL hzn1zXKJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYh+p6AAKCRDgIcpz8YmpEPTTB/ 9Nm9Dxg3WSur7zB1Abt51hsqTZJ6TRd/u/Jx+tqEfmRCycJ89uyjl30SrhfjtLpAnUI2jha9AS6e+e +Zp5ZgM/67CLBHvLOQ9xD04qmnsl9+6aIM9LFj409LI5UQwJnttguLW1zdpea4kOQOF/1Zq8dK91eT rKBG8LGz+V+9fXO9x6vbN6TBzxvRLRzZqFWk4khMGMH7WY0PyktwnuIRbaU4s5n+rmvXroeLUNJ2ZY CgRpRTS3ykCDnUHj5fROFNHpJMWOSxjaln/3LAlX3svyq/tkZX1hflr8g/0Nxz6DimghkUEg0ILehb /cYy/J8v+gjNitirJ9GpHv/ObwEE/s X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Queue-Id: 8B9504001A X-Stat-Signature: 9rnsq1yhdub3ajgggun3gnufgb1st9uz Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=pGtPuEgr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=EtbnYSUX; spf=pass (imf12.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646242298-463777 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: From: Oliver Glitta Aggregate objects in slub cache by unique stack trace in addition to caller address when producing contents of debugfs files alloc_traces and free_traces in debugfs. Also add the stack traces to the debugfs output. This makes it much more useful to e.g. debug memory leaks. Signed-off-by: Oliver Glitta Signed-off-by: Vlastimil Babka Reviewed-and-tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slub.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 42cb79af70a0..25138cd7a4ef 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5074,6 +5074,7 @@ EXPORT_SYMBOL(validate_slab_cache); */ struct location { + depot_stack_handle_t handle; unsigned long count; unsigned long addr; long long sum_time; @@ -5126,9 +5127,13 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, { long start, end, pos; struct location *l; - unsigned long caddr; + unsigned long caddr, chandle; unsigned long age = jiffies - track->when; + depot_stack_handle_t handle = 0; +#ifdef CONFIG_STACKDEPOT + handle = READ_ONCE(track->handle); +#endif start = -1; end = t->count; @@ -5143,7 +5148,8 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, break; caddr = t->loc[pos].addr; - if (track->addr == caddr) { + chandle = t->loc[pos].handle; + if ((track->addr == caddr) && (handle == chandle)) { l = &t->loc[pos]; l->count++; @@ -5168,6 +5174,8 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, if (track->addr < caddr) end = pos; + else if (track->addr == caddr && handle < chandle) + end = pos; else start = pos; } @@ -5190,6 +5198,7 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, l->max_time = age; l->min_pid = track->pid; l->max_pid = track->pid; + l->handle = handle; cpumask_clear(to_cpumask(l->cpus)); cpumask_set_cpu(track->cpu, to_cpumask(l->cpus)); nodes_clear(l->nodes); @@ -6101,6 +6110,21 @@ static int slab_debugfs_show(struct seq_file *seq, void *v) seq_printf(seq, " nodes=%*pbl", nodemask_pr_args(&l->nodes)); +#ifdef CONFIG_STACKDEPOT + { + depot_stack_handle_t handle; + unsigned long *entries; + unsigned int nr_entries, j; + + handle = READ_ONCE(l->handle); + if (handle) { + nr_entries = stack_depot_fetch(handle, &entries); + seq_puts(seq, "\n"); + for (j = 0; j < nr_entries; j++) + seq_printf(seq, " %pS\n", (void *)entries[j]); + } + } +#endif seq_puts(seq, "\n"); }