From: Steven Rostedt <rostedt@goodmis.org>
To: Eugene Mavick <m@mavick.dev>
Cc: Will Deacon <will@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Boqun Feng <boqun@kernel.org>,
Mark Rutland <mark.rutland@arm.com>, Gary Guo <gary@garyguo.net>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@gentwo.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH v3 2/5] refcount: add ref_trace_final_put tracepoint
Date: Mon, 27 Jul 2026 16:27:43 -0400 [thread overview]
Message-ID: <20260727162743.55ca2d14@gandalf.local.home> (raw)
In-Reply-To: <20260711-refcount-final-put-trace-v3-2-674c8f03d9f9@mavick.dev>
On Sat, 11 Jul 2026 12:40:20 +0800
Eugene Mavick <m@mavick.dev> wrote:
> Add the ref_trace_final_put tracepoint to __refcount_sub_and_test() and
> refcount_dec_if_one()
>
> This tracepoint fires when a refcount_t reaches zero, capturing the caller
> address, the function name, and the refcount_t address.
>
> Signed-off-by: Eugene Mavick <m@mavick.dev>
> ---
> include/linux/refcount.h | 2 ++
> lib/refcount.c | 8 +++++++-
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/refcount.h b/include/linux/refcount.h
> index ba7657ced281..70d07a462da1 100644
> --- a/include/linux/refcount.h
> +++ b/include/linux/refcount.h
> @@ -107,6 +107,7 @@
> #include <linux/limits.h>
> #include <linux/refcount_types.h>
> #include <linux/spinlock_types.h>
> +#include <linux/ref_trace.h>
>
> struct mutex;
>
> @@ -393,6 +394,7 @@ bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp)
>
> if (old > 0 && old == i) {
> smp_acquire__after_ctrl_dep();
> + do_trace_ref_final_put(r);
> return true;
> }
>
> diff --git a/lib/refcount.c b/lib/refcount.c
> index a207a8f22b3c..cd7e32df3919 100644
> --- a/lib/refcount.c
> +++ b/lib/refcount.c
> @@ -7,6 +7,7 @@
> #include <linux/refcount.h>
> #include <linux/spinlock.h>
> #include <linux/bug.h>
> +#include <linux/ref_trace.h>
>
> #define REFCOUNT_WARN(str) WARN_ONCE(1, "refcount_t: " str ".\n")
>
> @@ -56,7 +57,12 @@ bool refcount_dec_if_one(refcount_t *r)
> {
> int val = 1;
>
> - return atomic_try_cmpxchg_release(&r->refs, &val, 0);
> + bool ret = atomic_try_cmpxchg_release(&r->refs, &val, 0);
> +
> + if (ret)
> + do_trace_ref_final_put(r);
> +
> + return ret;
Tracing should avoid adding any open conditionals. This is in the fast
path. No need to add an if statement that is only used when tracing is
enabled.
You can create another macro:
do_trace_ref_final_put_cond(ret, r);
And have that defined as:
#define do_trace_ref_final_put_cond(cond, obj) \
do { \
if (tracepoint_enabled(ref_trace_final_put)) { \
if (cond) \
do_ref_trace_final_put(_RET_IP_, __func__, obj);\
} \
} while (0)
That way the conditional is only checked if tracing is enabled.
-- Steve
> }
> EXPORT_SYMBOL(refcount_dec_if_one);
>
>
next prev parent reply other threads:[~2026-07-27 20:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 4:40 [PATCH v3 0/5] tracing: add ref_trace_final_put tracing Eugene Mavick
2026-07-11 4:40 ` [PATCH v3 1/5] tracing: add ref_trace_final_put tracepoint Eugene Mavick
2026-07-27 20:21 ` Steven Rostedt
2026-07-11 4:40 ` [PATCH v3 2/5] refcount: " Eugene Mavick
2026-07-27 20:27 ` Steven Rostedt [this message]
2026-07-11 4:40 ` [PATCH v3 3/5] percpu-refcount: add ref_trace_final_put trace Eugene Mavick
2026-07-11 4:40 ` [PATCH v3 4/5] kunit: add test for ref_trace_final_put Eugene Mavick
2026-07-11 4:40 ` [PATCH v3 5/5] MAINTAINERS: add entries " Eugene Mavick
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260727162743.55ca2d14@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=boqun@kernel.org \
--cc=cl@gentwo.org \
--cc=dennis@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=m@mavick.dev \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox