Re: [PATCH v1] perf sample: Make user_regs and intr_regs optional

From: Andi Kleen
Date: Tue Jan 14 2025 - 16:02:06 EST


On Mon, Jan 13, 2025 at 11:43:45AM -0800, Ian Rogers wrote:
> The struct dump_regs contains 512 bytes of cache_regs, meaning the two
> values in perf_sample contribute 1088 bytes of its total 1384 bytes
> size. Initializing this much memory has a cost reported by Tavian
> Barnes <tavianator@xxxxxxxxxxxxxx> as about 2.5% when running `perf
> script --itrace=i0`:
> https://lore.kernel.org/lkml/d841b97b3ad2ca8bcab07e4293375fb7c32dfce7.1736618095.git.tavianator@xxxxxxxxxxxxxx/
>
> Adrian Hunter <adrian.hunter@xxxxxxxxx> replied that the zero
> initialization was necessary and couldn't simply be removed.

A much easier fix is to keep a global/heap allocate perf event
around that has these parts zeroed and only override the fields
needed and clear them afterwards.

(similar strategy as a slab constructor in the kernel)

-Andi