Skip to content

Commit ff84c50

Browse files
committed
ring-buffer: Do not die if rb_iter_peek() fails more than thrice
As the iterator will be reading a live buffer, and if the event being read is on a page that a writer crosses, it will fail and try again, the condition in rb_iter_peek() that only allows a retry to happen three times is no longer valid. Allow rb_iter_peek() to retry more than three times without killing the ring buffer, but only if rb_iter_head_event() had failed at least once. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 785888c commit ff84c50

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

kernel/trace/ring_buffer.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,7 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
40124012
struct ring_buffer_per_cpu *cpu_buffer;
40134013
struct ring_buffer_event *event;
40144014
int nr_loops = 0;
4015+
bool failed = false;
40154016

40164017
if (ts)
40174018
*ts = 0;
@@ -4038,10 +4039,14 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
40384039
* to a data event, we should never loop more than three times.
40394040
* Once for going to next page, once on time extend, and
40404041
* finally once to get the event.
4041-
* (We never hit the following condition more than thrice).
4042+
* We should never hit the following condition more than thrice,
4043+
* unless the buffer is very small, and there's a writer
4044+
* that is causing the reader to fail getting an event.
40424045
*/
4043-
if (RB_WARN_ON(cpu_buffer, ++nr_loops > 3))
4046+
if (++nr_loops > 3) {
4047+
RB_WARN_ON(cpu_buffer, !failed);
40444048
return NULL;
4049+
}
40454050

40464051
if (rb_per_cpu_empty(cpu_buffer))
40474052
return NULL;
@@ -4052,8 +4057,10 @@ rb_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
40524057
}
40534058

40544059
event = rb_iter_head_event(iter);
4055-
if (!event)
4060+
if (!event) {
4061+
failed = true;
40564062
goto again;
4063+
}
40574064

40584065
switch (event->type_len) {
40594066
case RINGBUF_TYPE_PADDING:

0 commit comments

Comments
 (0)