From nobody Wed Dec 17 06:31:35 2025 Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.219]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 605A5768E1 for ; Mon, 17 Jun 2024 15:33:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.50.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718638438; cv=none; b=T6u3GLFCvEWJjtWrPAEeNLHLMY46ysWLS8SWXJwn9AwkK6dp56bFZUaaSObFyS/Vw+abzZ2Wklog9bQSfaBolVStCkrVUTE69dexJ+Do1X2Snh1PTT3c4jl7NeUdjyggQfehjip8cwg7C3H513+dpUNNyi5lxickvmR+KYw0kEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718638438; c=relaxed/simple; bh=pHiu+hAd4XU2vX1VrkxJP6YEyAUBEy25VGv1TWYVPcU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bH62TJUwfEE4V3nxHB1tyAwq5h/SRshXDNTzNebdC7eJhF8StHfmA810yTiQkq/9fyCG3QA9XCyPExq2ohg1yDNbevUhnrPzcHO3MNc8+hgiB2MApO96RVZF8/9kL5r07KeAF7X4p5U3q7KLFZfnqAkbYDEaSEYMBY258bb0Ga0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=jyJLQ0yO; arc=none smtp.client-ip=45.254.50.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="jyJLQ0yO" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDnFys+V3BmcLM3BA--.12089S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxCry5WF13CF4UGF18Xw1DKFg_yoW5Xr4rpF 4Y9F1UGan5JrykC3Wxtw1vqry3t3yjka43KrWjg395uF1YyrWDXayDKr1j9FyxCFy0gFnF vwnIg3y7C3WkA37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE1vVZUUUUU= X-CM-SenderInfo: qqqrilqqysqiywtou0bp/1tbiMwYBqmXAl5KK4wAAsX Content-Type: text/plain; charset="utf-8" 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; }; =20 /* @@ -102,14 +103,15 @@ static inline bool mem_alloc_profiling_enabled(void) =20 static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *t= ag) { - struct alloc_tag_counters v =3D { 0, 0 }; + struct alloc_tag_counters v =3D { 0, 0, 0 }; struct alloc_tag_counters *counter; int cpu; =20 for_each_possible_cpu(cpu) { - counter =3D per_cpu_ptr(tag->counters, cpu); - v.bytes +=3D counter->bytes; - v.calls +=3D counter->calls; + counter =3D per_cpu_ptr(tag->counters, cpu); + v.bytes +=3D counter->bytes; + v.calls +=3D counter->calls; + v.accu_calls +=3D counter->accu_calls; } =20 return v; @@ -145,6 +147,7 @@ static inline void __alloc_tag_ref_set(union codetag_re= f *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); } =20 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"); } =20 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) =20 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); } =20 static int allocinfo_show(struct seq_file *m, void *arg) --=20 2.39.2