From patchwork Mon Feb 12 21:39:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13554069 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 075FFC4829E for ; Mon, 12 Feb 2024 21:41:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF9586B00B6; Mon, 12 Feb 2024 16:40:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CA8E16B00B7; Mon, 12 Feb 2024 16:40:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF85B6B00B8; Mon, 12 Feb 2024 16:40:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9B8046B00B6 for ; Mon, 12 Feb 2024 16:40:42 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6F2ED80782 for ; Mon, 12 Feb 2024 21:40:42 +0000 (UTC) X-FDA: 81784471524.29.3CC0ED8 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 9FBB940013 for ; Mon, 12 Feb 2024 21:40:40 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="3TF4t/zw"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3V5DKZQYKCNYKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3V5DKZQYKCNYKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707774040; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hFi0jScQsczt4c2Plav2pAvubIeyjPFOX5wIUH8AZHM=; b=yjrq64QXYaYIo+IoBBrDXmiYwevtZ/+YK0jTw0W0iZv/UhQdl4a9u5IsHP8OxXm4iNfrwe ObTwTgKblNWbHpmBzDyyS4rzV6dmkTxo6JGOaM8H/BxjfxJR6fj7DzJuRbZlyhyOFrioky +NCSSVzG+p04TWbvp70+6/PW5HJTkFg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="3TF4t/zw"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3V5DKZQYKCNYKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3V5DKZQYKCNYKMJ6F38GG8D6.4GEDAFMP-EECN24C.GJ8@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707774040; a=rsa-sha256; cv=none; b=L2MYCMLWdiqNKyatHcKLEp1XefcX+oHpEEBIBWFSbimBz9CgjKFAc30ZFqb6ZtNMz4Bn13 lMhuaIyrf/7kLtPSk6HiShxKyUahc8ezmjRojTNVu/Rq3oH6ouBBRGpjOcb8Mm1eof25UY VaGccixE+DrgQm/w6U3+dk4jkXTPUDI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-604ad18981eso84789347b3.2 for ; Mon, 12 Feb 2024 13:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707774040; x=1708378840; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hFi0jScQsczt4c2Plav2pAvubIeyjPFOX5wIUH8AZHM=; b=3TF4t/zwjBfJ70Ygki9A2/Li9mimSv+A0hcUbBF6dioSd7YPyELwLQbq8nauTQcpC5 D/msBRPyYaMtgM3wKPOSnnhzNNYklvsULu6pO3U+xQttudWjM5xwumrnzDzVNoVax7O1 zgT1d8tjs235lBIOgwYP1wWoWtRfqOsV3/dzcP5ZUiJ6NFDu4231kKtI23RASd4hltsj 3PpsvOlXXwe0fTqYcrO7jcLn2+tu8IWsQdfebIReZXaMgRe4mP64ZfVNyKHsp8GR5tss jc+zaNBsvewLGWqv3On9sG+xf6VOT9SJYuYH99PzjyIVUKGRUYx9ueMLoG5rX3COhPaD oj8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707774040; x=1708378840; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hFi0jScQsczt4c2Plav2pAvubIeyjPFOX5wIUH8AZHM=; b=gVoNW4pflNeIKkF4r1BcBSabZDSBY2yaUsdrHp5N/ZHxXx5I/9NucuWzvVW+WCaSpI 88irTelmJN7QNkzmiJHh+e0qDKqStjGPBEfVfdhNVv1GRbI4lMeUfDKRmLwf8M7bOOA2 G9DvQ+L6vt6KUKkNil5M4F0Gi8fGuKg1+IPjRPV5OMETOYHXgF95A+l6cHFZe2Z/C4Le ETrouBRxtXRn71blaVO+KtUd7M+XB+jLARt+y4ZJKMv8KW6pUdnk4qaOXDtZ/htbSNiY emjWj/3V5WfPqE6b1easzq/AMj/erW4UI6A4txgQ+ojN1GwDHduPhcQZq2p2tlIBrblM zINQ== X-Forwarded-Encrypted: i=1; AJvYcCUR5oAJOmgVYWCYTbnyIbEilAw/mR0lnoQWjEsiWJjXwR5DVOB2rE3203TpJW5yBDPDIglyuUpFIVt+d7twgjMCFH0= X-Gm-Message-State: AOJu0Yz64OAGWDGno1HZHvq/N+1pthE49jLHMvEtxEx85MQi+3Dhx5o7 4+X9/ft07FJk/O220S56uMYZ5bxVu0i8OJMnFRkYkKcZE8ZgWVTGLjRHqZcSbmGsY43FO2VdW/J mLg== X-Google-Smtp-Source: AGHT+IG01ZIdCxyG6doWIwi6F85UI5DWfcKo01/n0teetJJReA8rQ10tG50Lh8eu7adVmXuhCLeMmXOg6Mg= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b848:2b3f:be49:9cbc]) (user=surenb job=sendgmr) by 2002:a05:690c:b8b:b0:5ff:96b6:8ee1 with SMTP id ck11-20020a05690c0b8b00b005ff96b68ee1mr2134418ywb.7.1707774039644; Mon, 12 Feb 2024 13:40:39 -0800 (PST) Date: Mon, 12 Feb 2024 13:39:17 -0800 In-Reply-To: <20240212213922.783301-1-surenb@google.com> Mime-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240212213922.783301-32-surenb@google.com> Subject: [PATCH v3 31/35] lib: add memory allocations report in show_mem() From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9FBB940013 X-Stat-Signature: jbis615nkkzht76tgypq8cdqgj6yy8nw X-Rspam-User: X-HE-Tag: 1707774040-657212 X-HE-Meta: U2FsdGVkX1/nEjxdJubblq+ip+k5/rVtPY+dWUsq9mFj/fwTA4DxQYYyaK+5ZHOAJXP+5crtymFQNCFunjr3D4x3jHPyN4Rjvj+Lm4sgo1BozhftSrpWhGhvUam750dSh/3dyvhTRhrDqxrTf/dX5n88Hc9nu108mPFo4dUtDhKRvKPM1qwUhF0Fr8jmP7ccZqNfWZH9HIZnmhb6G+NEWE8shByj1g6WsGadzcP610Dzr8AYPrfx7HGGvoJyeClBv1i4OTt5ziqeRnQO36gDjHXRaEOquJf7VETw9ISHEgLb8+F6iiyYB33N0e8LxJGAQaN6SP39jWD77WtIoda88Uuuaz5IjtT5mp6pNk4ZJeVUiEyUyU0gfO3NUVR45OBMVhJalBxeGNV3UnDxWtW5AedLXFl/BVnAi1+4mfYsYuI5w+G7prkx6kzPMhuztIVwN9mBcwSFc8V7D0g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5wj67M3jY4msZiYZVRt2Sjnlt1HoGN3KzX15Q194BRpL4sfbDSVPRwCKR4VKrtPmTUABlzrZCjs/gOkT+7eir2HstbBiEC2BkjQ7OrrV3JKX1UX0B/scJCTAb9gT+aR5RMCqoDtl014xAMN076a+8BO2lYH+3ezC9z7+dH7jpHnC+ypPPvlFUPTLN7PGf8Oj6H+iX5AjW 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: List-Subscribe: List-Unsubscribe: Include allocations in show_mem reports. Signed-off-by: Kent Overstreet Signed-off-by: Suren Baghdasaryan --- include/linux/alloc_tag.h | 2 ++ lib/alloc_tag.c | 38 ++++++++++++++++++++++++++++++++++++++ mm/show_mem.c | 15 +++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 3fe51e67e231..0a5973c4ad77 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -30,6 +30,8 @@ struct alloc_tag { #ifdef CONFIG_MEM_ALLOC_PROFILING +void alloc_tags_show_mem_report(struct seq_buf *s); + static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct) { return container_of(ct, struct alloc_tag, ct); diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 2d5226d9262d..54312c213860 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -96,6 +96,44 @@ static const struct seq_operations allocinfo_seq_op = { .show = allocinfo_show, }; +void alloc_tags_show_mem_report(struct seq_buf *s) +{ + struct codetag_iterator iter; + struct codetag *ct; + struct { + struct codetag *tag; + size_t bytes; + } tags[10], n; + unsigned int i, nr = 0; + + codetag_lock_module_list(alloc_tag_cttype, true); + iter = codetag_get_ct_iter(alloc_tag_cttype); + while ((ct = codetag_next_ct(&iter))) { + struct alloc_tag_counters counter = alloc_tag_read(ct_to_alloc_tag(ct)); + + n.tag = ct; + n.bytes = counter.bytes; + + for (i = 0; i < nr; i++) + if (n.bytes > tags[i].bytes) + break; + + if (i < ARRAY_SIZE(tags)) { + nr -= nr == ARRAY_SIZE(tags); + memmove(&tags[i + 1], + &tags[i], + sizeof(tags[0]) * (nr - i)); + nr++; + tags[i] = n; + } + } + + for (i = 0; i < nr; i++) + alloc_tag_to_text(s, tags[i].tag); + + codetag_lock_module_list(alloc_tag_cttype, false); +} + static void __init procfs_init(void) { proc_create_seq("allocinfo", 0444, NULL, &allocinfo_seq_op); diff --git a/mm/show_mem.c b/mm/show_mem.c index 8dcfafbd283c..d514c15ca076 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -423,4 +424,18 @@ void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) #ifdef CONFIG_MEMORY_FAILURE printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); #endif +#ifdef CONFIG_MEM_ALLOC_PROFILING + { + struct seq_buf s; + char *buf = kmalloc(4096, GFP_ATOMIC); + + if (buf) { + printk("Memory allocations:\n"); + seq_buf_init(&s, buf, 4096); + alloc_tags_show_mem_report(&s); + printk("%s", buf); + kfree(buf); + } + } +#endif }