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 8A66AE7716C for ; Thu, 5 Dec 2024 15:19:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 812CE6B00AC; Thu, 5 Dec 2024 10:19:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5555E6B00AF; Thu, 5 Dec 2024 10:19:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 818256B00AE; Thu, 5 Dec 2024 10:19:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4AD8C8D0001 for ; Fri, 13 Sep 2024 01:58:13 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CCDE316076A for ; Fri, 13 Sep 2024 05:58:12 +0000 (UTC) X-FDA: 82558659624.14.926A9DD Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) by imf18.hostedemail.com (Postfix) with ESMTP id 24AA01C000D for ; Fri, 13 Sep 2024 05:58:09 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=nudFpYs6; dmarc=pass (policy=none) header.from=163.com; spf=pass (imf18.hostedemail.com: domain of 00107082@163.com designates 117.135.210.4 as permitted sender) smtp.mailfrom=00107082@163.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726207062; a=rsa-sha256; cv=none; b=KWAOkEoeAEcMW/2ajgShFbTgxawkHRTb2pqb4tsBOy8PBQmQxS/5BR8y19FIbjbAJvKkje J5ToEVZgxtttb+PHHsPSqMWaKIB3QpQZ0XJkxuipdTu13Je3QBMeCPj76ZxJO22GutYsj/ jvZMok+eYVKzVtOUCSu2O8mHkrsPq1g= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=nudFpYs6; dmarc=pass (policy=none) header.from=163.com; spf=pass (imf18.hostedemail.com: domain of 00107082@163.com designates 117.135.210.4 as permitted sender) smtp.mailfrom=00107082@163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726207062; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Jot10t2ttv2oSJjbHdmFaubj0wa1UNajLUVcu1bzgLY=; b=YbY3Zk7LSuerQr935prs/IsS6OIkVr+5TnP/ZqWgkNKaBK3RBCBR/FHwhbBd4cPTjYe98l dsoCBAgtp2qTgFzPJYCCHyQjAyfgVRUgeikNybHt9T+0zxyl22IsA2XOUYCaPqcGf6p4FN Flyja5qGsKXszMMJB8txBJURspb/60k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Jot10 t2ttv2oSJjbHdmFaubj0wa1UNajLUVcu1bzgLY=; b=nudFpYs60TolMSsP5ZFG3 SjF5wYJd8YYRgXepKOPm6aUby+6nesPtfp/1S7WNCAI/DwoqcVkHX1l8sQOJuDZZ 1zN42pWMd0o2AqHVfolhpykWD4BuBGPQN1THKQ3BcBua2OlKADZWtIUvZrD5Le+1 tox7AArfTTRA58DcXq/5Cg= Received: from localhost.localdomain (unknown [111.35.191.143]) by gzga-smtp-mta-g2-1 (Coremail) with SMTP id _____wDXryVb1ONmNSjeFg--.19887S4; Fri, 13 Sep 2024 13:58:02 +0800 (CST) From: David Wang <00107082@163.com> To: surenb@google.com, kent.overstreet@linux.dev, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Wang <00107082@163.com> Subject: [PATCH v2] lib/alloc_tag: Add accumulative call counter for memory allocation profiling Date: Fri, 13 Sep 2024 13:57:29 +0800 Message-Id: <20240913055729.7208-1-00107082@163.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wDXryVb1ONmNSjeFg--.19887S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFW3AFyUZrW8JFy3ZFWUJwb_yoWrCFW3pa 1Ygw17Ga1rXrn7Gry7K3409r93tw4vyryfKFW29w4F9F1ayFWDXr1DKryavFykCFW0qF1j vwnagrW7CFnrJwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE1vVZUUUUU= X-Originating-IP: [111.35.191.143] X-CM-SenderInfo: qqqrilqqysqiywtou0bp/1tbiqQxZqmVOC2jImAAAsO X-Rspam-User: X-Rspamd-Queue-Id: 24AA01C000D X-Rspamd-Server: rspam01 X-Stat-Signature: ug5r4r4ydwwgp8nkcmp81qbqbegbhro1 X-HE-Tag: 1726207089-372924 X-HE-Meta: U2FsdGVkX19RJHv89tlYDdwFmPUsPOIdSYaSVE2jWs9Agd/RS5JAsc+lbXBZVVU3zqrYomyPeRVeDD+ZCHNvKV86A8uM2BWXahv7hYoidy/PkVVKhUS36j0uJr7iM77NwUsWu+xNEdPKBwVt3hG1vffEB8Tqiieod8AU99D4/udkIXnzFjsqZzrIhQcEcBG6PIsbR9XID3UwIEOMjjUNw2uwCnnfYFyicRC/KcoPIGz3NgkkuEBURrK4EcEbDwAz18k2k9IN5ldaeAFYY4XULfR3tpTcewI6KXi3yRY9CWkfg5TxLKW5NULnpGLoF7TW663VzyD9NKYEIImpwAdTBrAXOWAW3EfiXPHJJuSeQn+grEeeOumJ2sqpcRZYKBEya9R2F2zfeKAA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nhzMz9VHLkW176aZU97bx5YNxnRCDPfPmFgyI0b2WJ/paiPWj0qTHtrJplUmgRAULeZ1k= 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: Accumulative allocation counter can be used to evaluate memory allocation behavior/rate via delta(counters)/delta(time). It can help analysis performance issues, identify top modules with high rate of memory allocation activity. Considering this would incur extra performance and memory impact, introduce kconfig MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER. Signed-off-by: David Wang <00107082@163.com> --- Changes in v2: - Add kconfig MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER as suggested by "Kent Overstreet " --- include/linux/alloc_tag.h | 18 +++++++++++++++--- lib/Kconfig.debug | 10 ++++++++++ lib/alloc_tag.c | 10 +++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 8c61ccd161ba..5a94d61205b5 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -18,6 +18,9 @@ struct alloc_tag_counters { u64 bytes; u64 calls; +#ifdef CONFIG_MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + u64 accu_calls; +#endif }; /* @@ -103,13 +106,19 @@ static inline bool mem_alloc_profiling_enabled(void) static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag) { struct alloc_tag_counters v = { 0, 0 }; +#ifdef CONFIG_MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + v.accu_calls = 0; +#endif struct alloc_tag_counters *counter; int cpu; for_each_possible_cpu(cpu) { - counter = per_cpu_ptr(tag->counters, cpu); - v.bytes += counter->bytes; - v.calls += counter->calls; + counter = per_cpu_ptr(tag->counters, cpu); + v.bytes += counter->bytes; + v.calls += counter->calls; +#ifdef CONFIG_MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + v.accu_calls += counter->accu_calls; +#endif } return v; @@ -145,6 +154,9 @@ static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag * counter because when we free each part the counter will be decremented. */ this_cpu_inc(tag->counters->calls); +#ifdef CONFIG_MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + this_cpu_inc(tag->counters->accu_calls); +#endif } static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index a30c03a66172..1e9974d28510 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1000,6 +1000,16 @@ config MEM_ALLOC_PROFILING_DEBUG Adds warnings with helpful error messages for memory allocation profiling. +config MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + bool "Enable accumulative allocation counters" + default n + depends on MEM_ALLOC_PROFILING + help + Record accumulative call counters for memory allocation. This may have + extra performance and memory impact, but the impact is small. + The stat can be used to evaluate allocation activity/rate + via delta(counter)/delta(time). + source "lib/Kconfig.kasan" source "lib/Kconfig.kfence" source "lib/Kconfig.kmsan" diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 81e5f9a70f22..6b03edb04e7d 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -66,8 +66,12 @@ static void allocinfo_stop(struct seq_file *m, void *arg) static void print_allocinfo_header(struct seq_buf *buf) { /* Output format version, so we can change it. */ - seq_buf_printf(buf, "allocinfo - version: 1.0\n"); + seq_buf_printf(buf, "allocinfo - version: 1.1\n"); +#ifdef CONFIG_MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + seq_buf_printf(buf, "# \n"); +#else seq_buf_printf(buf, "# \n"); +#endif } static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) @@ -78,8 +82,12 @@ static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) seq_buf_printf(out, "%12lli %8llu ", bytes, counter.calls); codetag_to_text(out, ct); +#ifdef CONFIG_MEM_ALLOC_PROFILING_ACCUMULATIVE_CALL_COUNTER + seq_buf_printf(out, " %llu\n", counter.accu_calls); +#else seq_buf_putc(out, ' '); seq_buf_putc(out, '\n'); +#endif } static int allocinfo_show(struct seq_file *m, void *arg) -- 2.39.2