perf script: Lazy symbol loading
Get series with b4
b4 am [email protected] change-id 20260915-perf-symbol-memory-send-e7cfca1ac3d9Versions newest first
- v8 Latest7 patches 5 repliesIn review
- v74 patches 2 repliesSuperseded
- v65 patches 10 repliesApplied
Earlier versions · 5
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v5 | 5 patches | 6 replies | Superseded | |
| v4 | 5 patches | 7 replies | Superseded | |
| v3 | 6 patches | 8 replies | Superseded | |
| v2 | 4 patches | 6 replies | Superseded | |
| v1 | 4 patches | 9 replies | Superseded |
Changes in v8 from the cover letter
- Rebase onto current perf-tools-next, which has Ian's annotation and ELF loader changes.
- Split v7 3/4 for review (Namhyung): 3/7 adds lazy names to the symbol code, 4/7 adds the check of the symbol table file, and 5/7 adds the option and makes the ELF loader create lazy names. The tests are in 6/7 (unit) and 7/7 (shell).
- 4/7: Also accept a file whose device, inode, size, mtime or ctime changed if it has the build ID of the DSO and its .strtab and .dynstr did not move, such as a copy of the same build (Namhyung). The identity is still checked first, since reading the build ID at each reopen more than doubles the time of the worst case.
- 4/7: Compare the ctime too, so a file copied over in place with its size and mtime kept (cp -p) is not taken for the same file. Treat a string table section that no longer exists or is compressed as another file.
- 4/7: Warn once when the file cannot be opened or checked, rather than only in debug output, and try again for later names, since the failure can be temporary.
- 5/7: Do not skip the .dynsym copies of lazy .symtab symbols. Skipping them changed the shape of the rb-tree, which broke lookups past a nested entry point and the PLT name of an exported IFUNC. This replaces the v7 fix for a zero-size symbol before a copy (Sashiko). Duplicate selection now reads the names of each copy, so on the profile above, where one binary exports most of its symbols, lazy loading keeps its memory saving but loses most of the run time it saved in v7. Most of that time goes to reading each name with its own pread(). As discussed with Namhyung, a later series will let the DSO data cache read the symbol table file, and names will be read through it. A prototype with a small read cache gets back about two thirds of the v7 speedup for about 1.5 MiB more RSS.
- 6/7: Add tests for a file overwritten in place, for a copy with the same build, with moved or missing string tables, and of another build, for a failed open, and for a copy whose build ID cannot be read.
- 7/7: Add parity cases for a zero-size symbol before a copy, nested entry points, and an exported IFUNC with aliases.
Patches in v8 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | perf symbols: Split out name-independent duplicate symbol selectiontools/ tools/ | +25 | 0 replies | |
| 2/7 | perf symbols: Point to the symbol name instead of embedding ittools/ tools/ tools/ | +3 | 0 replies | |
| 3/7 | perf symbols: Add lazy symbol namestools/ tools/ tools/ +5 more | +237 | 0 replies | |
| 4/7 | perf symbols: Check the file before reading lazy symbol namestools/ tools/ tools/ | +189 | 2 replies | |
| 5/7 | perf script: Add --lazy-load-symbols to load symbol names lazilytools/ tools/ tools/ | +110 | 2 replies | |
| 6/7 | perf test: Add lazy symbol loading unit teststools/ tools/ tools/ +1 more | +966 | 0 replies | |
| 7/7 | perf test: Add lazy symbol loading shell teststools/ tools/ tools/ | +657 | 0 replies |
Reviews trailers per patch
2 of 7 patches have a Reviewed-by or Acked-by.
| Patch | Ian Rogers |
|---|---|
| 1/7 | R-b |
| 2/7 | R-b |
| 3/7 | |
| 4/7 | |
| 5/7 | |
| 6/7 | |
| 7/7 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v8 0/7] perf script: Lazy symbol loading
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 --lazy-load-symbols reads 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 3.70 s 319 MiB v8 3.75 s 327 MiB v8 --lazy-load-symbols 3.56 s 174 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.
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 v7, 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 rb-tree. Unchanged from v7, reviewed by Ian.
[3/7] Add lazy symbol names to the symbol code: the DSO lookups read
the name of the symbol they return. Nothing creates such symbols yet.
[4/7] Check that the symbol table file is still the one perf loaded
before reading names from it. Nothing records a file yet.
[5/7] Add --lazy-load-symbols, which makes the ELF loader create
symbols with lazy names and record the file for the check.
[6/7] Unit tests for lazy names and for the file check.
[7/7] Shell tests, including parity with eager loading.
perf-tools-next now has the first three patches of Ian's series [1]. Its later patches replace the symbol rb-tree with an array, which would shrink each symbol further. They conflict with this series, since the name loading in 3/7 and the alias name loading in 5/7 walk that rb-tree. This series does not depend on them, and I'll rebase on them if they land first.
[1] https://lore.kernel.org/all/[email protected]/
Changes in v8:
- Rebase onto current perf-tools-next, which has Ian's annotation and ELF loader changes.
- Split v7 3/4 for review (Namhyung): 3/7 adds lazy names to the symbol code, 4/7 adds the check of the symbol table file, and 5/7 adds the option and makes the ELF loader create lazy names. The tests are in 6/7 (unit) and 7/7 (shell).
- 4/7: Also accept a file whose device, inode, size, mtime or ctime changed if it has the build ID of the DSO and its .strtab and .dynstr did not move, such as a copy of the same build (Namhyung). The identity is still checked first, since reading the build ID at each reopen more than doubles the time of the worst case.
- 4/7: Compare the ctime too, so a file copied over in place with its size and mtime kept (cp -p) is not taken for the same file. Treat a string table section that no longer exists or is compressed as another file.
- 4/7: Warn once when the file cannot be opened or checked, rather than only in debug output, and try again for later names, since the failure can be temporary.
- 5/7: Do not skip the .dynsym copies of lazy .symtab symbols. Skipping them changed the shape of the rb-tree, which broke lookups past a nested entry point and the PLT name of an exported IFUNC. This replaces the v7 fix for a zero-size symbol before a copy (Sashiko). Duplicate selection now reads the names of each copy, so on the profile above, where one binary exports most of its symbols, lazy loading keeps its memory saving but loses most of the run time it saved in v7. Most of that time goes to reading each name with its own pread(). As discussed with Namhyung, a later series will let the DSO data cache read the symbol table file, and names will be read through it. A prototype with a small read cache gets back about two thirds of the v7 speedup for about 1.5 MiB more RSS.
- 6/7: Add tests for a file overwritten in place, for a copy with the same build, with moved or missing string tables, and of another build, for a failed open, and for a copy whose build ID cannot be read.
- 7/7: Add parity cases for a zero-size symbol before a copy, nested entry points, and an exported IFUNC with aliases.
Previous versions:
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
---
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 symbols: Check the file before reading lazy symbol names perf script: Add --lazy-load-symbols to load symbol names lazily perf test: Add lazy symbol loading unit tests
perf test: Add lazy symbol loading shell tests
tools/perf/Documentation/perf-script.txt | 11 + tools/perf/builtin-script.c | 2 + tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/lazy_load_symbols_parity.sh | 447 ++++++++++ tools/perf/tests/shell/lib/lazy_names.sh | 20 + tools/perf/tests/shell/script_lazy_load_symbols.sh | 190 ++++ tools/perf/tests/symbol-lazy.c | 963 +++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/ui/browsers/map.c | 2 +- tools/perf/ui/stdio/hist.c | 1 + tools/perf/util/dso.c | 2 +- tools/perf/util/dso.h | 36 +- tools/perf/util/symbol-elf.c | 355 +++++++- tools/perf/util/symbol-minimal.c | 6 + tools/perf/util/symbol.c | 141 ++- tools/perf/util/symbol.h | 31 +- tools/perf/util/symbol_conf.h | 1 + 18 files changed, 2183 insertions(+), 28 deletions(-)
---
base-commit: bb27ddbaee56536fb8df0a24f07b526766dfe131
change-id: 20260915-perf-symbol-memory-send-e7cfca1ac3d9
Best regards,
Signature · 1 line
Alireza Haghdoost <[email protected]>