Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2018876rbb; Tue, 27 Feb 2024 08:13:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWA9hMEtypRuOrfNiAkTo4uH6zr88Mgx9DdgGHU8sQvFuOLJzZZQPQo4Y3YBmsbOgoqnJ9irzOD9F2elmE4Ee07q5TME3eUQMSoMJnOJw== X-Google-Smtp-Source: AGHT+IHerqYp3DPUFLQQJVIwj+Wh19HcuE/mEZrWxzZwgrwitz0b1WyoNqPxQzBWygI8kdRnZBOl X-Received: by 2002:a05:6512:61:b0:513:5e6:4fbf with SMTP id i1-20020a056512006100b0051305e64fbfmr1474322lfo.59.1709050396405; Tue, 27 Feb 2024 08:13:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709050396; cv=pass; d=google.com; s=arc-20160816; b=lLS7yPxdFdlJXwkuhCwtMBNsq6DyGPREmrJpKuM+neDeTMxlYubvs3z3JK51MviFmw mMuPl4hUdhs3b1bcgKyiXIMoKl0jA+ckpAI29myva2z7/5VKPyzYl/w0rXHwUhcDItdu 5A+r7DZDqlDus+HPKwp0hu9/pkX7yMoIxC4W+abgAVdoADig5x39LRJbbfZ73KUNsKiE vPtP/MsR6QKZkAiD2mwztEQEJ2ZKrIL0xlEe+x/vNGXUfl5y0e+WyGiI6ilbmp5DXRno jJzXe5bGu3ottSa+y5IxAaSpG07soIa/kazyLqmnZWiqbl3Jua3o+man/3tEzRJfb6BV GlwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=dNhcz6LZWcGFo7q9Dz7N+i5BDAre97NpDL4CFWNtFMg=; fh=v+fWWC2j8PhTwbatpuBEGxEHm547cm36Tz2uZZaayQU=; b=wYt/sI19v7k1iUA6p8l5/OPslptrBCxuL8kru2ilOyit7FUMZpMaN7VIJEwfVLG1tt Xe4C5oFL7/bUuGiCH0LrMT8oHp/ikoqkBp5JBZcPHkWvDklKFFLVi7q1RX8K1HVI9fX5 bkbmVtHmLekMiNHEr/ZAqqvcqqxccVPHcmWpY3hVSH46WDLTEX5OWr/4LujS2wotlEvr 2RuNbAHdT78bd7QrIpKpLY+YXMMzd3Z/hn5tNZ/Kj7LyJ8pUF29Wrw2RuM7I9Ei2Xe1n U79VzDFL7k7nKwkQUruYDrjmovNzyoDoFChPSUrjpsUbms4hUKhzjWasqTuoNsD/KNTr 1ROQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QHN1Ubxp; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-83575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ju5-20020a170906e90500b00a3f89680fe8si831478ejb.38.2024.02.27.08.13.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 08:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QHN1Ubxp; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-83575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83575-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F182C1F26741 for ; Tue, 27 Feb 2024 16:13:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D96B614900A; Tue, 27 Feb 2024 16:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QHN1Ubxp" Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 DA29814830E for ; Tue, 27 Feb 2024 16:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709050355; cv=none; b=a+Hiejjb+Q1OMR3pw6Yu4HPf4IvfRnMHum46ytr+Jd+ONL2rjOk1eGjnYXUgPRfMAnDTliCImgsIa9HaagKLEInI5Tj5rS3ESiFD9ZXkzOkd6xExg8FyUf6qCElzUEBPzcwyxkD7X015XaMAkeY79v0t6dgGydIIFs1SsMNdlEA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709050355; c=relaxed/simple; bh=ZWFzHKUaRbx0c3fmxooFMoXF2H6+yVg0x+0ZAiLEH/s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Jyn1thZcDAPWzdurwzMaEmOF9hNwHEHOC6F/nx2fdSSFM+H8tUQ5dbFgixC5EklPjjyIMb2GaxUSmNgUZxj3usbsapUlKpjHfD7tTLGbQZFYCzlIUAZVUioogiaDS2IjTjSP/NCGAX8+Sh8roJ9nzmK8aw+5wQb/FcEd8m/LvD0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QHN1Ubxp; arc=none smtp.client-ip=209.85.128.179 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=google.com Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6084e809788so29665517b3.1 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=vger.kernel.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=QHN1UbxpzgSeKc+xCb/D6hZEL5COzuERYGzTNe/SAYmBpmqTw4EdWtnzIf632kLNqI Y6ElVv/hOUQcOvffPi/xkTsVsRaEAetrTMOjNpnNAP0Y38HKVx7oeBVVpxPFMzGGMtrc H7d6NyuK3ROKjbJiiZu1FTajS7dFD5u/ghLUwzKypFQfk95XusKRUKLfU64vaaZd61mG hq62+HFKVYF/OD3cCQuPRnofl2wNkiW05c0PlngCCbLARiV11ps1DZ7z+CFHW2dHosUk k8jA3l2d+/l5dJuSItG3Leda3GFMpG4wvlrVHap/hN47/brGsJGR7KVDWmRu4n4PhEMw nWsw== 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=eNsOnlkkQierxSowtyXL93hNS0AWjIzJUC7XRq5i8I9o99wtACBVQ4OBBDtJjwqcoz B96nyocU4k+6vMl74Xwui3jY8uAVBbY8/Wn6lRWxQAmNEnOQKyUCOTEdE/yFHrQUmVNw udJhRjAo6MNIZsdb7r9IDzvPfyN9/QuDYqfRdoUul721xrQ4zZ93UzQHDwYkZkCDU6M7 /nsFSdaN4V+zi0YkeqR1tiWJxglYUfUpB4We2PgAy1yASGDBr7P/skBPENWCULyg36kY oLQhTfYogIBlA2wquL+p6p04wpVOMEnd0+toLbEPtPsXlGWZjgwvx2HE9FE3Tjr2eHG1 C3lw== X-Forwarded-Encrypted: i=1; AJvYcCXDAzDf5ErHmmXSyQ8bYvivmZ8tw987KrialLm1zkysvxNl8va4oF+bv53iuGlFqaGlRekwEa09fphEfe2zEuDJ/HvCx5tgJktzz+z0 X-Gm-Message-State: AOJu0Yy3KWlmqSLAVe9TQAMGnVyfSnpO2TB990/4Y1e3OXOR62ZZHsYk tRy94FGqA3SLW36iBdNqX/q0fzlm/bcOR8YPrPD9BxYXLmWvxe8AHFLfPo//Ng59rDmG9bWsAJ4 DmMGN1oFOOVk0c6X5axsUCbBjfip+022gjL/x 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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. >