[lkml]   [2018]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[tip:perf/urgent] perf mmap: Recalculate size for overwrite mode
Commit-ID:  dc6c35c679e96987dc83a003f30bc2cc33c84c00
Author: Kan Liang <>
AuthorDate: Thu, 18 Jan 2018 13:26:17 -0800
Committer: Arnaldo Carvalho de Melo <>
CommitDate: Thu, 15 Feb 2018 09:51:57 -0300

perf mmap: Recalculate size for overwrite mode

In perf_mmap__push(), the 'size' need to be recalculated, otherwise the
invalid data might be pushed to the record in overwrite mode.

The issue is introduced by commit 7fb4b407a124 ("perf mmap: Don't
discard prev in backward mode").

When the ring buffer is full in overwrite mode, backward_rb_find_range()
will be called to recalculate the 'start' and 'end'. The 'size' needs to
be recalculated accordingly.

Unconditionally recalculate the 'size', not just for full ring buffer in
overwrite mode. Because:

- There is no harmful to recalculate the 'size' for other cases.
- The code of calculating 'start' and 'end' will be factored out later.
The new function does not need to return 'size'.

Signed-off-by: Kan Liang <>
Acked-by: Jiri Olsa <>
Cc: Andi Kleen <>
Cc: Jin Yao <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Wang Nan <>
Fixes: 7fb4b407a124 ("perf mmap: Don't discard prev in backward mode")
Signed-off-by: Arnaldo Carvalho de Melo <>
tools/perf/util/mmap.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 05076e6..97cf4fa 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -302,6 +302,8 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite,
return -1;

+ size = end - start;
if ((start & md->mask) + size != (end & md->mask)) {
buf = &data[start & md->mask];
size = md->mask + 1 - (start & md->mask);
 \ /
  Last update: 2018-02-16 10:50    [W:0.499 / U:0.896 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site