From patchwork Tue Aug 28 10:39:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 10578181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C432914E1 for ; Tue, 28 Aug 2018 10:39:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B253F297D5 for ; Tue, 28 Aug 2018 10:39:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6446297F2; Tue, 28 Aug 2018 10:39:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E1B0297ED for ; Tue, 28 Aug 2018 10:39:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27AF26B45B8; Tue, 28 Aug 2018 06:39:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 201646B45B9; Tue, 28 Aug 2018 06:39:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CAC16B45BA; Tue, 28 Aug 2018 06:39:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by kanga.kvack.org (Postfix) with ESMTP id 88E9D6B45B8 for ; Tue, 28 Aug 2018 06:39:21 -0400 (EDT) Received: by mail-lf1-f72.google.com with SMTP id y74-v6so225197lfd.4 for ; Tue, 28 Aug 2018 03:39:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=si6LZ+tIYZgjIwdNQ3qlYFweoxWHC5nk2wB1anOMjL8=; b=FDkFs0CkWAcrovToORE81Mf/24DCITp4t5KYWKzdr3fvfuMlQUQCyzdpO6IIZdll2u B4MtgbJWr7MleVuYnyZuBUhqOYrATKz+dg4I54ET3nhNK6N5LENjaV1rGyN2jQ0FLoeG TPtlgPeDd8iX1ZdsxgmdH0zdV8bC2THfdOtOMJvmBQ6HLtKu9EvjJmtNpmcbpYtbTewN IXJBMDdbGPHFwrmW7FUF1V8qUd1LUXgm+/YmdfQKWc6z/m6cEV2gQicc5dwMcB8fxe/K cA2BsjDHRm8X4mxsY2IE4SoW9nApdv8eJXPgmyP+EbG/GR4TWrLqbl9kfamtPfuPEX3F 1SIQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) smtp.mailfrom=vincent.whitchurch@axis.com X-Gm-Message-State: APzg51BTJq3w/NMF3ND0IQLneJ3GqunA1QPOL5dGVS+EbKyAQnvbh4IX POv6bX2jeG31hAzm+8udnLDqs9KmaM0Gp4iW6VYkrAWRMdPRZSe+wi6PQnCScMB7bMGOy5nRaK7 gr9WqmUoKMalAGdudYSkcVRjATYYerpeNLp1hYSFmdsO41qib9+MxVIHz00uOQeq6zg== X-Received: by 2002:a19:5154:: with SMTP id f81-v6mr868995lfb.55.1535452760980; Tue, 28 Aug 2018 03:39:20 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda11lvWaghkzxRYAOKhv7fkIDbDklbxaZ2ORb4SvmWndI/u1pz/SX6hd2znhyGY7HnCgf3p X-Received: by 2002:a19:5154:: with SMTP id f81-v6mr868926lfb.55.1535452759488; Tue, 28 Aug 2018 03:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535452759; cv=none; d=google.com; s=arc-20160816; b=jL42r5nMjTL4gnnwdXanE/F/cXU1u44T1n4ljUOR2BGS3EsrZtw9pxNWDKult/Uzlt 8IRLbcGh/DM/vM3sVohbd9zuWA1lOw6Akg3c7yXn662TcGdzPoAJvYVuvj7IqyDYMhOS mXC20WigZAHbhy9AhWBzDjVI9ZfqQDYh8GQcix2QxKHAU6pSUAKEO7++IDt3zmrzLQlK SDLxz9VoSn6JXYWg4+IyRLkJhQfK8zCpU80ooiBYnBVXOwEvsGYv0vXpe8WziHsZYje8 MzD1kRdAtFj7a0UYp62CLZD7PSDTBtW9nLUsxJ0XnlJb0SXacP7/vsBlsSxwZVUfb8aF 2EXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=si6LZ+tIYZgjIwdNQ3qlYFweoxWHC5nk2wB1anOMjL8=; b=SqX8JVPOsPNeaPsugt+i0HcFw4egRrS+XoNBr/GSHEwtHu6BtyAa3hKyYWPbQTBEqM nRQPG++Z6BUwpVDUSFXX+Q3ZkIUg8yBoq0MaWll08ba9gswqeMqfZZSTkUCAsF/4RVj5 bYz1MyARBr6QTE52vrvl1mm57btZLIW1C+HEtHrzxbkPyeSYTtzpz0Hi2/2WWfylIRt8 K42S+jLIKE/dYqppGJ0vE6XBBGkK3vOquQOIyiQJQbdX2sI6xnkX+nI9eH0BlV2sku6m QJNbhsqmt52KTWbVqlSQpRRk7q6/XNT1E7IAzCKxCuLN9J4K+YBfkRLlllYG7nrrg8V6 NDuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) smtp.mailfrom=vincent.whitchurch@axis.com Received: from bastet.se.axis.com (bastet.se.axis.com. [195.60.68.11]) by mx.google.com with ESMTPS id e15-v6si342976lfg.95.2018.08.28.03.39.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 03:39:19 -0700 (PDT) Received-SPF: pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) client-ip=195.60.68.11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) smtp.mailfrom=vincent.whitchurch@axis.com Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id E11D6183A0; Tue, 28 Aug 2018 12:39:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id BAoW5Ap7omb3; Tue, 28 Aug 2018 12:39:18 +0200 (CEST) Received: from boulder03.se.axis.com (boulder03.se.axis.com [10.0.8.17]) by bastet.se.axis.com (Postfix) with ESMTPS id 076BF1839E; Tue, 28 Aug 2018 12:39:17 +0200 (CEST) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBB271E07E; Tue, 28 Aug 2018 12:39:17 +0200 (CEST) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D07521E07C; Tue, 28 Aug 2018 12:39:17 +0200 (CEST) Received: from thoth.se.axis.com (unknown [10.0.2.173]) by boulder03.se.axis.com (Postfix) with ESMTP; Tue, 28 Aug 2018 12:39:17 +0200 (CEST) Received: from lnxartpec.se.axis.com (lnxartpec.se.axis.com [10.88.4.9]) by thoth.se.axis.com (Postfix) with ESMTP id C44F02150; Tue, 28 Aug 2018 12:39:17 +0200 (CEST) Received: by lnxartpec.se.axis.com (Postfix, from userid 10564) id BEE958016F; Tue, 28 Aug 2018 12:39:17 +0200 (CEST) From: Vincent Whitchurch To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vincent Whitchurch Subject: [PATCH 1/2] kmemleak: dump all objects for slab usage analysis Date: Tue, 28 Aug 2018 12:39:13 +0200 Message-Id: <20180828103914.30434-1-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.11.0 X-TM-AS-GCONF: 00 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: X-Virus-Scanned: ClamAV using ClamSMTP In order to be able to analyse the kernel's slab usage, we'd need a list of allocated objects and their allocation stacks. Kmemleak already maintains such a list internally, so we expose it via debugfs file. This file can be post-processed in userspace and converted to a suitable format for slab usage analysis. Signed-off-by: Vincent Whitchurch --- mm/kmemleak.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 17dd883198ae..7bef05c690d6 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1759,6 +1759,34 @@ static int kmemleak_seq_show(struct seq_file *seq, void *v) return 0; } +static void kmemleak_print_object(struct seq_file *seq, + struct kmemleak_object *object) +{ + int i; + + seq_printf(seq, "object 0x%08lx (size %zu):\n", + object->pointer, object->size); + seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n", + object->comm, object->pid, object->jiffies); + + for (i = 0; i < object->trace_len; i++) { + void *ptr = (void *)object->trace[i]; + + seq_printf(seq, " [<%p>] %pS\n", ptr, ptr); + } +} + +static int kmemleak_all_seq_show(struct seq_file *seq, void *v) +{ + struct kmemleak_object *object = v; + unsigned long flags; + + spin_lock_irqsave(&object->lock, flags); + kmemleak_print_object(seq, object); + spin_unlock_irqrestore(&object->lock, flags); + return 0; +} + static const struct seq_operations kmemleak_seq_ops = { .start = kmemleak_seq_start, .next = kmemleak_seq_next, @@ -1766,11 +1794,23 @@ static const struct seq_operations kmemleak_seq_ops = { .show = kmemleak_seq_show, }; +static const struct seq_operations kmemleak_all_seq_ops = { + .start = kmemleak_seq_start, + .next = kmemleak_seq_next, + .stop = kmemleak_seq_stop, + .show = kmemleak_all_seq_show, +}; + static int kmemleak_open(struct inode *inode, struct file *file) { return seq_open(file, &kmemleak_seq_ops); } +static int kmemleak_all_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &kmemleak_all_seq_ops); +} + static int dump_str_object_info(const char *str) { unsigned long flags; @@ -1911,6 +1951,14 @@ static const struct file_operations kmemleak_fops = { .release = seq_release, }; +static const struct file_operations kmemleak_all_fops = { + .owner = THIS_MODULE, + .open = kmemleak_all_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + static void __kmemleak_do_cleanup(void) { struct kmemleak_object *object; @@ -2102,6 +2150,11 @@ static int __init kmemleak_late_init(void) if (!dentry) pr_warn("Failed to create the debugfs kmemleak file\n"); + dentry = debugfs_create_file("kmemleak_all", 0400, NULL, NULL, + &kmemleak_all_fops); + if (!dentry) + pr_warn("Failed to create the debugfs kmemleak_all file\n"); + if (kmemleak_error) { /* * Some error occurred and kmemleak was disabled. There is a