From: Paul Moses <p@1g4.org>
To: linux-perf-users@vger.kernel.org, acme@kernel.org, namhyung@kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org, kan.liang@intel.com,
linux-kernel@vger.kernel.org, Paul Moses <p@1g4.org>
Subject: [PATCH 0/2] perf mmap: Fix replayed and skipped records
Date: Tue, 20 Oct 2026 17:20:48 +0000 [thread overview]
Message-ID: <20261020171946.3593127-1-p@1g4.org> (raw)
perf_mmap__push() can copy through one producer head but save an earlier
head in prev, causing the next drain to write the same records again.
The race duplicates a small fraction of samples but reproduced in most
runs. Across 20 unpatched runs on two source baselines, each containing
500,000 unique samples:
- Replay occurred in 15 of 20 runs; five had no duplicates.
- Affected runs contained 14–53 duplicate samples each,
representing 0.0028–0.0106% of their 500,000 unique samples.
- The longest replay duplicated a block of 53 consecutive
timestamped records byte-for-byte.
- Overall, 485 duplicate samples were recorded alongside
10 million unique samples (0.00485%).
The patched builds had no duplicates in the corresponding 20 runs.
The second issue is that perf_mmap__read_done() advances the forward
cursor to the producer head even when unread records remain. perf kvm
stat live processes at most 25 records per mmap pass before calling
read_done(), so it can skip the remaining records without a race.
In three runs without patch 2, perf kvm stat live reported 111,894,
6,433, and 6,838 intervals against roughly 200,600 independently
counted KVM exits per run. With patch 2, the reported counts were
within 1–3 intervals of the independent counts. Separate cursor tracing
confirmed that read_done() advanced past unread records without the
fix and preserved the consumed cursor with it.
Paul Moses (2):
perf mmap: Use the head selected by read_init
perf mmap: Preserve the consumed cursor in forward mode
tools/lib/perf/mmap.c | 2 +-
tools/perf/util/mmap.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
--
2.56.GIT
next reply other threads:[~2026-10-20 17:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 17:20 Paul Moses [this message]
2026-10-20 17:20 ` [PATCH 1/2] perf mmap: Use the head selected by read_init Paul Moses
2026-10-20 17:21 ` [PATCH 2/2] perf mmap: Preserve the consumed cursor in forward mode Paul Moses
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=20261020171946.3593127-1-p@1g4.org \
--to=p@1g4.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@intel.com \
--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®