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 516A1C5478C for ; Tue, 27 Feb 2024 16:12:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D27A8280027; Tue, 27 Feb 2024 11:12:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB21C28001D; Tue, 27 Feb 2024 11:12:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7837280027; Tue, 27 Feb 2024 11:12:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A699028001D for ; Tue, 27 Feb 2024 11:12:35 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 68A6140C45 for ; Tue, 27 Feb 2024 16:12:35 +0000 (UTC) X-FDA: 81838076670.25.CB0B1DA Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by imf20.hostedemail.com (Postfix) with ESMTP id A66C91C000B for ; Tue, 27 Feb 2024 16:12:33 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Z7SbehfQ; spf=pass (imf20.hostedemail.com: domain of surenb@google.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709050353; a=rsa-sha256; cv=none; b=8dmm9MQVt5XoXu3T07+/mi2D9vS4nIVltjhuzI9NXVDFJZVKJ5lrdTuwH+uNH/jSl/qPI1 lALKyxLqq36+kEEBDCFT1Il4MXS+7dP9a9fQJxZDX9bSGqw9teM5BGN2o5UxJQwgnoTK1t ejeEfTiIblw8OEGy4OqUWxOM5FlJ67A= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Z7SbehfQ; spf=pass (imf20.hostedemail.com: domain of surenb@google.com designates 209.85.128.172 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=1709050353; 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=dNhcz6LZWcGFo7q9Dz7N+i5BDAre97NpDL4CFWNtFMg=; b=0/IJlHEHKc8rygUQagyL7yEBV5YS07DqhQQBnScItcapMCxnFOZua5QDzIdd/mV5aAphN7 z5Y3B7O0dtWNgcuhkDKBkZZ3ZmK6URQNFtudVm1qI4p0aFxa2+Bk8zAp1emkKtN6hZonB+ lcBPlPgOSK2nBTPSjHVzKA81ipLr3P4= Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6087396e405so32210737b3.0 for ; Tue, 27 Feb 2024 08:12:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709050353; x=1709655153; 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=dNhcz6LZWcGFo7q9Dz7N+i5BDAre97NpDL4CFWNtFMg=; b=Z7SbehfQDD3Y5FKGasGdSiSWTJmCTOvFezek681Ph5dksGsdc/lm3aPsVU1ZmDewdb lF4TQztwSCbt7q9zYoawk2hAumlbaeFxx2gMSZ1cZse44A0/ky31gvA8lR+r9sZ6wIxN 7eXXPOMvB9hpNuLr3uNcRe1f4xlHLVLO2ixjiqXy1YW3spUc7uHzJmzqTacnDADExLAX BNiBCEAdxLOKRdO2pMJmzvocPMbi43qSbBB6FevJ22zfX5TH7gdZOGacsWFUAMz3DFr9 0XPdBcxgF/kgrlhwjmpGzAIsLJp4J+jyl6M1RHiNJEoeTeUOR1FQNcgffh2F48jHz4op O+jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709050353; x=1709655153; 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=dNhcz6LZWcGFo7q9Dz7N+i5BDAre97NpDL4CFWNtFMg=; b=JBL7ENWxrRc2cqvwv3aCmwWC0VtZ6l8ol2xAMgwgSfzJZoqimOzwTcG4tZTFZxWVXI 60mAaPmdkEugIl/2mvnrJT07lGJyQ7Bvoh1kn4D1p+zf1UYQCvQC8il22StyaPO9/tGF CHxR/LrTjtVusc518/2FX0xFVKl4hNK58Bj5BfEk8wdaZ9dBcVZBwC85G7PBhvgBazUv mvHqK1a2+ygNlqRII8NDlnwEae/qCGDyX/fso/TmYS7Kgw5LU12kEcLu/FYo/hLn1Kb7 2TKMhpOmhpSRJvkDL01UvrjtF+5XuJ8lr8samDOist/+GcYwhz55mK6dVPBtNeftcLZd oG/Q== X-Forwarded-Encrypted: i=1; AJvYcCVRc3zU75k3ocBN8sPcjB7hCHDlK+qgaQR+p3G5FbFz9m2+RXYITyr2YB2eBVgb1AAotTzB09dVpda8q1hYsSO3Fbo= X-Gm-Message-State: AOJu0Yx2wZ1lJUj3EBXwZmO1hOVONUU/rPdYo2P7Og8reezghRfnkcqf rICcC/phnbmC7wFqRSyiE/QhvAtiIEAPKalgK/wFYZMiEIQ642xzqmo5d541U0FYVd4CyfGvTS1 r+tl8hlxjR00tBBGhBGaBwnFMpomsgt+YojRb X-Google-Smtp-Source: AGHT+IE3Ib/dLAymrmwvQkYDzdp8TQ37Go/G2wnHE4Xm/9+fqP9Mn0SYQYjmra6zLBDtJRxXpTmBRSRRYI9tV7m3olM= X-Received: by 2002:a25:c501:0:b0:dc2:2f3f:2148 with SMTP id v1-20020a25c501000000b00dc22f3f2148mr1714724ybe.29.1709050352173; Tue, 27 Feb 2024 08:12:32 -0800 (PST) MIME-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> <20240221194052.927623-32-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 27 Feb 2024 08:12:21 -0800 Message-ID: Subject: Re: [PATCH v4 31/36] lib: add memory allocations report in show_mem() To: Vlastimil Babka Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, 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, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A66C91C000B X-Stat-Signature: 91odokjxxstzq1dmy3kyzgmx9s9djhbz X-Rspam-User: X-HE-Tag: 1709050353-261214 X-HE-Meta: U2FsdGVkX1/X8Bwrr+eE/I74F0F4unYYEVJU4/1m1uGBaY6qD+mHtZqdiClVt+l7UETNXzMTZv1xrpokPKAbgwx5dgft8CoAT4/YbIdAK7r5UFnM7GujPljaSrXdMKSB2nXta1cwUw8tWt7YsuvL+nPW1Jz8U6CKKdp+W0QrJw9vIFcF4i4iuzAWpgxKGBRSXCIP2BK5E2xRpiYYjnzDXzdRABZWSbLyX36HgW7HvzwhxI0g2yVJ6oPSeyiwCQk0hiaMwsYKzxhmgEIsa4TxRb4TOD3BvZfiJhiaF7qY8Nqhq8C3PK4qHPlwmYj8/uEkjtyJdq2CIkBcYDyq9wURG2f2K8fekXo/9wSnkxcv6kOkFacMMc1coDvYYZeIIGnnECaffw3X4ndyLIgTECe0h6nqcaEGfnPN5g8zZ5maWqrNw6fQo/unhwLeQNvVKMlrop2wHzoDDrf1iLrEVhWaisVf8ydgaZEUEAuPmqHRVZrHJ/Mc/337K4PadgIQoF4zw4PupswBxCDMmnHGC3K7PPH9Qdmg/BmkjIKgTNIBqtld0KUpxD4zHqEMJD9ekgL3yx/4IMxUAEjso6amSgAEgavwU4ln4D/+UwjxGuoCACT8FyJ5Hmy9Xpl6Sjgoc4XAXWW9he6jjhAZSHo5aZoPdD5LSduy9+uD2KCoVOlR+lPHmY1ZQJd2vCOXkdFLYl/h41h9irLB/PkiGJIyQwnuE9tJM7aLCXcTIR65Ez9zj5bwppVhvmR4PXb/pUECJ79e3iTUnZt4VqdUSQnrLk1gQq2Dd4PApNWliJTa5ZT1LraoqsKBETwempvw8Aqc03p/TZieBx88pmhQuucN/hop03pJtSV0MnUTmLHVjbleLfKgCEWTlFZjYf2gtwnZ7+r9+By40hQ+CvkzMHUgqTeljEmvwdWC7gwl9gQIJ1DloZ52dF+gPIaIKnmzjb5Fq0S43wWNMF1jCsVe/CxboJl MbMF6R4O 2KNyHXsgmgTl9ZoanRNgUBfsbfUB082j5XRQD8BSbwu1gUYh7FPxy10+LDYz0KluUnsrWX/EI498FeczLQpIlKADcHE8UolrgV4390FRUwvVtUrva39Dt1MENdQ== 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 Tue, Feb 27, 2024 at 5:18=E2=80=AFAM Vlastimil Babka wr= ote: > > On 2/21/24 20:40, Suren Baghdasaryan wrote: > > Include allocations in show_mem reports. > > > > Signed-off-by: Kent Overstreet > > Signed-off-by: Suren Baghdasaryan > > Reviewed-by: Vlastimil Babka > > Nit: there's pr_notice() that's shorter than printk(KERN_NOTICE I used printk() since other parts of show_mem() used it but I can change if that's preferable. > > > --- > > include/linux/alloc_tag.h | 7 +++++++ > > include/linux/codetag.h | 1 + > > lib/alloc_tag.c | 38 ++++++++++++++++++++++++++++++++++++++ > > lib/codetag.c | 5 +++++ > > mm/show_mem.c | 26 ++++++++++++++++++++++++++ > > 5 files changed, 77 insertions(+) > > > > diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h > > index 29636719b276..85a24a027403 100644 > > --- a/include/linux/alloc_tag.h > > +++ b/include/linux/alloc_tag.h > > @@ -30,6 +30,13 @@ struct alloc_tag { > > > > #ifdef CONFIG_MEM_ALLOC_PROFILING > > > > +struct codetag_bytes { > > + struct codetag *ct; > > + s64 bytes; > > +}; > > + > > +size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, b= ool can_sleep); > > + > > static inline struct alloc_tag *ct_to_alloc_tag(struct codetag *ct) > > { > > return container_of(ct, struct alloc_tag, ct); > > diff --git a/include/linux/codetag.h b/include/linux/codetag.h > > index bfd0ba5c4185..c2a579ccd455 100644 > > --- a/include/linux/codetag.h > > +++ b/include/linux/codetag.h > > @@ -61,6 +61,7 @@ struct codetag_iterator { > > } > > > > void codetag_lock_module_list(struct codetag_type *cttype, bool lock); > > +bool codetag_trylock_module_list(struct codetag_type *cttype); > > struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttyp= e); > > struct codetag *codetag_next_ct(struct codetag_iterator *iter); > > > > diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c > > index cb5adec4b2e2..ec54f29482dc 100644 > > --- a/lib/alloc_tag.c > > +++ b/lib/alloc_tag.c > > @@ -86,6 +86,44 @@ static const struct seq_operations allocinfo_seq_op = =3D { > > .show =3D allocinfo_show, > > }; > > > > +size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, b= ool can_sleep) > > +{ > > + struct codetag_iterator iter; > > + struct codetag *ct; > > + struct codetag_bytes n; > > + unsigned int i, nr =3D 0; > > + > > + if (can_sleep) > > + codetag_lock_module_list(alloc_tag_cttype, true); > > + else if (!codetag_trylock_module_list(alloc_tag_cttype)) > > + return 0; > > + > > + iter =3D codetag_get_ct_iter(alloc_tag_cttype); > > + while ((ct =3D codetag_next_ct(&iter))) { > > + struct alloc_tag_counters counter =3D alloc_tag_read(ct_t= o_alloc_tag(ct)); > > + > > + n.ct =3D ct; > > + n.bytes =3D counter.bytes; > > + > > + for (i =3D 0; i < nr; i++) > > + if (n.bytes > tags[i].bytes) > > + break; > > + > > + if (i < count) { > > + nr -=3D nr =3D=3D count; > > + memmove(&tags[i + 1], > > + &tags[i], > > + sizeof(tags[0]) * (nr - i)); > > + nr++; > > + tags[i] =3D n; > > + } > > + } > > + > > + codetag_lock_module_list(alloc_tag_cttype, false); > > + > > + return nr; > > +} > > + > > static void __init procfs_init(void) > > { > > proc_create_seq("allocinfo", 0444, NULL, &allocinfo_seq_op); > > diff --git a/lib/codetag.c b/lib/codetag.c > > index b13412ca57cc..7b39cec9648a 100644 > > --- a/lib/codetag.c > > +++ b/lib/codetag.c > > @@ -36,6 +36,11 @@ void codetag_lock_module_list(struct codetag_type *c= ttype, bool lock) > > up_read(&cttype->mod_lock); > > } > > > > +bool codetag_trylock_module_list(struct codetag_type *cttype) > > +{ > > + return down_read_trylock(&cttype->mod_lock) !=3D 0; > > +} > > + > > struct codetag_iterator codetag_get_ct_iter(struct codetag_type *cttyp= e) > > { > > struct codetag_iterator iter =3D { > > diff --git a/mm/show_mem.c b/mm/show_mem.c > > index 8dcfafbd283c..1e41f8d6e297 100644 > > --- a/mm/show_mem.c > > +++ b/mm/show_mem.c > > @@ -423,4 +423,30 @@ void __show_mem(unsigned int filter, nodemask_t *n= odemask, int max_zone_idx) > > #ifdef CONFIG_MEMORY_FAILURE > > printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_p= ages)); > > #endif > > +#ifdef CONFIG_MEM_ALLOC_PROFILING > > + { > > + struct codetag_bytes tags[10]; > > + size_t i, nr; > > + > > + nr =3D alloc_tag_top_users(tags, ARRAY_SIZE(tags), false)= ; > > + if (nr) { > > + printk(KERN_NOTICE "Memory allocations:\n"); > > + for (i =3D 0; i < nr; i++) { > > + struct codetag *ct =3D tags[i].ct; > > + struct alloc_tag *tag =3D ct_to_alloc_tag= (ct); > > + struct alloc_tag_counters counter =3D all= oc_tag_read(tag); > > + > > + /* Same as alloc_tag_to_text() but w/o in= termediate buffer */ > > + if (ct->modname) > > + printk(KERN_NOTICE "%12lli %8llu = %s:%u [%s] func:%s\n", > > + counter.bytes, counter.cal= ls, ct->filename, > > + ct->lineno, ct->modname, c= t->function); > > + else > > + printk(KERN_NOTICE "%12lli %8llu = %s:%u func:%s\n", > > + counter.bytes, counter.cal= ls, ct->filename, > > + ct->lineno, ct->function); > > + } > > + } > > + } > > +#endif > > } > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >