Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH v9 0/7] perf script: Lazy symbol loading
@ 2026-11-24 19:28 Alireza Haghdoost via B4 Relay
  2026-11-24 19:28 ` [PATCH v9 1/7] perf symbols: Split out name-independent duplicate symbol selection Alireza Haghdoost via B4 Relay
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Alireza Haghdoost via B4 Relay @ 2026-11-24 19:28 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: linux-perf-users, linux-kernel, Alireza Haghdoost

perf script loads the entire ELF symbol table of every DSO that appears
in a sample, and keeps each symbol, with its demangled name, until
process exit. Most of those symbols are never sampled. On a large
profile this turns symbol loading into the main memory cost of perf
script, and in a memory-constrained cgroup into an OOM kill.

With this series, perf script, perf report and perf top
--lazy-load-symbols read a symbol name only when a sample needs it. On a
perf script run over a 45,073-sample callchain profile of a large C++
service (about 1M symbols), the output is identical in all three cases
(medians of eleven runs):

                                      time    max RSS
  perf-tools-next                     2.24 s  305 MiB
  v9                                  2.26 s  315 MiB
  v9 --lazy-load-symbols              1.97 s  164 MiB

Eager loading remains the default, and costs 8 more bytes per symbol for
the name pointer. Lazy loading covers userspace ELF .symtab and .dynsym.
The kernel, modules, PPC64 .opd and .gnu_debugdata still load names
eagerly. Names are read from the file that perf loaded the symbols
from, so the output is the same as with eager loading as long as the
binaries do not change while perf runs.

The patches:

  [1/7] Split the size, type and binding checks out of
        choose_best_symbol(), so that the loader can tell which aliases
        need their names. No functional change. Unchanged from v8,
        reviewed by Ian.

  [2/7] Make the symbol name a pointer instead of a flexible array, so
        that a name can be set after the symbol is in the symbol array.
        Reviewed by Ian; only the commit message changed.

  [3/7] Add lazy symbol names to the symbol code: the DSO address
        lookups read the name of the symbol they return, and walks and
        lookups by name read all names of the DSO first. Nothing
        creates such symbols yet.

  [4/7] Add --lazy-load-symbols to perf script, which makes the ELF
        loader create symbols with lazy names.

  [5/7] Add --lazy-load-symbols to perf report and perf top.

  [6/7] Unit tests.

  [7/7] Shell tests, including parity with eager loading for perf
        script and perf report.

This series is rebased onto the first six patches of Ian's v8 [1], now
in perf-tools-next. Ian's v9 [2] applies on top of it with one trivial
conflict in struct dso, and the symbol and lazy loading tests pass on
the combination. I'll rebase if his patches land first.

[1] https://lore.kernel.org/linux-perf-users/20261122050405.80335-1-irogers@google.com/
[2] https://lore.kernel.org/linux-perf-users/20261124032902.3859564-1-irogers@google.com/

Changes in v9:

- Rebase onto current perf-tools-next, which has Ian's symbol array and
  the fix that keeps cached debuginfo in perf's mount namespace. 3/7
  now tracks per DSO whether all its names are loaded, since a DSO
  sorted by name can still have lazy names.
- Drop v8 4/7, the check of the symbol table file, and its tests
  (Namhyung). The man pages say that the output equals eager loading as
  long as the binaries do not change while perf runs.
- 4/7 (was 5/7): drop the kmodule check, use pr_debug2(), and add
  parentheses around multi-line expressions (Namhyung).
- 4/7: create lazy names only for a symbol table file that perf can
  reopen by the same name in its own mount namespace, since perf top's
  sample thread cannot switch namespaces.
- New 5/7: --lazy-load-symbols for perf report and perf top (Namhyung).
- 6/7: drop the file check tests.
- 7/7: rename script_lazy_load_symbols.sh to lazy_load_symbols.sh, and
  add perf report parity and a case for a process in another mount
  namespace.

Previous versions:

v8: https://lore.kernel.org/all/20261121-perf-symbol-memory-send-v8-0-370561cbb5a7@uber.com/
v7: https://lore.kernel.org/all/20261113-perf-symbol-memory-send-v7-0-d992eced9f9c@uber.com/
v6: https://lore.kernel.org/all/20261028-perf-symbol-memory-send-v6-0-7e90415f0101@uber.com/
v5: https://lore.kernel.org/all/20261005-perf-symbol-memory-send-v5-0-165dceb2b049@uber.com/
v4: https://lore.kernel.org/all/20261002-perf-symbol-memory-send-v4-0-0a592bb2539e@uber.com/
v3: https://lore.kernel.org/all/20260925-perf-symbol-memory-send-v3-0-3e4e234c363b@uber.com/
v2: https://lore.kernel.org/all/20260919-perf-symbol-memory-send-v2-0-495b8f00ad7c@uber.com/
v1: https://lore.kernel.org/all/20260915-perf-symbol-memory-send-v1-0-1d3360e21f07@uber.com/

---
Alireza Haghdoost (7):
      perf symbols: Split out name-independent duplicate symbol selection
      perf symbols: Point to the symbol name instead of embedding it
      perf symbols: Add lazy symbol names
      perf script: Add --lazy-load-symbols to load symbol names lazily
      perf report/top: Add --lazy-load-symbols
      perf test: Add lazy symbol loading unit tests
      perf test: Add lazy symbol loading shell tests

 tools/perf/Documentation/perf-report.txt           |   9 +
 tools/perf/Documentation/perf-script.txt           |   9 +
 tools/perf/Documentation/perf-top.txt              |  10 +
 tools/perf/builtin-report.c                        |   2 +
 tools/perf/builtin-script.c                        |   2 +
 tools/perf/builtin-top.c                           |   2 +
 tools/perf/tests/Build                             |   1 +
 tools/perf/tests/builtin-test.c                    |   1 +
 tools/perf/tests/shell/lazy_load_symbols.sh        | 243 ++++++++
 tools/perf/tests/shell/lazy_load_symbols_parity.sh | 462 +++++++++++++++
 tools/perf/tests/shell/lib/lazy_names.sh           |  20 +
 tools/perf/tests/symbol-lazy.c                     | 647 +++++++++++++++++++++
 tools/perf/tests/tests.h                           |   1 +
 tools/perf/ui/browsers/map.c                       |   2 +-
 tools/perf/ui/stdio/hist.c                         |   1 +
 tools/perf/util/dso.h                              |  28 +-
 tools/perf/util/symbol-elf.c                       | 218 ++++++-
 tools/perf/util/symbol-minimal.c                   |   6 +
 tools/perf/util/symbol.c                           | 138 ++++-
 tools/perf/util/symbol.h                           |  29 +-
 tools/perf/util/symbol_conf.h                      |   1 +
 tools/perf/util/symsrc.h                           |   2 +
 22 files changed, 1804 insertions(+), 30 deletions(-)
---
base-commit: 964e8b1c9c795982886a6778cb0cd73c901ca4ca
change-id: 20260915-perf-symbol-memory-send-e7cfca1ac3d9

Best regards,
--  
Alireza Haghdoost <haghdoost@uber.com>



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-24 19:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 19:28 [PATCH v9 0/7] perf script: Lazy symbol loading Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 1/7] perf symbols: Split out name-independent duplicate symbol selection Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 2/7] perf symbols: Point to the symbol name instead of embedding it Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 3/7] perf symbols: Add lazy symbol names Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 4/7] perf script: Add --lazy-load-symbols to load symbol names lazily Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 5/7] perf report/top: Add --lazy-load-symbols Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 6/7] perf test: Add lazy symbol loading unit tests Alireza Haghdoost via B4 Relay
2026-11-24 19:28 ` [PATCH v9 7/7] perf test: Add lazy symbol loading shell tests Alireza Haghdoost via B4 Relay
2026-11-24 19:43 ` [PATCH v9 0/7] perf script: Lazy symbol loading sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox