From mboxrd@z Thu Jan 1 00:00:00 1970 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 BCB08C25B75 for ; Tue, 14 May 2024 16:36:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 525586B024B; Tue, 14 May 2024 12:36:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D5426B024C; Tue, 14 May 2024 12:36:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39DA96B024D; Tue, 14 May 2024 12:36:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 18C7B6B024B for ; Tue, 14 May 2024 12:36:21 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BDADCA09C7 for ; Tue, 14 May 2024 16:36:20 +0000 (UTC) X-FDA: 82117554120.07.D54CBC9 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by imf24.hostedemail.com (Postfix) with ESMTP id EA08018001D for ; Tue, 14 May 2024 16:36:18 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="k+EBDsk/"; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715704579; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TVXdzVMs1VeoT7/U5XZ7/BvuwzKdJTwIaeZHIZqw7zs=; b=jj7lH7CS0FWCf4jlsKQnGdZ/RxhDeMjCkQC7pTPtVSbg5jfVCVYdt1Rp4ADSEoIwqq9x7g Th2e7ZZiw6cTFqL/Undr1PjGlL62QmJ4ADMV6+SWztl9yLplZjQAKmWCJt0BB730iS3Ahi Tln80FKzflLb6PQog7lgz5lGSeJLglE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715704579; a=rsa-sha256; cv=none; b=ddR9zr3WnqF4d08gLl19p6N6iXWWV1fXvxfIjB/5b+3tq+zv+dNDjfwlZohmgNFQ4QB6fV QYCb8fvICRN6d4UbavKDVKFrebxBg5gWjDLfaA3U7fqCwuy3t7LrgBEzVB4uhMmD2O8RpP LZO2LSEscN3uQaa8o/ogNRdgKH0kNn0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="k+EBDsk/"; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3c999d53e04so2619468b6e.2 for ; Tue, 14 May 2024 09:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1715704578; x=1716309378; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TVXdzVMs1VeoT7/U5XZ7/BvuwzKdJTwIaeZHIZqw7zs=; b=k+EBDsk/jmv33E/p5LEYQPhHGDVo/1/7EZr2xxJpt1MhwRAuKJKm6sZpsvgQPXBNFe sJuPGdszvNGUOMF3xIUvLoU0KZ5MlNJUanRYeXM+gMv5Z/kghhuK1nNAbqpFJ8e4uflX m7le7Y9yxIlH6uisIq2ZFlni8DM3xSvG6nhaeE+mvwOPEiSKlRF4Sl+JtDX1aajD3czJ AmbeO5hHxtib3u3N+i1BboPn2KYLebZHfT8KPIHYsPBYKPrhc5l+6MMqpNAGnjPy0UBq TBrwaGjMqtiGRHs8kA+k4csmGQ/bbn+4NcSmbHJrtJbw6EKGsaHZQ44/bCos7625JbkD Oarw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715704578; x=1716309378; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TVXdzVMs1VeoT7/U5XZ7/BvuwzKdJTwIaeZHIZqw7zs=; b=dCqohOnML6XTWs5jBCG0xlu1dXw+xbTsDX43bMHdys46t0L7qOh/vqND1eOxrmaptM /3tQu4Vp4tuoZOEIns6SSPLBPjwHSKGQiDNRkSIZQ1bm104QVFxm8SnRpjeZzj2o/skA 8rU1A4dHff3EX2VIzoci/FdYMEW6SbPa+dD5vmCDIEczLxp92fNIiI75h2d6KwJVL1q5 ceLvv0oUr0dcd57Ie63UI5aF+FQXMdJn/3LZJxE3M3dskM3IKXVL6f6qiVS5R1T/0Qyj 3V7K/5xaqtO8Lwt5aogfwtef+1Nmfpm11P6Vl+bM4i1C1JPcJrdn1dkGFZkS1xuy+jbl Q0Sg== X-Forwarded-Encrypted: i=1; AJvYcCV7dzvKkQVE7JUGGx5uZKaEtyz/oPsMWB5iZWkaOwqj6YY2CXmPE8L3TgjB/D4txtGFP6ydjQ4OERfGbvXP40nuOkc= X-Gm-Message-State: AOJu0YxqdPVTzfr6YN+BB2tjrtB8+zMO7s+31eUjn85F2I7m8Nq3AUYS ejcb4L2bpQWkTWeMAf5qqZSNCXRBHVpSpQvcu+2wegt9gR6fQTs/D4tkutgF5eMkJxGQiqTmCQj zXikF/wok1mciXwtRgYUl6kPrUTx7dpr4/iXpTg== X-Google-Smtp-Source: AGHT+IHXhf/LB/P+OFo+FdOeXpiwPNJZ/SCkFpjq//2iG7aZGRrWYAAU+buSwBUrPXCFyNB00v9UP0HfL/s7mpQsvk8= X-Received: by 2002:a05:6870:80c9:b0:22e:dd56:a72d with SMTP id 586e51a60fabf-24172901007mr17239397fac.26.1715704577857; Tue, 14 May 2024 09:36:17 -0700 (PDT) MIME-Version: 1.0 References: <20240514163128.3662251-1-surenb@google.com> In-Reply-To: <20240514163128.3662251-1-surenb@google.com> From: Pasha Tatashin Date: Tue, 14 May 2024 10:35:40 -0600 Message-ID: Subject: Re: [PATCH v2 1/1] lib: add version into /proc/allocinfo output To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 39oz8fpgw1exqcg8jx5r9chic7u34wdu X-Rspamd-Queue-Id: EA08018001D X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1715704578-441376 X-HE-Meta: U2FsdGVkX190l/Yiq1+/nauOcV1TcvqA4YBzvQIpistSfcxLrGYON+vm37qisBT9Lvwd+sqciVeEWlNwSRQw8epKD6AihGCG2EpVbC+hlsflX98Mxof7QiyKdA4/OvrYgyWhd6iEbwwvbD+Sh7jwz7JIijiNL6WGqBGuWvIfMbsze4DuwKqJ0a4X41q7nWTQjuJrqbgaWtxH5VUq/8Ad25qryldrwYNcwU3WpKKl375G2P1C85y20PaHeYXlyf1K8ZpdzVKJbG4w+91RKGomE2YYagKa93bk8wXKlp5+9UWiOEOQyYD2wXCJIBk8TweFWE9IIqZWwHk3D8eU7XWGx6z4FkEqq434unPSHEjgMjdIJi2R2Znz0l6iGCUANabmur3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sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, May 14, 2024 at 10:31=E2=80=AFAM Suren Baghdasaryan wrote: > > 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 Thank you, Pasha > --- > 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.co= m/ > > Documentation/filesystems/proc.rst | 5 ++-- > lib/alloc_tag.c | 48 ++++++++++++++++++++---------- > 2 files changed, 36 insertions(+), 17 deletions(-) > > diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesyste= ms/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 al= l 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 c= alling > the allocation. The number of bytes allocated and number of calls at eac= h > -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 =3D *pos; > > - iter =3D kzalloc(sizeof(*iter), GFP_KERNEL); > - m->private =3D iter; > - if (!iter) > + priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); > + m->private =3D priv; > + if (!priv) > return NULL; > > + priv->print_header =3D (node =3D=3D 0); > codetag_lock_module_list(alloc_tag_cttype, true); > - *iter =3D codetag_get_ct_iter(alloc_tag_cttype); > - while ((ct =3D codetag_next_ct(iter)) !=3D NULL && node) > + priv->iter =3D codetag_get_ct_iter(alloc_tag_cttype); > + while ((ct =3D codetag_next_ct(&priv->iter)) !=3D 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 =3D (struct codetag_iterator *)arg; > - struct codetag *ct =3D codetag_next_ct(iter); > + struct allocinfo_private *priv =3D (struct allocinfo_private *)ar= g; > + struct codetag *ct =3D 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 =3D (struct codetag_iterator *)m->p= rivate; > + struct allocinfo_private *priv =3D (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 =3D ct_to_alloc_tag(ct); > @@ -71,13 +85,17 @@ static void alloc_tag_to_text(struct seq_buf *out, st= ruct codetag *ct) > > static int allocinfo_show(struct seq_file *m, void *arg) > { > - struct codetag_iterator *iter =3D (struct codetag_iterator *)arg; > + struct allocinfo_private *priv =3D (struct allocinfo_private *)ar= g; > char *bufp; > size_t n =3D 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 =3D false; > + } > + alloc_tag_to_text(&buf, priv->iter.ct); > seq_commit(m, seq_buf_used(&buf)); > return 0; > } > > base-commit: 7e8aafe0636cdcc5c9699ced05ff1f8ffcb937e2 > -- > 2.45.0.rc1.225.g2a3ae87e7f-goog >