Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2769152lqo; Tue, 14 May 2024 08:36:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpuEe4YBiqedNLsvb8NcyP0L2C5WXsH6p0jBIIYxFApkcPp+4ryV83IujpnnIxYst3tcUmIP17jhjhZc+/UNbBLWkmt6MUYRH/feDvoA== X-Google-Smtp-Source: AGHT+IHlrK5Sm02nAwFMYYcPP8rh6WeO0Rt7OlFgDP47ERJTeja9kDMb1E0b4ZhDHUugj3XU/9g7 X-Received: by 2002:a05:6e02:1c03:b0:36d:aa5a:3587 with SMTP id e9e14a558f8ab-36daa5a37b3mr34213745ab.22.1715700965848; Tue, 14 May 2024 08:36:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715700965; cv=pass; d=google.com; s=arc-20160816; b=O/xqDQRtbZiKbsafdnF7cNFVshJ4/alM4bPK+eWcKaezYelDN/swN/n9i3rzQhTGrl y5Cx/AOm9g2wp27f5+ehqWgpFfYYYV+qNq8QDZZCciLmATO+CTTgxkiPBONj/utCSPlf qQ45vpD+gKCVJHNHXU6Dpn/ifqAMVHEFBnC7ks/BjUJjAKiFBgHUxqmxeQ94vp58Q2uM PdXT21SQle//uBa8YfP+HxL3WR0nofqKgyPamC9q700ZBjMZUP/520n2pc61JbLhwfoj uC4DuvzrkFIPpDMdzMxGe7TiEzGNz9IfyiKm70RD5rz4cB9N0Xfq4qrjs7HSpGwM3HHz OTSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=8h1heic/WIrKkqKhGl4cPRJjsIzjvgjOs1wUbMcKuFY=; fh=irsjx0zFIbRaTdbxADa86ZkmEvF6nhWM+YU9YMzBV6A=; b=pCvD4v99g0Na5uxA8IeD8O+jvotvIdQO8mSZA5IbQ0BX+MN5s0wg9XZN3tZ+hAW20n C1R78OQ0anNhFmRh0x4a/O1bW3mEuWvG7kXDHDOZyqBW0pTWT4pM61wSqq6+cnfKsSuB 1IMu9CRLvbrw6xi388gKlu5m6GtmsVZ27EhgaISjqYjVaob7pJKLCP2148A0jCk48s7c Etxq+HHX00f6v4GQCxWTNDnKLKY+n+bwa55Bh1kOb91j0lOQHUpz+rjT+sCBIIBxUnSw i+RHuCwN2MfEB5RC2nUYxnDeZgr1zeLNPstMHOORmq183U5vzgA2YZ/LEmCpgSy+3Xv1 8s4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ynDfwUYW; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-178866-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6341180d5casi11431090a12.519.2024.05.14.08.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 08:36:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178866-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ynDfwUYW; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-178866-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8729DB2173D for ; Tue, 14 May 2024 15:36:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DC6717EBB6; Tue, 14 May 2024 15:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ynDfwUYW" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45D0817EBA1 for ; Tue, 14 May 2024 15:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715700955; cv=none; b=rNSUMRFX6j5vz4iWF+hhjNOFi63TxLAdmMKvLrhzBUuYzf5O+zoczfz02kVu7iSQiq2kAkUcHFlic9J44r2nwcOCS33sdVZzk2Q4AohPnZbhHpSEwaRQGfkwsOAvTzE/0LSK4e7y52IRTuv5fWTQndZtGFrRBSQ6OspzvACB8hU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715700955; c=relaxed/simple; bh=tyOLfaPN+vxyxmvRN25LjWKTOxGw/TP319a6bq49tsk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=p0rY0W/dzcxUZJS6Lbc6aX7wSpfnNnNr/Qmy09AaG82yA9+aG45kBr6MceikasIAgl5GgGtbp7kcaFwPnd16yzyrDj2LQj3wxACpI7hpocsLtAkG2ZR20uO+2dKrKsGT39SiPOISxNKciz2P0HzQbFsAYVxtExQiFsZA2ucnSYU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ynDfwUYW; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be8f9ca09so99430277b3.2 for ; Tue, 14 May 2024 08:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715700952; x=1716305752; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=8h1heic/WIrKkqKhGl4cPRJjsIzjvgjOs1wUbMcKuFY=; b=ynDfwUYW+cvf9+xm+MI9Ojrd1a3pWQ1eMwSiVDRgo5hvJ34CY0ajJCLvQrnQcbxnzB F/jsiZJA1q3LkwABfDAzGIxBZxQqRhseh735q/W1Ol8QrWoMPwPw19Na8M8A7BGnqTMw d46WVyKjN1JBjt+HfRZGkgjgMn6BwOMRylL+jWHSkIpzbYbEOgsDZ9GFl0pnG/FT4mPc Ea8uYOOHvFr+ZXyc3gkd95KmZaqGv+zpQMnML9cvIYHR70ekfbY1PGpvsP3CBG/GgdyE WXCaJnArwoX2BTUJscw9lUkPpRkraFiHnQE2f1FbbZRJ9UHg/mIrAxXZZ65GZEO9uybv 6fag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715700952; x=1716305752; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8h1heic/WIrKkqKhGl4cPRJjsIzjvgjOs1wUbMcKuFY=; b=VGj1pNrSuboJ9CHwzI+H9IXi9cQBQDwrFfT+yfc2bsLBNljRdxrEvHGRf5p0qCAIrO O5m2o9DlyGJqBTmxSdahvb3nel/r0EFPibbf279MvnFCwngHBNB2DQ+0lTzJrfFaKgkX 5S705PvJ2i/TR2CFST+XrGc3T4d+1AnIctDo2LUBzNJ25Y2ZSFnF2pcTYqD5U++H6d8q mJlaT1X4clUY1DX7QyPDPMo/iqeCiKog7y3LYKs3NOD1BoEVw0ZGsJ6lJ4+iZVA3tiMj M+AkNjgrqjq1qCGs8B9DFJfOUMhKoSmw2MDuGmlbRDj3ezyGc28u5hsVoMKTfy61xF1R EQSw== X-Forwarded-Encrypted: i=1; AJvYcCWU/lnOfSEAVxfpszEmKCc4lHMW/a2WcKK2Up67hewPiWp4GrbGimMzwiYPX1HyN9ZXqukSN8lxw6UYctI8uf+7W4SmGUeBNw/4uxRF X-Gm-Message-State: AOJu0YyC4y+KP3H1awL9WcCYl94gjRbk3HGOjyY+gS0meWcsCrgYku28 4aCx8dm/DBtFr2GrBtnVDWyNn/ZysCj84yhqSTMxyZqz62bKJtP6eUzRM/3J9b5Xx97R3bUu6FO KnA== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:e8f6:c5d2:b646:f90d]) (user=surenb job=sendgmr) by 2002:a05:690c:3802:b0:61b:e2ea:4d7b with SMTP id 00721157ae682-622affa5943mr35383047b3.1.1715700952239; Tue, 14 May 2024 08:35:52 -0700 (PDT) Date: Tue, 14 May 2024 08:35:32 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240514153532.3622371-1-surenb@google.com> Subject: [PATCH 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 Content-Type: text/plain; charset="UTF-8" Add version string at the beginning of /proc/allocinfo to allow later format changes. Exampe 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 --- Documentation/filesystems/proc.rst | 4 +-- lib/alloc_tag.c | 42 +++++++++++++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 245269dd6e02..97d76adb1ecf 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -961,13 +961,13 @@ 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. Example output. :: - > sort -rn /proc/allocinfo + > tail -n +2 /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..777b5cebf9a4 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -16,44 +16,51 @@ 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); } } @@ -71,13 +78,18 @@ 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) { + /* Output format version, so we can change it. */ + seq_buf_printf(&buf, "allocinfo - version: 1.0\n"); + priv->print_header = 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