Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Li Pengfei" <ljdlns1987@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v8 3/5] tracing: Add stackmap statistics interface
Date: Sat, 07 Nov 2026 06:04:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-202646@kernel.org> (raw)
In-Reply-To: <20261107055139.3138633-4-lipengfei28@xiaomi.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] tracing: undercounted fallbacks in ftrace_stackmap_get_cookie()
  on pool race
--

commit 668d6dcc7b8dc107b88cd7cdf37f1ed69e5f66bc
Author: Pengfei Li <lipengfei28@xiaomi.com>

tracing: Add stackmap statistics interface

This commit adds a tracefs stack_map_stat file and per-CPU counters to
report stackmap generation, capacity, element usage, and lookup successes
and fallbacks.

> diff --git a/kernel/trace/trace_stackmap.c b/kernel/trace/trace_stackmap.c
> index b02eb22c76a98..5d2a406f39b93 100644
> --- a/kernel/trace/trace_stackmap.c
> +++ b/kernel/trace/trace_stackmap.c

[ ... ]

> @@ -254,8 +276,10 @@ bool ftrace_stackmap_get_cookie(struct ftrace_stackmap *smap,
>  		probes++;
>  	}
>  
> +	stackmap_count(smap->fallbacks);
>  	return false;
>  found:
> +	stackmap_count(smap->successes);
>  	*cookie = ((u64)smap->generation << FTRACE_STACKMAP_COOKIE_GEN_SHIFT) | idx;
>  	return true;
>  }

[Severity: Low]
Can ftrace_stackmap_get_cookie() undercount smap->fallbacks when the
element pool runs out during a concurrent insert?

When two CPUs pass the smap->next_elt < smap->max_elts check for the last
available element, both claim an entry->key slot via cmpxchg(), and
stackmap_get_elt() returns NULL for the loser:

kernel/trace/trace_stackmap.c:ftrace_stackmap_get_cookie() {
    ...
		if (test_key == key_hash) {
			val = stackmap_load_elt(entry);
			/* Insert in progress; from NMI it may be the interrupted one. */
			if (!val)
				return false;
    ...
		} else if (!test_key) {
			if (atomic_read(&smap->next_elt) >= smap->max_elts)
				break;
			/* Lost the race; the slot may now hold this stack. */
			if (cmpxchg(&entry->key, 0, key_hash) != 0)
				continue;

			val = stackmap_get_elt(smap);
			if (!val)
				break;
    ...
}

That leaves entry->key set to key_hash with entry->val still NULL.  Every
subsequent lookup for that stack (or any stack with the same key_hash
probing through that slot) then hits test_key == key_hash, sees !val, and
returns false early without incrementing smap->fallbacks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261107055139.3138633-1-lipengfei28@xiaomi.com?part=3

  reply	other threads:[~2026-11-07  6:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07  5:51 [PATCH v8 0/5] tracing: Add stack trace deduplication for the ring buffer Li Pengfei
2026-11-07  5:51 ` [PATCH v8 1/5] tracing: Add lock-free stackmap for stack trace deduplication Li Pengfei
2026-11-07  5:51 ` [PATCH v8 2/5] tracing: Use the stackmap from the ftrace stack recording path Li Pengfei
2026-11-07  6:17   ` sashiko-bot
2026-11-07 22:35   ` kernel test robot
2026-11-08  7:24     ` Pengfei Li
2026-11-07  5:51 ` [PATCH v8 3/5] tracing: Add stackmap statistics interface Li Pengfei
2026-11-07  6:04   ` sashiko-bot [this message]
2026-11-07  6:28     ` Li Pengfei
2026-11-07  5:51 ` [PATCH v8 4/5] Documentation: tracing: Document the ftrace stackmap Li Pengfei
2026-11-07  5:51 ` [PATCH v8 5/5] selftests/ftrace: Add a stackmap basic functionality test Li Pengfei
2026-11-07  6:07   ` sashiko-bot
2026-11-07  6:28     ` Li Pengfei

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=sashiko-outbox-202646@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=ljdlns1987@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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