From 1e826983ceef421d7047ed76581840b778294ad4 Mon Sep 17 00:00:00 2001 From: Paul Moses Date: Tue, 20 Oct 2026 17:21:07 +0000 Subject: [PATCH] perf mmap: Preserve the consumed cursor in forward mode perf_mmap__read_event() updates prev as it consumes forward-buffer records. perf_mmap__read_done() then overwrites prev with a fresh producer head, even when unread records remain. perf_kvm__mmap_read_idx() stops after 25 records per mmap and calls read_done(). If more records are pending, prev advances past them. The next drain starts at that new position and skips the unread remainder. An event arriving after the last empty read_event() and before read_done() can also be skipped. read_done() does not itself update the kernel's data_tail. Only refresh prev for overwrite buffers, which need the current head as the end of the next backward read. Leave the forward cursor at the consumed position. Fixes: 53172f9057e92c9b ("perf kvm: Switch to new perf_mmap__read_event() interface") Signed-off-by: Paul Moses Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/perf/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c index ec124eb0ec0a..ab3adf1d8baf 100644 --- a/tools/lib/perf/mmap.c +++ b/tools/lib/perf/mmap.c @@ -200,7 +200,7 @@ void perf_mmap__read_done(struct perf_mmap *map) /* * Check if event was unmapped due to a POLLHUP/POLLERR. */ - if (!refcount_read(&map->refcnt)) + if (!refcount_read(&map->refcnt) || !map->overwrite) return; map->prev = perf_mmap__read_head(map);