Re: [PATCH v4 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI
From: Ian Rogers
Date: Tue Dec 01 2026 - 12:11:33 EST
On Tue, Dec 1, 2026 at 12:14 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Mon, Nov 30, 2026 at 11:38:46AM -0800, Ian Rogers wrote:
> > On Wed, Nov 25, 2026 at 01:45:32PM -0800, Namhyung Kim wrote:
> > > On Wed, Nov 25, 2026 at 02:25:12PM +0100, Peter Zijlstra wrote:
> > > > > 64-bit offsets whose top 8 bits encode the 1-based build ID index (or
> > > > > 0x00 for unresolved user addresses and 0xff for kernel/context entries).
> > > > > In common cases where multiple callchain frames belong to the same
> > > > > binary, each unique build ID is encoded only once.
> > > >
> > > > Why ?!? This is insane
> > >
> > > This is basically to save space for callchains. When multiple entries
> > > fall into the same binary, it can have a table of binaries/build-ids
> > > and use indices instead of repeating full build-id for each entry.
> > >
> > > It'd be great if it could have a global (or per-session) table. This is
> > > a per-sample table. Please let us know if you have a better idea.
> >
> > For context on how we arrived here: in v1/v2 each callchain frame was
> > simply a fixed 32-byte { struct perf_build_id bid; u64 offset; } entry
> > (4x larger than raw u64 IPs, ~4 KiB for a 127-frame stack). The
> > per-sample table + 8-bit index in v3/v4 was an attempt to cut that size
> > overhead while keeping each sample self-contained.
> >
> > Fair enough if the bit-packing / per-sample table complexity is too
> > ugly for UAPI. Before spinning v5, what direction would you prefer?
>
> Personally, I would much prefer buildid to cease existing ;-) It is an
> abomination.
>
> > Some alternatives:
> >
> > 1. Simple fixed-size entries per frame (no table, no bit-packing):
> > back to { struct perf_build_id bid; u64 offset; } per entry, trading
> > extra ring-buffer bytes for a trivial UAPI and kernel path.
> >
> > 2. Per-sample table without bit-packing into offsets: e.g. fixed
> > struct perf_build_id build_ids[nr_build_ids] plus explicit
> > { u64 offset; u32 bid_idx; u32 reserved; } (or separate u8/u16
> > index array) so 64-bit offsets/addresses stay untouched.
> >
> > 3. A session/ring-buffer sideband record (e.g. assigning a monotonic
> > ID per build ID when first encountered, or emitting a build-ID table
> > record) so samples only carry { id, offset } instead of repeating
> > 20-byte build IDs across samples.
> >
> > Which aspect is the main objection here -- the 8-bit/56-bit packing,
> > the per-sample deduplication in the kernel, or repeating build IDs per
> > sample instead of a sideband mapping?
>
> Like I just replied; I don't see why we need it at all; we already have
> buildid in the mmap sideband data. That is sufficient to reconstruct at
> post processing.
The point of having build ID + offset in samples is to avoid needing
MMAP2 sideband and /proc synthesis altogether -- with a symbol server /
debuginfod, samples carry everything needed to symbolize without
tracking every process's address space.
Relying on MMAP2 sideband only gives new mappings; for system-wide
profiling, perf still has to crawl /proc/<pid>/maps for every existing
task at startup and record every subsequent mmap/fork across the
machine, even for processes that are never sampled. On large
consolidated servers that overhead is substantial:
- For infrequent system-wide events (e.g. bus lock), synthesizing and
recording all system-wide mmaps dwarfs the cost and size of the
actual samples.
- Even for high-frequency events like cycles, on a large server with
lots of consolidated work we see over half of perf.data consisting of
mmap events, and that share keeps growing as more work (including
guest VMs / containers) is consolidated onto larger machines.
- On a loaded machine, just allocating the procfs inodes to scan
/proc/<pid>/maps at perf startup can trigger memory reclaim and
latency spikes -- worst when you are profiling a machine because it
is already under stress.
So build ID + offset samples make sense today for infrequent
system-wide events (like bus lock) and for profiling machines under
stress without an upfront synthesis storm (reusing the kernel's
existing stack_map_get_build_id_offset() helper via defer_callchain).
Longer term, for general profiling this also lets us optimize sideband
overhead by running two events -- one with build ID + offset and one
with raw virtual addresses -- starting with build-ID samples while
lazily synthesizing mappings in the background, then switching over to
compact virtual-address samples once mappings are ready.
Given those use cases, is your objection specifically to the packed
table encoding in v4 (where a simpler UAPI layout could work), or to
having build-ID + offset samples in perf at all?
Thanks,
Ian