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 73982C48BEB for ; Fri, 16 Feb 2024 08:57:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3C768D0017; Fri, 16 Feb 2024 03:57:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC4498D0001; Fri, 16 Feb 2024 03:57:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B178C8D0017; Fri, 16 Feb 2024 03:57:16 -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 9F9C58D0001 for ; Fri, 16 Feb 2024 03:57:16 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7BF6CA036F for ; Fri, 16 Feb 2024 08:57:16 +0000 (UTC) X-FDA: 81797062872.04.378E61A Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf03.hostedemail.com (Postfix) with ESMTP id AF57020013 for ; Fri, 16 Feb 2024 08:57:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xqZAC8Nf; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DNo3cJgt; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=o6dFJHJY; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aZITzFqx; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708073834; 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=6frag4EZ1jOwLxH7IawG8bVTXT73kvKmKsBZp1SHOo0=; b=PsQSEqS8yUsC+A5vJQVqEcFcbMjlFqoO5QH7iOlm0ks4LdSQQqxJhPyM3c91DUeafw2ueP 1b4Qrj1xO4Nv9P6W6OhuB/74tYWSf89/Cro2vW9klTNfrqOwnhOY33m1RQCj7CvV6opg91 0uoyzKfZ7BkK2duvkjKJB9grElVggyo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708073834; a=rsa-sha256; cv=none; b=V51S0JkrVGBrkaWxJj/ZPmex/HmjDRMs8DOOtSwcNVipo5+OA7AIKdEf6KRZzXxkmJU/WH QMnhjBFxJ7emK2W+/Kp7+anaGwODejoZoKCvyuq4I9uHmNawNcsMaA2Bw1f8r33fYrGm6o dOxtRL8jy3BVTqxXhHV3iMSQOr/V7Ac= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=xqZAC8Nf; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=DNo3cJgt; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=o6dFJHJY; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aZITzFqx; spf=pass (imf03.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BDE1A1FB4A; Fri, 16 Feb 2024 08:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708073831; h=from:from:reply-to: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; bh=6frag4EZ1jOwLxH7IawG8bVTXT73kvKmKsBZp1SHOo0=; b=xqZAC8NfI4VPwOmiN56g60Raff5Lxhe17+xsX3vNH0QOzt6ShH89ZxADUdhLUmfzqa/yo3 TabAy019LUdCeaduHWP4hOkoOZikSueMUfLfFSxX3nthI3Q5FCXBIh5gkIPnuSEzUUHNC8 aoYjNlz6r1ytNmjUW0gbjA0CboAyvwM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708073831; h=from:from:reply-to: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; bh=6frag4EZ1jOwLxH7IawG8bVTXT73kvKmKsBZp1SHOo0=; b=DNo3cJgtVq0BnRTQlqXu+WykI9JOTEPvpS44g5kWEcGyImxRgdwT11KmfN81I/tNOI2VSh 2qzAv6tbxotS0DBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708073830; h=from:from:reply-to: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; bh=6frag4EZ1jOwLxH7IawG8bVTXT73kvKmKsBZp1SHOo0=; b=o6dFJHJYflEIhmu8oJUS9nBoJdP7QX+krsnSyjAwSUNaPBESiTUd+tjTVJio1OYYVYDu8j RJQ2ECJWmXvAR40mvWwwCTnb0VwMxSzGAwbFN7ZbKS4nInD0v8SqrIY6ixqlIVwvXyJkLa BmrtOuKfG6D2kWVEeFboNt4w/oWeZcU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708073830; h=from:from:reply-to: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; bh=6frag4EZ1jOwLxH7IawG8bVTXT73kvKmKsBZp1SHOo0=; b=aZITzFqxUxBBasuAdIqf/L/wncDfXgMKlk4TZrjJz7f6VSl6Ep4mywzmGsuZ9cplv0PiuQ xX5khlTEjs1YAwAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 309BB13A67; Fri, 16 Feb 2024 08:57:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id hBNOC2Yjz2U1ZQAAD6G6ig (envelope-from ); Fri, 16 Feb 2024 08:57:10 +0000 Message-ID: Date: Fri, 16 Feb 2024 09:57:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 13/35] lib: add allocation tagging support for memory allocation profiling Content-Language: en-US To: Suren Baghdasaryan , akpm@linux-foundation.org Cc: 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, 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 References: <20240212213922.783301-1-surenb@google.com> <20240212213922.783301-14-surenb@google.com> From: Vlastimil Babka In-Reply-To: <20240212213922.783301-14-surenb@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: AF57020013 X-Rspam-User: X-Stat-Signature: j3g159pixbb45b7mjmy3p3hqyjuse9fs X-Rspamd-Server: rspam03 X-HE-Tag: 1708073833-164266 X-HE-Meta: U2FsdGVkX1/Vxk/Vp/7BG11T573E6GVBssI1lsnwZwtIgFB5fs9y8IgAxodLxtonga3jaMn6SDkOg7iq1DAPrS4pZ/194EHCWxq+lV3yUlL/b2WWEbIgn9V49uRw1iQhKJNXow6pKEtzGIkriXuajDpJSybqXaq2W+tKWAvd3WPk1xKeKlktHn6/d/xTlYYEw99qZ68tOLG0OTUFZWnOYV3odP/CrPFu+GVGicb2U2ONp8LXX9Zsnj9bo1wVpC3+yJsDypc7ses+bi/KDyZvp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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 2/12/24 22:38, Suren Baghdasaryan wrote: > Introduce CONFIG_MEM_ALLOC_PROFILING which provides definitions to easily > instrument memory allocators. It registers an "alloc_tags" codetag type > with /proc/allocinfo interface to output allocation tag information when > the feature is enabled. > CONFIG_MEM_ALLOC_PROFILING_DEBUG is provided for debugging the memory > allocation profiling instrumentation. > Memory allocation profiling can be enabled or disabled at runtime using > /proc/sys/vm/mem_profiling sysctl when CONFIG_MEM_ALLOC_PROFILING_DEBUG=n. > CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT enables memory allocation > profiling by default. > > Signed-off-by: Suren Baghdasaryan > Co-developed-by: Kent Overstreet > Signed-off-by: Kent Overstreet > --- > Documentation/admin-guide/sysctl/vm.rst | 16 +++ > Documentation/filesystems/proc.rst | 28 +++++ > include/asm-generic/codetag.lds.h | 14 +++ > include/asm-generic/vmlinux.lds.h | 3 + > include/linux/alloc_tag.h | 133 ++++++++++++++++++++ > include/linux/sched.h | 24 ++++ > lib/Kconfig.debug | 25 ++++ > lib/Makefile | 2 + > lib/alloc_tag.c | 158 ++++++++++++++++++++++++ > scripts/module.lds.S | 7 ++ > 10 files changed, 410 insertions(+) > create mode 100644 include/asm-generic/codetag.lds.h > create mode 100644 include/linux/alloc_tag.h > create mode 100644 lib/alloc_tag.c > > diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst > index c59889de122b..a214719492ea 100644 > --- a/Documentation/admin-guide/sysctl/vm.rst > +++ b/Documentation/admin-guide/sysctl/vm.rst > @@ -43,6 +43,7 @@ Currently, these files are in /proc/sys/vm: > - legacy_va_layout > - lowmem_reserve_ratio > - max_map_count > +- mem_profiling (only if CONFIG_MEM_ALLOC_PROFILING=y) > - memory_failure_early_kill > - memory_failure_recovery > - min_free_kbytes > @@ -425,6 +426,21 @@ e.g., up to one or two maps per allocation. > The default value is 65530. > > > +mem_profiling > +============== > + > +Enable memory profiling (when CONFIG_MEM_ALLOC_PROFILING=y) > + > +1: Enable memory profiling. > + > +0: Disabld memory profiling. Disable ... > +allocinfo > +~~~~~~~ > + > +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 and the function calling the allocation. The number of bytes > +allocated at each location is reported. See, it even says "number of bytes" :) > + > +Example output. > + > +:: > + > + > cat /proc/allocinfo > + > + 153MiB mm/slub.c:1826 module:slub func:alloc_slab_page Is "module" meant in the usual kernel module sense? In that case IIRC is more common to annotate things e.g. [xfs] in case it's really a module, and nothing if it's built it, such as slub. Is that "slub" simply derived from "mm/slub.c"? Then it's just redundant? > + 6.08MiB mm/slab_common.c:950 module:slab_common func:_kmalloc_order > + 5.09MiB mm/memcontrol.c:2814 module:memcontrol func:alloc_slab_obj_exts > + 4.54MiB mm/page_alloc.c:5777 module:page_alloc func:alloc_pages_exact > + 1.32MiB include/asm-generic/pgalloc.h:63 module:pgtable func:__pte_alloc_one > + 1.16MiB fs/xfs/xfs_log_priv.h:700 module:xfs func:xlog_kvmalloc > + 1.00MiB mm/swap_cgroup.c:48 module:swap_cgroup func:swap_cgroup_prepare > + 734KiB fs/xfs/kmem.c:20 module:xfs func:kmem_alloc > + 640KiB kernel/rcu/tree.c:3184 module:tree func:fill_page_cache_func > + 640KiB drivers/char/virtio_console.c:452 module:virtio_console func:alloc_buf > + ... > + > + > meminfo ... > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 0be2d00c3696..78d258ca508f 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -972,6 +972,31 @@ config CODE_TAGGING > bool > select KALLSYMS > > +config MEM_ALLOC_PROFILING > + bool "Enable memory allocation profiling" > + default n > + depends on PROC_FS > + depends on !DEBUG_FORCE_WEAK_PER_CPU > + select CODE_TAGGING > + help > + Track allocation source code and record total allocation size > + initiated at that code location. The mechanism can be used to track > + memory leaks with a low performance and memory impact. > + > +config MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT > + bool "Enable memory allocation profiling by default" > + default y I'd go with default n as that I'd select for a general distro. > + depends on MEM_ALLOC_PROFILING > + > +config MEM_ALLOC_PROFILING_DEBUG > + bool "Memory allocation profiler debugging" > + default n > + depends on MEM_ALLOC_PROFILING > + select MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT > + help > + Adds warnings with helpful error messages for memory allocation > + profiling. > +