[PATCH v3 0/2] perf record: fix multi-record Zstd compression

From: Dmitry Ilvokhin

Date: Wed Jul 08 2026 - 09:44:38 EST


Fix a 'perf record -z' regression that aborts recording and writes a perf.data
that cannot be decompressed (see full analysis in patch 2).

v2 -> v3:

- Dropped "perf record: Avoid overrunning the zstd output buffer" and "perf
record: Don't store raw data on zstd compression failure": both are now fixed
in perf-tools-next.
- Added "perf record: Return the written size from process_comp_header()", a
no-functional-change prep patch, so the fix's per-record padding can't
overrun 'dst'
- Removed blank line from record+zstd_comp_decomp_multi_record.sh between test
description and license (Namhyung Kim).
- Added missing <string.h> include (Sashiko).
- Rebased onto perf-tools-next (Namhyung Kim).

v1 -> v2:

- Patch 2 ("perf record: Avoid overrunning the zstd output buffer"):
rework the overly strict output buffer check to pass the remaining dst
size to process_comp_header() and bail only when a record won't fit
(Sashiko).

v1: https://lore.kernel.org/all/cover.1781797544.git.d@xxxxxxxxxxxx/
v2: https://lore.kernel.org/all/cover.1782743187.git.d@xxxxxxxxxxxx/

Dmitry Ilvokhin (2):
perf record: Return the written size from process_comp_header()
perf record: Fix multiple PERF_RECORD_COMPRESSED2 records per push

tools/perf/builtin-record.c | 49 +++++++++------
.../record+zstd_comp_decomp_multi_record.sh | 63 +++++++++++++++++++
tools/perf/util/compress.h | 6 +-
tools/perf/util/zstd.c | 25 ++++----
4 files changed, 111 insertions(+), 32 deletions(-)
create mode 100755 tools/perf/tests/shell/record+zstd_comp_decomp_multi_record.sh

--
2.53.0-Meta