Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 15/20] perf symbol: Switch backing storage from rbtree to struct symbols array
Date: Tue, 10 Nov 2026 22:41:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-207840@kernel.org> (raw)
In-Reply-To: <20261110220803.2503416-16-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf symbol: missing end address tie-breaker in
  symbols__sort_cmp()
--

commit 0573604acc8bf2d5351a71f4fe63cacfd8d508e5
Author: Ian Rogers <irogers@google.com>

perf symbol: Switch backing storage from rbtree to struct symbols array

This commit replaces the embedded rbtree node in struct symbol with a
locked, lazily-sorted pointer array in struct symbols and updates symbol
iteration and lookup callers to use it.

> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index ec2a78873b903..66c5bd0386362 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -213,57 +213,153 @@ static int choose_best_symbol(struct symbol *syma, struct symbol *symb)

[ ... ]

> +static inline bool symbol__less_or_equal(const struct symbol *a, const struct symbol *b)
> +{
> +	return symbol__start(a) <= symbol__start(b);
> +}
> +
> +static int symbols__sort_cmp(const void *vlhs, const void *vrhs)
> +{
> +	const struct symbol *lhs = *((const struct symbol **)vlhs);
> +	const struct symbol *rhs = *((const struct symbol **)vrhs);
> +
> +	if (symbol__start(lhs) != symbol__start(rhs))
> +		return symbol__start(lhs) < symbol__start(rhs) ? -1 : 1;
> +	return 0;
> +}

[ ... ]

> @@ -397,97 +495,94 @@ static void symbol__set_idle(struct symbol *sym, bool idle)

[ ... ]

