From patchwork Tue May 14 16:31:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13664280 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 541FCC04FFE for ; Tue, 14 May 2024 16:31:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91AFD8D002D; Tue, 14 May 2024 12:31:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CA178D000D; Tue, 14 May 2024 12:31:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C4A48D002D; Tue, 14 May 2024 12:31:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 590FA8D000D for ; Tue, 14 May 2024 12:31:36 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F3E63A1ADA for ; Tue, 14 May 2024 16:31:35 +0000 (UTC) X-FDA: 82117542150.11.742FCE9 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf08.hostedemail.com (Postfix) with ESMTP id 364D016002E for ; Tue, 14 May 2024 16:31:32 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fRXVVjPy; spf=pass (imf08.hostedemail.com: domain of 35JFDZgYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=35JFDZgYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715704293; 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: references:dkim-signature; bh=FYV+SMOQiamlhj9PR1ancAtyOBQwhK6fsau38j27Dhw=; b=qsYiB0rDxLYiBFbL4z/Mgr9ozkqp8QzeT9QjEHF0nJdx1xvNMqxZXFm8PNiHZ90aHgzDrz FKaNAo3WLua/MDo/Cs/Ln/DA77qnyPVwyFWKFy+pUODogEaxfjkhge/OLbTK61kcZbg5UC N1KQjY2lJk1+xw2G+OZgjwHlNJ7UV+Q= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=fRXVVjPy; spf=pass (imf08.hostedemail.com: domain of 35JFDZgYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=35JFDZgYKCE89B8v4sx55x2v.t532z4BE-331Crt1.58x@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715704293; a=rsa-sha256; cv=none; b=Ib1XbBkqGquVIZnTV7MJIq98kHMN6icc79K6klcu2eJtJ7PwZXX6oK5up4XkPWjWMvyiqF RNIJ5AVEVZyx7EzAO4eEbCXZQE/dtySoVSdYkZ8kQqRCkADdfdnC2goznqfw53vOlTSy4F bf4eHzS7N4gr/bV42AuH0a9+4xRUs3U= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc64f63d768so10432570276.2 for ; Tue, 14 May 2024 09:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715704292; x=1716309092; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=FYV+SMOQiamlhj9PR1ancAtyOBQwhK6fsau38j27Dhw=; b=fRXVVjPyNpD8HhiquBL4aq7S1uDSRTakV6HQu2pa2vuBd/0cMdWTcZjWW6kckUT3ef +IJawiUdXKVsjlhL+Q8OEG+tZgDzn4ALxU2QQ3xw376Zc8K7Zj/MMVlc2RRVrWA1i5X/ GRULZd/QAB34CjFdILebZ9vRjvI45u/i9niOkHBxNrskbb8ogevlPEVpYwUfDe/5pD1T 92bH6ARmJG7BtpGenAB6C7MRKBYk9WcOn55mN6QFQOQIKDzRjAviRBxlYWNdVac8xXE0 dfP8mBAOu0xm5g3dc6WDr+BLbLpqgEaz6ExtjIB/V1m/9LWY1mx+zRLgxWAWhEURltCW LS6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715704292; x=1716309092; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FYV+SMOQiamlhj9PR1ancAtyOBQwhK6fsau38j27Dhw=; b=o4QmlXkcBIO1XnvMXMbYu5PLgnFFLaTDCAtONHhiG00KQlEGn+3PMkWaay2Iu6wse5 2qMFjj03mdrOVMwZzSDtHHWqaO9ZkmxJ4mQ3tGsHOXOYePVzrK7BtKhnu6DjLPQxdaQH m99dxCtKZ4FBpG0E3dLR8RBcAt1Z6q7QmZrNT4fX2RrZjp5Oo5gPXDrh/NBHy5/ra8C9 xrzjWVui10hPgG1BIhuIHfmykFlriDKjiePsq/dhwTmbsR57cfJv/WOMtW/CNsMyLKK6 LqHjz7vlitmEd5BldvpIWdmpUlk4yBQYXMnIfDk/7WiMawYtzwdEGr44wOTOB02jwFtZ fGWw== X-Forwarded-Encrypted: i=1; AJvYcCVHyY/vE+4amYJM/xJTHmHmWJiyalc0E5qycUlB9GCqKffg5/7FnmyzcVnf+BaPtwubIHqPRg2T5/+AY8cIrIsHtwI= X-Gm-Message-State: AOJu0Yy+FqP7EQnZ+Y4ycJ5tJnC3ROan+XB8TDuIrZunFuOeAz6ZrB3v dJmubkMcBNk4EJ1+GQ6zwWmnVJ9NcC+B7YfgZDBy2LNk/UCvN4FuC0SKNuNQUhIlxM1FT8AlQqb QGg== X-Google-Smtp-Source: AGHT+IH8tWOuykXAgU5Pee8JW3hexeYZkHO8+gPnARCp67pA23h8mZSsUc7ypioRDnfO1jlvRbsOhwVLSfc= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:e8f6:c5d2:b646:f90d]) (user=surenb job=sendgmr) by 2002:a05:6902:1027:b0:dcc:c57c:8873 with SMTP id 3f1490d57ef6-dee4f3659c5mr3649331276.9.1715704292212; Tue, 14 May 2024 09:31:32 -0700 (PDT) Date: Tue, 14 May 2024 09:31:28 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240514163128.3662251-1-surenb@google.com> Subject: [PATCH v2 1/1] lib: add version into /proc/allocinfo output From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, pasha.tatashin@soleen.com, vbabka@suse.cz, keescook@chromium.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 364D016002E X-Stat-Signature: p3scrfafg9exncqy1hiwu7ph91rdxnt9 X-Rspam-User: X-HE-Tag: 1715704292-471546 X-HE-Meta: U2FsdGVkX18WQN65LP4HqfbKByQct/Da3UpJRHHv/ayJNcX63vJFPklWY/6XfZHoQQsTfkLbo8A9hEQR1x0MUrDpiqKvPiwhUiaRkU3txOMqjsjlYO+Jm0rsaslgW3/0Gu7iA4XcufROeQZpA5bTfjbCdU7ewWLVWTmedxwqbYHAnYXd1grX8uVG+20g7+78zAo721vW862yghrtQcUmEnG3Zw84SloxhxvzTh0A1D3gSkwGXDQrGRHt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375v/MGD9wqhkVO2DAtV/xTEYxK0clUFnHoo8jbPq6Tj//SQclgQjMbrrUY0atcicoDHyk2B4IcmkxY2AaZTyasXKHa+GdaYWZNeWqKgXd9FNU9HmA52W5LQbKzEW8JkDyqq/w4up31xzZ90v5qLZ4cbDREfhyKxH3BQ0bT3aQIOhf6UQV+rpfa8CIR+F+AuQzMCE++OL4cEBByhISlmWw7l9kse3bP1WcM74M5O7rtA/fWvdqchzwvPU8Pxr8EvOC5LUXZ5Lt+x9oTz8sW7GK4h9gVR65UaO9/rMMm60fDfkZLJqBQr/OuQqKiULCmO9146SWM65YZbrZDcm+gG59e 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: Add version string and a header at the beginning of /proc/allocinfo to allow later format changes. Example output: > head /proc/allocinfo allocinfo - version: 1.0 # 0 0 init/main.c:1314 func:do_initcalls 0 0 init/do_mounts.c:353 func:mount_nodev_root 0 0 init/do_mounts.c:187 func:mount_root_generic 0 0 init/do_mounts.c:158 func:do_mount_root 0 0 init/initramfs.c:493 func:unpack_to_rootfs 0 0 init/initramfs.c:492 func:unpack_to_rootfs 0 0 init/initramfs.c:491 func:unpack_to_rootfs 512 1 arch/x86/events/rapl.c:681 func:init_rapl_pmus 128 1 arch/x86/events/rapl.c:571 func:rapl_cpu_online Signed-off-by: Suren Baghdasaryan Reviewed-by: Pasha Tatashin Reviewed-by: Kees Cook --- Changes since v1 [1]: - Added header with field names, per Pasha Tatashin - Fixed a spelling error in the changelog [1] https://lore.kernel.org/all/20240514153532.3622371-1-surenb@google.com/ Documentation/filesystems/proc.rst | 5 ++-- lib/alloc_tag.c | 48 ++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 17 deletions(-) base-commit: 7e8aafe0636cdcc5c9699ced05ff1f8ffcb937e2 diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 245269dd6e02..4b71b3903d46 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -961,13 +961,14 @@ Provides information about memory allocations at all locations in the code base. Each allocation in the code is identified by its source file, line number, module (if originates from a loadable module) and the function calling the allocation. The number of bytes allocated and number of calls at each -location are reported. +location are reported. The first line indicates the version of the file, the +second line is the header listing fields in the file. Example output. :: - > sort -rn /proc/allocinfo + > tail -n +3 /proc/allocinfo | sort -rn 127664128 31168 mm/page_ext.c:270 func:alloc_page_ext 56373248 4737 mm/slub.c:2259 func:alloc_slab_page 14880768 3633 mm/readahead.c:247 func:page_cache_ra_unbounded diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 531dbe2f5456..cbe93939332d 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -16,47 +16,61 @@ EXPORT_SYMBOL(_shared_alloc_tag); DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT, mem_alloc_profiling_key); +struct allocinfo_private { + struct codetag_iterator iter; + bool print_header; + +}; + static void *allocinfo_start(struct seq_file *m, loff_t *pos) { - struct codetag_iterator *iter; + struct allocinfo_private *priv; struct codetag *ct; loff_t node = *pos; - iter = kzalloc(sizeof(*iter), GFP_KERNEL); - m->private = iter; - if (!iter) + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + m->private = priv; + if (!priv) return NULL; + priv->print_header = (node == 0); codetag_lock_module_list(alloc_tag_cttype, true); - *iter = codetag_get_ct_iter(alloc_tag_cttype); - while ((ct = codetag_next_ct(iter)) != NULL && node) + priv->iter = codetag_get_ct_iter(alloc_tag_cttype); + while ((ct = codetag_next_ct(&priv->iter)) != NULL && node) node--; - return ct ? iter : NULL; + return ct ? priv : NULL; } static void *allocinfo_next(struct seq_file *m, void *arg, loff_t *pos) { - struct codetag_iterator *iter = (struct codetag_iterator *)arg; - struct codetag *ct = codetag_next_ct(iter); + struct allocinfo_private *priv = (struct allocinfo_private *)arg; + struct codetag *ct = codetag_next_ct(&priv->iter); (*pos)++; if (!ct) return NULL; - return iter; + return priv; } static void allocinfo_stop(struct seq_file *m, void *arg) { - struct codetag_iterator *iter = (struct codetag_iterator *)m->private; + struct allocinfo_private *priv = (struct allocinfo_private *)m->private; - if (iter) { + if (priv) { codetag_lock_module_list(alloc_tag_cttype, false); - kfree(iter); + kfree(priv); } } +static void print_allocinfo_header(struct seq_buf *buf) +{ + /* Output format version, so we can change it. */ + seq_buf_printf(buf, "allocinfo - version: 1.0\n"); + seq_buf_printf(buf, "# \n"); +} + static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) { struct alloc_tag *tag = ct_to_alloc_tag(ct); @@ -71,13 +85,17 @@ static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) static int allocinfo_show(struct seq_file *m, void *arg) { - struct codetag_iterator *iter = (struct codetag_iterator *)arg; + struct allocinfo_private *priv = (struct allocinfo_private *)arg; char *bufp; size_t n = seq_get_buf(m, &bufp); struct seq_buf buf; seq_buf_init(&buf, bufp, n); - alloc_tag_to_text(&buf, iter->ct); + if (priv->print_header) { + print_allocinfo_header(&buf); + priv->print_header = false; + } + alloc_tag_to_text(&buf, priv->iter.ct); seq_commit(m, seq_buf_used(&buf)); return 0; }