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 EFFE7C27C4F for ; Sun, 30 Jun 2024 19:33:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 595E36B0092; Sun, 30 Jun 2024 15:33:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 544E86B0095; Sun, 30 Jun 2024 15:33:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 433E16B0096; Sun, 30 Jun 2024 15:33:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 20B1A6B0092 for ; Sun, 30 Jun 2024 15:33:29 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B34F2A02EB for ; Sun, 30 Jun 2024 19:33:28 +0000 (UTC) X-FDA: 82288554096.05.4C7D7C1 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by imf25.hostedemail.com (Postfix) with ESMTP id D5837A0003 for ; Sun, 30 Jun 2024 19:33:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=W7Qo2j8c; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of surenb@google.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719775989; a=rsa-sha256; cv=none; b=bh3YvDmV2umZN7kCk5spsfxo6fGNCMuL4V9JgdGPCSd2Gx/rOmTpc+wuyHaiMvyEiamC0k UBy6mZshyeFEhz0hgx0juYaH/AAcO+FWvNhxbDGXeJ2WMXd0GdsZmsiGdMQgVSWX7ME/1C DyCJdl2WoTboaiObxB/QEBEVLKEYKsM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=W7Qo2j8c; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of surenb@google.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719775989; 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=g5jFZosVLQ5njavRkbtKkWFfcQaMI48MvNy4kw/eY0g=; b=u0BS5s6g/OV4GBHWswGK7Loa4BQHOwuDXtQAvIQSOyDq0Gg9YPA7AJeSSbt1MqFiLPnFXc kBnU9UEnEzD4MYzz65tAGNOAV3oYsEq0e08af0O5t3s3nqIHF5L13GwJKjqpsIjDJTt4LG ZFqFlGsT9cgruFMTx1H2kSzaj9Qw2h0= Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-64b3655297aso18678087b3.1 for ; Sun, 30 Jun 2024 12:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719776006; x=1720380806; darn=kvack.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=g5jFZosVLQ5njavRkbtKkWFfcQaMI48MvNy4kw/eY0g=; b=W7Qo2j8cH4OMQeK/koSCXxuHb5+cOaIGTpp58Wz2qPh7F+RPACF27b+QV7/FjcTie4 Yv/9sQUjQa/9Ii2SBMVE3eer57KE8i0o+PVAa6fKrbFdkVlQ+CRhUwrPYzYG+4/iuVii hAEx9Cse1HLRFoLlCFmSLbCIUKchHPL/gVinqJV1RJKT2Yhynjb2F6uPGKMmb66xOnTm yeNRMo7M8ASV74Zt3qXrVieA+XBzjvHiuxidmb+GYaTYB+WfEtepgqlzejuNuGfyGcur Yn/EAXcQbGoyYybHoarR0QsZbjuIoIDephxM0rhEBWN05Xx26FZerLKqwyXoQ9c7t90E M5/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719776006; x=1720380806; 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=g5jFZosVLQ5njavRkbtKkWFfcQaMI48MvNy4kw/eY0g=; b=QHcVPKMk3Wiu27wt7FX0ucKN6aJcO5gj6qhxiJ2/BKx9ofc5JEt2/vxvPdieWBX20d jbKRr6KtmRcfZzx64sUKURTzzl43+Q9mKgKDXBb0NClyiVCi86a+5TgLSsU/oPy24EsE xRBbgmyNAWI2fiFeyoVK7gw22Ge47m4vSkJ6DZeRxqsza2jt95zZ/gxKg8UX7tVMdtYa Ujg8XSUAic7SBwvIgEBoqa8CL1w3lprlS+AUlsb7d80xCm2RJGcpyZBdrs32WQomdbnu 4+VrzPop25t03ygSZyttDuYIIIKKkQfjVj22NS22kDYLRzMfRRuYjDX2VFHVlVcOay3B jJig== X-Forwarded-Encrypted: i=1; AJvYcCWxMIiTKB9nZll3RwawL4rPvhGk2sY12mkoqlDwf0NpSuL9mYMTr3zwTO4I1DP2Kn47yRhVtsmMpXtZ9XLoD8+GHrc= X-Gm-Message-State: AOJu0Ywl9k7Ng0B9L8a7SQ6eXcxj+Z1fjoc2R9rg4SAOlYdtKQHzPk1l 9ORhXq7EVnag47zjPdqCluQ1wiPcIcXJGFiLIfNP9fIf/Ck/oFBlYoUgQw/uA2YnwQSFwDyMjX2 EfRFqL8g1+ydUbnw7p1IeUtCMlEgvIbdFmj3N X-Google-Smtp-Source: AGHT+IHPO34FOZWGU5tBOTf9EpO302U9/tKO9iLfbVU2UZG2QqSR0FEip02DdXEWZTJJiYBRKdhq/JWqYK64DKKvbmU= X-Received: by 2002:a05:690c:ec1:b0:64a:e7ec:f3d with SMTP id 00721157ae682-64c72682f11mr43522187b3.18.1719776005709; Sun, 30 Jun 2024 12:33:25 -0700 (PDT) MIME-Version: 1.0 References: <20240617153250.9079-1-00107082@163.com> In-Reply-To: <20240617153250.9079-1-00107082@163.com> From: Suren Baghdasaryan Date: Sun, 30 Jun 2024 12:33:14 -0700 Message-ID: Subject: Re: [PATCH] Add accumulated call counter for memory allocation profiling To: David Wang <00107082@163.com> Cc: kent.overstreet@linux.dev, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D5837A0003 X-Stat-Signature: i8u3kbbq97xib1xndp5np5knizjkgcon X-Rspam-User: X-HE-Tag: 1719776006-88101 X-HE-Meta: U2FsdGVkX1/Jkbz8tXYvwOMcXV+1DjyRNoMSg/pO5VW/YbiocN+x4TA5pLCNosni+q9QM9ogOISq3iLmA+pP+KoyxpfjpRmxK1LiTPZerCJLD4HUkVSuI9+Wp8b5uEf2/Vyxf3zJ3GNyJ/Xr9fhSmcMrIjnSfoxmcDBvl8JimGTx2AXJEpJkZVzZiYvqlGnln/Q4pZoa8jqInmWOC3LJjENgocsrwLaqiFUc76HUqo7kAkarO0jM6GsnwygeEuK8Hr6FnJrQ/mYPnINCFiIULzhyGsJfhCM/eT2vf81et7mNX/LoMkhfLF50EHqrMsZvulPj+43Z+/9YyIUIL6r4O8hGSXcBRrOQYvpSjUc159xq9L8TnBypZ0ZTI53iHHcZno80rl7W51/aMDCBVPqjmHA10VFRGjdCuM1wPkcC0LkquAQk8XYI/W0NnwafxUS5fzlFseBUgcxnRaCTNVhIhApD6kPmWbTklFT3XquRjyMOKf1a6inl2bYpqDmEDewMUrx8gzAiU0oEbAVt7d9WG0COwvoOzSMlxXOVdr2cdSXA80eM1VQDy+6+qORqZfalG4U/7N/6BKyHevd3r0WyP5l0aQpO5LvAwoR6y9kv2IpSbEIcS1tQmfPQMudIGJdSVEGsC4KU8KgqQq7oYEBpGKepcPrWGaMwxeaOIw238rdVIfqoHoMdKtX4d5MHvpDI4Jl5GmvnYiMuFxGfVcREv7pwJMVVPHrJzG4w4ELVNBPx4wZSRIrN+evMevOKKBJ3uWmZTB7Q4mglWACdT32eGC4jjpPq9bWr9XjfZwDY6jwvFV5HMtOtjKxx1KFKZOw8St0s/GazlcfSwks+6A1N+XZG+r/qmlPBiX8cypwtCyTvxMGYAD0gz9/9VFNNOWhB2r9AuH3f5mGAvL2NZ8hLTnP9+VYwjc8BFFYILiD4Fydb9s+zvCckZHw/o1ZS/9/og4Bp0QVxFTBqAEE+g0B niQPWlJm smuJJcgYETHrzpxhvhfBRyaNRjt7Gcv1cLb0uE8p+QpBTOb3k0cx47pQxBOoP/+TV5vZH1xByDTeawrClEvR/fo2F233wQcp3JgVIolhnr0Ulku8rwPfX3bC9PyEy9CVijVyJuD8HIL62Wn/CrXPIJFBshZPryXOc4VXsW9k08N9g7aFj9ufZiDeN2Zz5GYPyhcDfRriga1wQUY5YKpy7eJACtAaUwrOFVn6WdoQxgJBNIUkEqLnKpjC32RmUFNk7qucuRr84A+uv5s83puHn9a9E9qeerNyrYsyJB9zhjtXV7yrWTbqnX8fwDA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 Mon, Jun 17, 2024 at 8:33=E2=80=AFAM David Wang <00107082@163.com> wrote= : > > 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. Sorry for the delay, David. IIUC with this counter you can identify the number of allocations ever made from a specific code location. Could you please clarify the usage a bit more? Is the goal to see which locations are the most active and the rate at which allocations are made there? How will that information be used? I'm a bit cautious here because each counter will take more space and use some additional cpu cycles. Thanks, Suren. > > 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 =3D { 0, 0 }; > + struct alloc_tag_counters v =3D { 0, 0, 0 }; > struct alloc_tag_counters *counter; > int cpu; > > 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; > } > > 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 dec= remented. > */ > 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 allo= c_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 *ar= g) > 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, stru= ct 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) > -- > 2.39.2 >