All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Alireza Haghdoost <haghdoost@uber.com>
Cc: Ian Rogers <irogers@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 0/7] perf symbol: Reference counting, flat array storage, and LRU shrinking
Date: Tue, 29 Sep 2026 11:09:56 -0700	[thread overview]
Message-ID: <arv-9NWWZ14TG5Te@google.com> (raw)
In-Reply-To: <CA+w=M=S3USeLyFNaHSjHL+cmzssWk2Bygahetzr0dNU55TZEMw@mail.gmail.com>

On Mon, Sep 28, 2026 at 05:12:35PM -0700, Alireza Haghdoost wrote:
> On Mon, Sep 28, 2026 at 3:05 PM Ian Rogers <irogers@google.com> wrote:
> > > I think many of this memory overhead come from the symbol string.
> > > Probably we don't use most of them.  Then would it be nice if we can
> > > lazy-load the strings?
> 
> Namhyung, your guess is right. I counted live symbol allocations in eager mode
> on the sample fixture. At the peak, 986,688 symbols take 258 MiB:
> 
>    names (demangled, avg 210 bytes)   197 MiB   77%
>    struct symbol (48 bytes each,       45 MiB   18%
>      24 of them the rb_node)
>    malloc overhead                     15 MiB    6%
> 
> That is most of the 335 MiB max RSS. With --lazy-load-symbols, only
> 2,928 symbols are created (0.5 MiB), with identical output, and max
> RSS is 108 MiB.

Thanks for checking this!

> 
> > > Without the string (and the priv part), now it has a fixed size so it
> > > should be saved in an array directly.
> 
> That is close to what patch 5/6 of my v3 does. Its index is a sorted
> array of fixed-size entries:
> 
>    struct sym_idx {
>            u64     start;
>            u64     end;
>            u32     name_off;
>            u8      binding;
>            u8      type;
>            u8      flags;
>    };
> 
> That is 24 bytes per symbol. The name is read from the string table
> and demangled only when a sample lands in the symbol. The difference
> from your description is that v3 then creates a regular struct symbol
> for the hit and inserts it in the rb-tree, because the rest of perf
> holds struct symbol pointers. If the entry itself were the symbol,
> with the name as a pointer/offset union, that extra step would go
> away. Ian's patch 1 would help: once every name access goes through
> symbol__name(), that accessor is the only place that has to resolve
> an offset.

I'm curious if name_off would work well for PLT symbols which come from
the dynamic symbol table.  Probably you need to handle them differently.

> 
> > > Probably we can add a limit there
> > > and print it with offset when it doesn't have the name.
> 
> Agreed, that is better than [unknown]. The symbol boundaries are still
> known, so the frame can be printed as an offset and resolved offline.
> I can do the same for the byte cap in v4.
> 
> >
> > We load all symbols instead of lazily because we need the end of a
> > symbol, which we can only determine by processing the entire symbol
> > table as the end of one symbol is the start of the next.
> >
> 
> Ian, I think most symbols don't need the next one for their end. ELF
> symbols have st_size, so the end is start + st_size. Only zero-size
> symbols take the next symbol's start. The whole table still has to be
> scanned to find the symbol for an address, because .symtab isn't
> sorted by address, so an address window would scan it again each time
> it grows. The v3 index scans it once, sorts the entries and fixes up
> the ends there, but keeps only the 24-byte entries, not the names.
> 
> On which kernel symbol is right in the nf_tables example: the sample
> is at 0xffffffffc0c4b280, and /proc/kallsyms has nft_do_chain at
> 0xffffffffc0c4b0b0 and the next nf_tables symbol at
> 0xffffffffc0c4b4e0, so your series is right. The last dca symbol
> starts at 0xffffffffc0c4aa50, and symbols__fixup_end() extends it to
> 0xffffffffc0c4c000, over the first page of nf_tables. I've sent the
> fix separately:
> https://lore.kernel.org/all/20260928-haghdoost-perf-symbols-fixup-module-end-v1-1-0a70d1edd401@uber.com/

Thanks for the fix!
Namhyung


  reply	other threads:[~2026-09-29 18:09 UTC|newest]

Thread overview: 17+ 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 [this message]
2026-09-29 21:24             ` Alireza Haghdoost
2026-09-29 18:06         ` Namhyung Kim

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=arv-9NWWZ14TG5Te@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=haghdoost@uber.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.