From: Alireza Haghdoost via B4 Relay <devnull+haghdoost.uber.com@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andriin@fb.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Alireza Haghdoost <haghdoost@uber.com>
Subject: [PATCH v5 0/5] perf script: Lazy symbol loading
Date: Mon, 05 Oct 2026 10:30:30 -0700 [thread overview]
Message-ID: <20261005-perf-symbol-memory-send-v5-0-165dceb2b049@uber.com> (raw)
perf script loads the entire ELF symbol table of every DSO that appears
in a sample, allocating each symbol into an rb-tree held 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.
This series adds an opt-in lazy loader for userspace ELF DSOs, after a
regression fix and two preparatory patches:
[1/5] Fix a broken "#ifdef ELF_C_READ_MMAP" guard so perf actually
mmaps ELF files instead of malloc'ing section data. This is a
standalone regression fix for 22dd1ac91a77.
[2/5] Let a DSO read its data from one explicit file through the DSO
data cache. This fixes the split-debuginfo case where offsets from
the debuginfo file would be applied to the runtime image.
[3/5] Factor duplicate-symbol selection so it works on symbol
attributes rather than struct symbol. No functional change.
[4/5] --lazy-load-symbols: build a compact per-DSO sorted index and
resolve only the sampled addresses, reading names through the DSO
data cache at lookup time.
[5/5] Unit and shell tests.
Patches 1-3 stand on their own and can be applied first.
On a 120 second cgroup profile of a production database service (54k
samples across 11 DSOs), peak RssAnon drops from 314 MiB to 80 MiB and
wall time from 4.49 s to 3.75 s, with identical output. Memory
optimizations usually cost time; this one does not because lazy loading
skips a lot of calloc and demangle calls.
This series does not change struct symbol. The new sorted index holds
only the address range, binding, type and string-table offset of each
symbol. When a sample hits an entry, perf reads and demangles the name
and creates a normal struct symbol with the name embedded, so the rest
of perf never sees an unresolved name.
Lazy loading handles the common userspace ELF symtab/dynsym path. The
kernel, modules, PPC64 .opd and .gnu_debugdata still load eagerly, and
eager loading remains the default.
This is independent of Ian's reference counting and shrinking series
[1]. The two should complement each other: lazy loading avoids creating
symbols that are never used, and shrinking can reclaim the ones that
were.
[1] https://lore.kernel.org/all/20260928075237.3055101-1-irogers@google.com/
Changes in v5:
- Rebase onto current perf-tools-next.
- 1/5: add Ian's Reviewed-by.
- 4/5: add kernel-doc for struct dso_ondemand (Ian).
- 4/5: choose between lazy and eager lookup in dso__find_symbol() instead
of map__find_symbol(), so direct callers also use the lazy index (Ian).
- 4/5: share one bound search between the lower- and upper-bound callers,
and say why bsearch() does not fit (Ian).
- 4/5: explain the ARM Thumb bit stripping (Ian). Trim comments that
restated the code.
- 5/5: call dso__find_symbol() directly in the lookup test, and add a
nested range lookup test.
Previous versions:
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 (5):
perf symbols: Fix broken ELF_C_READ_MMAP fallback guard
perf dso: Allow reading DSO data from an explicit file
perf symbols: Factor out duplicate symbol selection
perf script: Add --lazy-load-symbols for lazy symbol loading
perf test: Test lazy symbol loading
tools/perf/Documentation/perf-script.txt | 9 +
tools/perf/arch/powerpc/util/sym-handling.c | 6 +-
tools/perf/builtin-script.c | 2 +
tools/perf/tests/Build | 1 +
tools/perf/tests/builtin-test.c | 1 +
tools/perf/tests/dso-data.c | 42 +
tools/perf/tests/shell/lazy_load_symbols_parity.sh | 326 ++++++++
tools/perf/tests/shell/script_lazy_load_symbols.sh | 185 +++++
tools/perf/tests/symbol-lazy.c | 760 +++++++++++++++++
tools/perf/tests/tests.h | 1 +
tools/perf/util/dso.c | 54 +-
tools/perf/util/dso.h | 82 ++
tools/perf/util/map.c | 5 +-
tools/perf/util/symbol-elf.c | 920 +++++++++++++++++++++
tools/perf/util/symbol-minimal.c | 9 +
tools/perf/util/symbol.c | 61 +-
tools/perf/util/symbol.h | 25 +-
tools/perf/util/symbol_conf.h | 1 +
18 files changed, 2459 insertions(+), 31 deletions(-)
---
base-commit: 1dc462fc214907671600172280c2e79ef9fe6fcf
change-id: 20260915-perf-symbol-memory-send-e7cfca1ac3d9
Best regards,
--
Alireza Haghdoost <haghdoost@uber.com>
next reply other threads:[~2026-10-05 17:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 17:30 Alireza Haghdoost via B4 Relay [this message]
2026-10-05 17:30 ` [PATCH v5 1/5] perf symbols: Fix broken ELF_C_READ_MMAP fallback guard Alireza Haghdoost via B4 Relay
2026-10-05 17:30 ` [PATCH v5 2/5] perf dso: Allow reading DSO data from an explicit file Alireza Haghdoost via B4 Relay
2026-10-05 17:30 ` [PATCH v5 3/5] perf symbols: Factor out duplicate symbol selection Alireza Haghdoost via B4 Relay
2026-10-05 17:30 ` [PATCH v5 4/5] perf script: Add --lazy-load-symbols for lazy symbol loading Alireza Haghdoost via B4 Relay
2026-10-05 17:30 ` [PATCH v5 5/5] perf test: Test " Alireza Haghdoost via B4 Relay
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=20261005-perf-symbol-memory-send-v5-0-165dceb2b049@uber.com \
--to=devnull+haghdoost.uber.com@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--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=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®