tracing: ring_buffer: Rewind persistent ring buffer on reboot
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Wed, 4 Jun 2025 00:10:21 +0000 (09:10 +0900)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Thu, 10 Jul 2025 00:38:42 +0000 (20:38 -0400)
commitca296d32ece38b07113bad64e08add75073a0e2b
treeee38b22d3a8b4d20a5b60a4c71350c9de5d74e94
parentd7b8f8e20813f0179d8ef519541a3527e7661d3a
tracing: ring_buffer: Rewind persistent ring buffer on reboot

Rewind persistent ring buffer pages which have been read in the previous
boot. Those pages are highly possible to be lost before writing it to the
disk if the previous kernel crashed. In this case, the trace data is kept
on the persistent ring buffer, but it can not be read because its commit
size has been reset after read.  This skips clearing the commit size of
each sub-buffer and recover it after reboot.

Note: If you read the previous boot data via trace_pipe, that is not
accessible in that time. But reboot without clearing (or reusing) the read
data, the read data is recovered again in the next boot.

Thus, when you read the previous boot data, clear it by `echo > trace`.

Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/174899582116.955054.773265393511190051.stgit@mhiramat.tok.corp.google.com
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ring_buffer.c