From patchwork Mon Jun 17 15:32:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wang <00107082@163.com> X-Patchwork-Id: 13700979 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 6F4A5C2BA15 for ; Mon, 17 Jun 2024 15:33:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6D9F6B0204; Mon, 17 Jun 2024 11:33:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1E136B0205; Mon, 17 Jun 2024 11:33:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE54F6B0206; Mon, 17 Jun 2024 11:33:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9F2046B0204 for ; Mon, 17 Jun 2024 11:33:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F0C2D1A18E7 for ; Mon, 17 Jun 2024 15:33:39 +0000 (UTC) X-FDA: 82240775358.25.B1641EB Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.219]) by imf10.hostedemail.com (Postfix) with ESMTP id 3BFF6C001C for ; Mon, 17 Jun 2024 15:33:36 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=jyJLQ0yO; spf=pass (imf10.hostedemail.com: domain of 00107082@163.com designates 45.254.50.219 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718638413; 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=7OviYDEQb7uRFcJ+eACIcQxXYLnr6KuLZxlnKBnBsaI=; b=JYGmFof1rCA/lKm92dmskOzE/MIyBdA0K/qnjzYUXdzwqSg+xMxTIld1bvl7I7DhYc+rKG hW8vRe8l+dmctq9uwRL/tyd1BNinXxzJ1jnY3d6Jk0VEZvri/aPgeGH5EWe+LAI4/DgoR5 49dkc2rsn+bJc1nPF0USdlWUJsjCveI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718638413; a=rsa-sha256; cv=none; b=E7iY+KPurx6uHwEFMyVLcxHGrY+2nr4TtZXojdnA1WzeCmhQvxEaHVVwwRgVYNhT4IoYzh /byz1wrFsCZtIedHtrG1/GytWK2KXETl3AsnnkgLGVf9zL2vW/nQAwBHO8WchhCKDImcCY sp8iQgg2cD2nU3SdWvkCVgNKIhbjNwI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=163.com header.s=s110527 header.b=jyJLQ0yO; spf=pass (imf10.hostedemail.com: domain of 00107082@163.com designates 45.254.50.219 as permitted sender) smtp.mailfrom=00107082@163.com; dmarc=pass (policy=none) header.from=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=7OviY DEQb7uRFcJ+eACIcQxXYLnr6KuLZxlnKBnBsaI=; b=jyJLQ0yOFz/4Yu2UG8Xba /tsXf/vMWZ0NDoxtu/bRZlAl3Xdp9V3em/sjV+GNLYkR3RdQFTtKI5dfgz46k1/Y qFEQhFUtqfEr4dEhzpinL2z/1zmWfQvH5fFvsYu9FAYcrugzjjMgcA2fvUDIhQUc VGbqHrbqqxMNrPw3763YuA= Received: from localhost.localdomain (unknown [111.35.186.64]) by gzga-smtp-mta-g0-2 (Coremail) with SMTP id _____wDnFys+V3BmcLM3BA--.12089S4; Mon, 17 Jun 2024 23:33:25 +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] Add accumulated call counter for memory allocation profiling Date: Mon, 17 Jun 2024 23:32:50 +0800 Message-Id: <20240617153250.9079-1-00107082@163.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CM-TRANSID: _____wDnFys+V3BmcLM3BA--.12089S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxCry5WF13CF4UGF18Xw1DKFg_yoW5Xr4rpF 4Y9F1UGan5JrykC3Wxtw1vqry3t3yjka43KrWjg395uF1YyrWDXayDKr1j9FyxCFy0gFnF vwnIg3y7C3WkA37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE1vVZUUUUU= X-Originating-IP: [111.35.186.64] X-CM-SenderInfo: qqqrilqqysqiywtou0bp/1tbiMwYBqmXAl5KK4wAAsX X-Rspamd-Queue-Id: 3BFF6C001C X-Stat-Signature: j5ns6cfw3mn96uj68h78byqstwzoc6x8 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718638416-858920 X-HE-Meta: U2FsdGVkX1/PdImrpnRHtKaFoBCgGKXsep0OdenI9e7f8twkosNkJ4DPvicalT8vf2sU01qECMSrOCgPzfn6+ixxMAufCWuip/khzfb/DdEituVpGJkRILXfdza9+PSgw9xNZ3wwpkX/TDVui9o7029fFaWkwaYczHBps/BklTXbUMQ1clOyKilFtGMmqEbB77boypnHVG0xjr2qVnbt4cvcZrYWv1diP9Wm1TtiLWqLmdtbqotrBT948SmLLQMzPxH2BSvGhN7xINztHxLHAcDDawVb244DnFZ1+SPRrOUZFeB84AGfVWyemBHpsotFNsn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HtFSHAXP6nwm12cLZAcp5rT+8398Q== 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: Accumulated call counter can be used to evaluate rate of memory allocation via delta(counters)/delta(time). This metrics can help analysis performance behaviours, e.g. tuning cache size, etc. Signed-off-by: David Wang <00107082@163.com> --- include/linux/alloc_tag.h | 11 +++++++---- lib/alloc_tag.c | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index abd24016a900..62734244c0b9 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -18,6 +18,7 @@ struct alloc_tag_counters { u64 bytes; u64 calls; + u64 accu_calls; }; /* @@ -102,14 +103,15 @@ 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 }; + struct alloc_tag_counters v = { 0, 0, 0 }; 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; + v.accu_calls += counter->accu_calls; } return v; @@ -145,6 +147,7 @@ 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); + this_cpu_inc(tag->counters->accu_calls); } static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag) diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 11ed973ac359..c4059362d828 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -66,8 +66,8 @@ 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, "# \n"); + seq_buf_printf(buf, "allocinfo - version: 1.1\n"); + seq_buf_printf(buf, "# \n"); } static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct) @@ -78,8 +78,7 @@ 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); - seq_buf_putc(out, ' '); - seq_buf_putc(out, '\n'); + seq_buf_printf(out, " %llu\n", counter.accu_calls); } static int allocinfo_show(struct seq_file *m, void *arg)