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 D5553E77188 for ; Mon, 6 Jan 2025 21:12:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 658806B009F; Mon, 6 Jan 2025 16:12:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 607066B00B8; Mon, 6 Jan 2025 16:12:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481A56B00B9; Mon, 6 Jan 2025 16:12:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1F5326B009F for ; Mon, 6 Jan 2025 16:12:02 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C2569AEB2F for ; Mon, 6 Jan 2025 21:12:01 +0000 (UTC) X-FDA: 82978274442.18.070999A Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf21.hostedemail.com (Postfix) with ESMTP id D85F71C0012 for ; Mon, 6 Jan 2025 21:11:59 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1lhHZo63; spf=pass (imf21.hostedemail.com: domain of surenb@google.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=surenb@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=1736197919; 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=BtsPrpUvll5Rwc9qiWABH85YMqdY4e+fYCyLVH4Hgcw=; b=uyptwN0cN4xIDQ9MbXBUJtbLwXSOgdaIS0KYeopkM78dW4rP1KMbSXCzejbMj4WHjn0kNT nSvGPTWo/QvFKHJocwe+Y0lSHS2EL+Bpjeq2VuIiMhjUEi/3cVkoY/DzWKy2cOyCDm4Heh kT0ftsPLYNQJDqX8Uk9TfzXW9y0zOKY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736197919; a=rsa-sha256; cv=none; b=qVWxWkkfXxnoyg0Mm9WjzQLzeHDPViN83dh9rTI/cq1jJK0dTrsO2ANjyCMjcpOTVAYx69 UAHv9m91a04NSJMcM788SmWAMOY1ODOHdP1qK5txnlJQS3v6ALb1dqFIQHP96TprG/baVH IRjzg1MoL9bRz7oa/GCw1XuFjJwlFhc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1lhHZo63; spf=pass (imf21.hostedemail.com: domain of surenb@google.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4679b5c66d0so10041cf.1 for ; Mon, 06 Jan 2025 13:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736197919; x=1736802719; 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=BtsPrpUvll5Rwc9qiWABH85YMqdY4e+fYCyLVH4Hgcw=; b=1lhHZo63HyFhfP+eD4AqOcYO5kAdo+bzE3SBhm4fEfZ92Uh7Ds5lQvKUpX5rZRurtj ybWZkdkz/1+BcItOID2xN3dVS1Fx64Lp95FnG3e0HEPfyyqh0EImj5mP7uNpVb3oANVI 10SLsakqKLboisTi5iZdRovBhLyZoCTFP5+yFySE51ZRzdGbBfEiV5Xxr5oFF783iQKA 3uGP2H+mRbXExcHtNC33aDcWOhMlrsLYZHWKDssg/s3ZIHKYrFJqWtN3OFaGA9zpLyTm p/Q7c6TYaWV/TnW9MbgV60F/zm2cKKTUVqcJPS9+xJx12k0rieUzFSMNOtkX1Vc8gNNI 5Dbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736197919; x=1736802719; 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=BtsPrpUvll5Rwc9qiWABH85YMqdY4e+fYCyLVH4Hgcw=; b=gbe6NnGmNSrX7+Ma7xnZrE6lRy2abBuNkxUBbAjFDwCB2rGjfn0sMtYkGFImfyo8gj m+GlbLHKwD7KoVQsU2oUv2ByxsLl6+3cz+GPlsQi3lOrpnr2Ww0WGzzUuqduFSDfrk6c YPsdmqV1ZrlppX+IMOo9h3reAa2DlQoGVakQtdo/L7FLMSPKqNUwBmmgNkJFdsa2NV0P lLNdGnYzqzQswwbPGNuxlHMvua47VSzsKX3p2rkszd6jPaYTRcoWd5TbWQZvfVriamJp N2bcfcL7yg+LJ9E7hBx+/9qvvImL5ydU6cc3DY9XKDwnbwAeBZz8T9gPmtZ5BPRImHm0 Zu2g== X-Forwarded-Encrypted: i=1; AJvYcCV47yOKNMm2p5WaBt8cYmZDrD4uk0Ga00AcJq8TI8gtyd1dUmC0DBimO7sF4YHoEOwXoJAbV7V4Vg==@kvack.org X-Gm-Message-State: AOJu0YytedN434fYCQrRVc7RMXOhg8G1Tr6W0Prr0CjKJtzRxTK+ZguE hxm/80k9pfBBzS8682jNAJGl7v35H8SyLrK32cdA4V2WV6T3JtBPRFsd6vCMbMiOLc81s0s4V7I lTxcVv+DZWPYU+4oSwTMEuDrL33mIYiVzPaYp X-Gm-Gg: ASbGncu9z0ZfAkX3sKpIRG927F2vjag49Ufo1xWOWnvsOk6jZDJq00rPxSVWvV0QZIq C2St9fDsFdIL3jrkrOgLI4BGyCi4MifoTwnMTjQ== X-Google-Smtp-Source: AGHT+IGBHbtCHxyTjg/hp8a3CtHZQ7z7ZAdQbkvmaZ1oDqW8W3hGksm5mxbtnuA4E2n4/pz0b9YouNBSPEVghMyl9lw= X-Received: by 2002:a05:622a:14c9:b0:465:18f3:79c8 with SMTP id d75a77b69052e-46b3b9955cemr499441cf.13.1736197918729; Mon, 06 Jan 2025 13:11:58 -0800 (PST) MIME-Version: 1.0 References: <20250106112103.25401-1-hao.ge@linux.dev> In-Reply-To: <20250106112103.25401-1-hao.ge@linux.dev> From: Suren Baghdasaryan Date: Mon, 6 Jan 2025 13:11:47 -0800 X-Gm-Features: AbW1kvYWLR7hjojS7BrZjHFXrQo-Y-Pkb2WU4oeiP2MUKlQgla-nVsZLy6ZqaD8 Message-ID: Subject: Re: [PATCH] tools/mm: Introduce a tool to handle entries in allocinfo To: Hao Ge Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Hao Ge , Alessio Balsini , Pasha Tatashin , Sourav Panda , David Wang <00107082@163.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D85F71C0012 X-Stat-Signature: dje8x56fqrsgh6gjo6a8xqjkstr77913 X-Rspam-User: X-HE-Tag: 1736197919-370587 X-HE-Meta: U2FsdGVkX19QovZM4jjhF40LS+Gp/6dNDUh+9rODnvvUB9BS4vICLSkKT689ByEdi5rn1yc1Vkd2Zx6mG7EiY0kJzYD4B6/JBY6moGJeEFSPiuj87bpoAyrFgqTKwe8MBN6SlcDLpCP2CPWlC7vtbqUoZ2CCG92FHcMLlAd2lt8zrM2WFToP3gA6V6m2v3QqkM5QVl1vnYExKIZb9aXjJzQ9As+R2VYwLoKllJngwSvoOuLv8N7HE027Id41arxry81T/AjstQo1W20cA346iIAsVOfdArKrm+c+AdH+jQ+zQm9f/3mx6CY05vTznUseotmj6uXVRGeBhvlyHL4Dvikqd/rAAOivZCHd8m1iiYSU0InBNU102RyiESvXwj0a6C4uitXcL5WfLVliCnsVVEGZjGRzOxkw8CZ1KeOcQ4l+ga+8GX7cc+8gl/riRfdvD7jEVtANzIqhAQ1MDzgCH1WKqc0juvpbmX05iTgWQslewwEDT1X8zr5F6N/AM/BtffkamWLAtJmfqDV0fO22FrU8NkvEEV4TpLySYiyUOoQVFQyz9APPSo+XSGb5La9ZvHCUp2b1WyQra087hW56VeE0PsVkjK8mRrX7Q818ua8pif+45KX7NNIH5kOKPKQCQTRdR6NOhA1dx1CKg6KbtqkIbqx5JdJmR1gH3UzrZAc1iuXpHtDpw7rjQBPZef+pslP2pywX5t0sUMKeCTqxtk5fvELPxaP2TKJpkwF9n/gU4b78s+RlesSZ7WlQDOnDfU6k7TFXlcpE1E7PVogs5UafFfBLDvqwAnBt/d+L387Bcdl8vdOePYNYkCwR4fpEp4GKHh3PPbk/PEc66hPDWOS/yo13BA2ZpXCjseAtFCK+wmUyFwDYzBsCrwcrKLSHC0RitWOVxqbU9O72OV7bOgfF3wuFO6NRJcM2C5Fyp2W7bG3thk4t60V1VgXwzBmwsgVwoovytSyAYCWx8H8 yi8TOvVO fzgVY4Wfhl8Wn6fmHaclsb5j5BpObQv7o0Pj44AglydVJh+PSt55UMWKnIMOWkyAyUJbIgArxMyO8vgxAd+/oNhEpr+Ca4FWZbhNqMAc8UsHaRs4Altkn5ZKmVVqIqzpz4qCWoe8A6+T+UJWc63TprgDQVMo4d4y+ew1xlKW+rPY/olFtwnfnJpqn96GeDHP3VRk7+O5qqGqF3aVfasStNSFRz9pZywAsGUuxO0yN+ETFJUIHN9wXRO0LbA== 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: On Mon, Jan 6, 2025 at 3:22=E2=80=AFAM Hao Ge wrote: > > From: Hao Ge > > Some users always say that the information provided by /proc/allocinfo > is too extensive or bulky. > > However, from allocinfo's own perspective, it is not at fault as it > needs to provide comprehensive information. Users can then select the > information that is useful to them based on their own needs. > > For commonly used scenarios, we can develop a tool to facilitate users in > filtering and utilizing relevant information from allocinfo. > > Currently, there is only one filtering feature available, which is to > filter out entries where the 'bytes' field is 0 (since it is often used > to understand the current memory allocation status, as previously > mentioned by David Wang, who noticed that 2/3 of the lines have an > accumulative counter of 0, indicating no memory activities,it will fill > up the entire screen,by using the "-s" parameter, a lot of unnecessary > information for this scenario can be filtered out.) > > In subsequent phases, we will continue to add more features to this tool, > with the goal of making it convenient for most people to use the memory > allocation profiling tool. CC'ing Alessio along with Pasha and Sourav who were interested in such a to= ol. Hi Hao, Thanks for the tool! Actually Alessio just developed a tool called alloctop (similar to slabtop) which I think will do what you want and more. It supports sorting, filtering, continuous update, etc. It's written in Rust and we are planning to upstream it once we finish testing and evaluating it on Android. Please take a look and see if it fits your usecase. Please also note that this tool has been implemented just last week, so hot off the press and might have some early bugs. Thanks, Suren. [1] https://cs.android.com/android/platform/superproject/main/+/main:system= /memory/libmeminfo/tools/alloctop/src/ > > Signed-off-by: Hao Ge > --- > MAINTAINERS | 1 + > tools/mm/Makefile | 4 +- > tools/mm/allocinfo_tool.c | 150 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 153 insertions(+), 2 deletions(-) > create mode 100644 tools/mm/allocinfo_tool.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index 910305c11e8a..cfc3f9f0c046 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -15000,6 +15000,7 @@ F: Documentation/mm/allocation-profiling.rst > F: include/linux/alloc_tag.h > F: include/linux/pgalloc_tag.h > F: lib/alloc_tag.c > +F: tools/mm/allocinfo_tool.c > > MEMORY CONTROLLER DRIVERS > M: Krzysztof Kozlowski > diff --git a/tools/mm/Makefile b/tools/mm/Makefile > index f5725b5c23aa..f669d534a82b 100644 > --- a/tools/mm/Makefile > +++ b/tools/mm/Makefile > @@ -3,7 +3,7 @@ > # > include ../scripts/Makefile.include > > -BUILD_TARGETS=3Dpage-types slabinfo page_owner_sort thp_swap_allocator_t= est > +BUILD_TARGETS=3Dpage-types slabinfo page_owner_sort thp_swap_allocator_t= est allocinfo_tool > INSTALL_TARGETS =3D $(BUILD_TARGETS) thpmaps > > LIB_DIR =3D ../lib/api > @@ -23,7 +23,7 @@ $(LIBS): > $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) > > clean: > - $(RM) page-types slabinfo page_owner_sort thp_swap_allocator_test > + $(RM) page-types slabinfo page_owner_sort thp_swap_allocator_test= allocinfo_tool > make -C $(LIB_DIR) clean > > sbindir ?=3D /usr/sbin > diff --git a/tools/mm/allocinfo_tool.c b/tools/mm/allocinfo_tool.c > new file mode 100644 > index 000000000000..817f46d07a50 > --- /dev/null > +++ b/tools/mm/allocinfo_tool.c > @@ -0,0 +1,150 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * allocinfo_tool: Tool to parse allocinfo > + * > + * Authors: Hao Ge > + * > + * Compile with: > + * gcc -o allocinfo_tool allocinfo_tool.c > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#define ALLOCINFO_FILE "/proc/allocinfo" > +#define BUF_SIZE 1024 > +#define NAME_MAX_LENTH 64 > + > +struct alloc_tag_counters { > + signed long long bytes; > + unsigned long long calls; > +}; > + > +struct codetag { > + unsigned int lineno; > + char modname[NAME_MAX_LENTH]; > + char function[NAME_MAX_LENTH]; > + char filename[NAME_MAX_LENTH]; > +}; > + > +struct alloc_info { > + struct alloc_tag_counters counters; > + struct codetag tag; > + int has_modname; > +}; > + > +static int arg_opt; > + > +enum OPT_BIT { > + SKIP_ZERO =3D 1 << 0, > +}; > + > +void usage(void) > +{ > + printf("Usage: ./allocinfo_tool [OPTIONS]\n" > + "-s\t\t\tskip bytes for 0 allocinfo entries\n" > + ); > +} > + > +int parse_alloc_info(char *line, struct alloc_info *info) > +{ > + if (sscanf(line, "%12lli %8llu %[^:]:%d [%[^]]] func:%s", > + &info->counters.bytes, &info->counters.calls, > + info->tag.filename, &info->tag.lineno, > + info->tag.modname, info->tag.function) =3D=3D 6){ > + info->has_modname =3D 1; > + return 1; > + }; > + > + if (sscanf(line, "%12llu %8llu %[^:]:%u func:%s", > + &info->counters.bytes, &info->counters.calls, > + info->tag.filename, &info->tag.lineno, > + info->tag.function) =3D=3D 5){ > + info->has_modname =3D 0; > + return 1; > + } > + > + return 0; > +} > + > +int read_alloc_info(void) > +{ > + FILE *file =3D fopen(ALLOCINFO_FILE, "r"); > + > + if (!file) { > + perror("Failed to open /proc/allocinfo"); > + return EXIT_FAILURE; > + } > + > + int line =3D 0, i =3D 0; > + char *buffer =3D malloc(BUF_SIZE); > + struct alloc_info *info; > + > + while (fgets(buffer, BUF_SIZE, file)) { > + > + /* > + * allocinfo - version: 1.0 > + * # > + */ > + if (line < 2) { > + printf("%s", buffer); > + line++; > + continue; > + } > + > + info =3D realloc(info, sizeof(struct alloc_info) * (i + 1= )); > + > + if (parse_alloc_info(buffer, info + i) =3D=3D 0) { > + printf("Mismatch with the format of /proc/allocin= fo"); > + return 0; > + } > + > + if ((arg_opt & SKIP_ZERO) && (info[i].counters.bytes =3D= =3D 0)) > + continue; > + > + printf("%12lli %8llu ", info[i].counters.bytes, info[i].c= ounters.calls); > + > + if (info[i].has_modname) > + printf("%s:%u [%s] func:%s", > + info[i].tag.filename, info[i].tag.lineno, > + info[i].tag.modname, info[i].tag.function)= ; > + else > + printf("%s:%u func:%s", > + info[i].tag.filename, info[i].tag.lineno, > + info[i].tag.function); > + printf(" "); > + printf("\n"); > + i++; > + } > + > + free(info); > + free(buffer); > + fclose(file); > +} > + > +int main(int argc, char *argv[]) > +{ > + > + int opt; > + struct option longopts[] =3D { > + { "s", 0, NULL, 1}, > + { 0, 0, 0, 0}, > + }; > + > + while ((opt =3D getopt_long(argc, argv, "s", longopts, NULL)) != =3D -1) { > + switch (opt) { > + case 's': > + arg_opt =3D arg_opt | SKIP_ZERO; > + break; > + default: > + usage(); > + exit(1); > + } > + } > + > + read_alloc_info(); > + > +} > -- > 2.25.1 >