> -static struct symbol *symbols__find(struct rb_root_cached *symbols, u64 ip)
> +/*
> + * Binary search @symbols->symbols for a symbol covering @ip. Lazily sorts
> + * @symbols under @symbols->lock if unsorted.
> + */
> +static struct symbol *symbols__find(struct symbols *symbols, u64 ip)
>  {
> -	struct rb_node *n;
> +	int low, high;
> +	struct symbol *res = NULL;
>  
>  	if (symbols == NULL)
>  		return NULL;
>  
> -	n = symbols->rb_root.rb_node;
> +	symbols__sort_read_lock(symbols);
>  
> -	while (n) {
> -		struct symbol *s = rb_entry(n, struct symbol, rb_node);
> +	low = 0;
> +	high = (int)symbols->cnt - 1;
> +	while (low <= high) {
> +		int mid = low + (high - low) / 2;
> +		struct symbol *s = symbols->symbols[mid];
> +		u64 start = symbol__start(s);
> +		u64 end = symbol__end(s);
>  
> -		if (ip < symbol__start(s))
> -			n = n->rb_left;
> -		else if (ip > symbol__end(s) || (ip == symbol__end(s) && ip != symbol__start(s)))
> -			n = n->rb_right;
> -		else
> -			return s;
> +		if (ip < start)
> +			high = mid - 1;
> +		else if (ip > end || (ip == end && ip != start))
> +			low = mid + 1;
> +		else {
> +			res = s;
> +			break;
> +		}
>  	}
> +	up_read(&symbols->lock);
>  
> -	return NULL;
> +	return res;
>  }

[Severity: Medium]
Should symbol__less_or_equal() and symbols__sort_cmp() also compare
symbol__end() when two symbols share the same start address?

Because they only compare symbol__start(), a sized symbol [X, X + L) can
precede a zero-length alias [X, X) at the same start address (for example
when symbol_conf.allow_aliases is set or when both .symtab and .dynsym
define symbols at X).

If symbols__find() looks up an ip in (X, X + L) and mid lands on the
later [X, X) entry, ip > end advances low = mid + 1, skipping the
covering [X, X + L) entry to its left and returning NULL.

In addition, during ELF loading symbols__fixup_end() runs before
symbols__fixup_duplicate() and extends a trailing [X, X) entry up to the
next distinct symbol address Y, inflating its size before
choose_best_symbol() compares lengths, and map__fixup_end() can pick the
shorter symbol at symbols->symbols[symbols->cnt - 1] as the map end.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110220803.2503416-1-irogers@google.com?part=15

  reply	other threads:[~2026-11-10 22:41 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  7:52 [PATCH v1 0/7] perf symbol: Reference counting, flat array storage, and LRU shrinking Ian Rogers
2026-09-28  7:52 ` [PATCH v1 1/7] perf symbol: Add accessor functions for struct symbol fields Ian Rogers
2026-09-28  7:52 ` [PATCH v1 2/7] perf symbol: Remove symbol_conf.priv_size and negative-offset allocations Ian Rogers
2026-09-28  7:52 ` [PATCH v1 3/7] perf symbol: Switch backing storage from rbtree to struct symbols array Ian Rogers
2026-09-28  7:52 ` [PATCH v1 4/7] perf symbol: Add reference counting and DECLARE_RC_STRUCT(symbol) Ian Rogers
2026-09-28  7:52 ` [PATCH v1 5/7] perf symbol: Add LRU memory shrinking for symbols, DSOs, and machines Ian Rogers
2026-09-28  7:52 ` [PATCH v1 6/7] perf session: Periodically shrink symbols and DSOs during event processing Ian Rogers
2026-09-28  7:52 ` [PATCH v1 7/7] perf test symbols: Add tests for symbol and DSO LRU shrinking Ian Rogers
2026-09-28 15:37 ` [PATCH v1 0/7] perf symbol: Reference counting, flat array storage, and " Ian Rogers
2026-09-28 19:45 ` Alireza Haghdoost
2026-09-28 20:55   ` Ian Rogers
2026-09-28 21:51     ` Namhyung Kim
2026-09-28 22:04       ` Ian Rogers
2026-09-29  0:12         ` Alireza Haghdoost
2026-09-29 18:09           ` Namhyung Kim
2026-09-29 21:24             ` Alireza Haghdoost
2026-09-29 18:06         ` Namhyung Kim
2026-10-27 23:14 ` [PATCH v2 00/18] perf symbol: Reference counting, sorted arrays, and memory shrinking Ian Rogers
2026-10-27 23:14   ` [PATCH v2 01/18] perf bench internals: Add symbols and maps benchmarks Ian Rogers
2026-10-29 19:46     ` Alireza Haghdoost
2026-11-01  2:48     ` Namhyung Kim
2026-10-27 23:14   ` [PATCH v2 02/18] perf demangle: Add fast-path prefix checks for Rust and Java demanglers Ian Rogers
2026-10-27 23:14   ` [PATCH v2 03/18] perf symbol: Add accessor functions for struct symbol fields Ian Rogers
2026-10-30  4:08     ` Alireza Haghdoost
2026-10-27 23:14   ` [PATCH v2 04/18] perf map_browser: Compute symbol browser index on demand Ian Rogers
2026-10-27 23:14   ` [PATCH v2 05/18] perf db-export: Store symbol database IDs in a hashmap Ian Rogers
2026-10-27 23:15   ` [PATCH v2 06/18] perf annotate: Move struct annotation to a hashmap and remove symbol_conf.priv_size Ian Rogers
2026-10-30 12:51     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 07/18] perf symbol: Switch backing storage from rbtree to struct symbols array Ian Rogers
2026-10-30 13:12     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 08/18] perf symbol: Add reference counting and DECLARE_RC_STRUCT(symbol) Ian Rogers
2026-10-30 13:22     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 09/18] perf symbol: Optimize symbol sorting with natural-run merge sort and binary insertion Ian Rogers
2026-10-30 13:27     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 10/18] perf maps: Optimize tail insertion and small-append sorting Ian Rogers
2026-10-27 23:15   ` [PATCH v2 11/18] perf symbol-elf: Cache ELF program/section headers and defer symbol name lookup Ian Rogers
2026-10-30 13:32     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 12/18] perf rwsem: Add down_read_trylock() and down_write_trylock() Ian Rogers
2026-10-30 13:39     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 13/18] perf vdso: Constify dso parameter in dso__is_vdso() Ian Rogers
2026-10-27 23:15   ` [PATCH v2 14/18] perf machine: Protect machines->guests rbtree with a rw_semaphore Ian Rogers
2026-10-27 23:15   ` [PATCH v2 15/18] perf symbol: Add memory shrinking for symbols, DSOs, and machines Ian Rogers
2026-10-30 13:53     ` Alireza Haghdoost
2026-10-27 23:15   ` [PATCH v2 16/18] perf session: Add dso__session() and session-scoped allocation wrappers Ian Rogers
2026-10-27 23:15   ` [PATCH v2 17/18] perf symbol: Use session allocation wrappers in symbol, DSO, thread, and hist paths Ian Rogers
2026-10-27 23:15   ` [PATCH v2 18/18] perf test symbols: Add tests for symbol shrinking and session alloc wrappers Ian Rogers
2026-10-30 13:55     ` Alireza Haghdoost
2026-10-28 20:29   ` [PATCH v2 00/18] perf symbol: Reference counting, sorted arrays, and memory shrinking Ian Rogers
2026-10-30 14:02     ` Alireza Haghdoost
2026-10-30 16:10       ` Ian Rogers
2026-10-30 17:57         ` Ian Rogers
2026-10-31 17:22           ` David Laight
2026-11-10 22:07   ` [PATCH v3 00/20] perf symbol: Sorted arrays, DSO-owned lifetimes, " Ian Rogers
2026-11-10 22:07     ` [PATCH v3 01/20] perf map_browser: Fix browser index heap corruption by computing on demand Ian Rogers
2026-11-10 22:20       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 02/20] perf machine: Protect machines->guests rbtree with a rw_semaphore Ian Rogers
2026-11-10 22:22       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 03/20] perf vdso: Constify dso parameter in dso__is_vdso() Ian Rogers
2026-11-10 22:14       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 04/20] perf rwsem: Add down_read_trylock() and down_write_trylock() Ian Rogers
2026-11-10 22:33       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 05/20] perf map_symbol: Add struct dso_symbol and use for parent symbols Ian Rogers
2026-11-10 22:24       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 06/20] perf call-path: Use struct dso_symbol to retain symbol DSO lifetimes Ian Rogers
2026-11-10 22:20       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 07/20] perf db-export: Store symbol database IDs in a hashmap Ian Rogers
2026-11-10 22:25       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 08/20] perf annotate: Move struct annotation to a hashmap and remove symbol_conf.priv_size Ian Rogers
2026-11-10 22:26       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 09/20] perf bench internals: Add symbols benchmark Ian Rogers
2026-11-10 22:21       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 10/20] perf bench internals: Add maps benchmark Ian Rogers
2026-11-10 22:24       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 11/20] perf demangle: Add fast-path prefix checks for Rust and Java demanglers Ian Rogers
2026-11-10 22:23       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 12/20] perf symbol-elf: Cache ELF program/section headers and defer symbol name lookup Ian Rogers
2026-11-10 22:25       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 13/20] perf maps: Optimize tail insertion and small-append sorting Ian Rogers
2026-11-10 22:37       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 14/20] perf symbol: Add accessor functions for struct symbol fields Ian Rogers
2026-11-10 22:36       ` sashiko-bot
2026-11-10 22:07     ` [PATCH v3 15/20] perf symbol: Switch backing storage from rbtree to struct symbols array Ian Rogers
2026-11-10 22:41       ` sashiko-bot [this message]
2026-11-10 22:07     ` [PATCH v3 16/20] perf symbol: Optimize symbol sorting with natural-run merge sort and binary insertion Ian Rogers
2026-11-10 22:34       ` sashiko-bot
2026-11-10 22:08     ` [PATCH v3 17/20] perf symbol: Add memory shrinking for symbols, DSOs, and machines Ian Rogers
2026-11-10 22:46       ` sashiko-bot
2026-11-10 22:08     ` [PATCH v3 18/20] perf session: Add dso__session() and session-scoped allocation wrappers Ian Rogers
2026-11-10 22:46       ` sashiko-bot
2026-11-10 22:08     ` [PATCH v3 19/20] perf symbol: Use session allocation wrappers in symbol, DSO, thread, and hist paths Ian Rogers
2026-11-10 22:55       ` sashiko-bot
2026-11-10 22:08     ` [PATCH v3 20/20] perf test symbols: Add tests for symbol shrinking and session alloc wrappers Ian Rogers
2026-11-10 22:44       ` sashiko-bot

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-207840@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --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