Commit 2d09328
ring-buffer: Fix wrong stat of cpu_buffer->read
When pages are removed in rb_remove_pages(), 'cpu_buffer->read' is set
to 0 in order to make sure any read iterators reset themselves. However,
this will mess 'entries' stating, see following steps:
# cd /sys/kernel/tracing/
# 1. Enlarge ring buffer prepare for later reducing:
# echo 20 > per_cpu/cpu0/buffer_size_kb
# 2. Write a log into ring buffer of cpu0:
# taskset -c 0 echo "hello1" > trace_marker
# 3. Read the log:
# cat per_cpu/cpu0/trace_pipe
<...>-332 [000] ..... 62.406844: tracing_mark_write: hello1
# 4. Stop reading and see the stats, now 0 entries, and 1 event readed:
# cat per_cpu/cpu0/stats
entries: 0
[...]
read events: 1
# 5. Reduce the ring buffer
# echo 7 > per_cpu/cpu0/buffer_size_kb
# 6. Now entries became unexpected 1 because actually no entries!!!
# cat per_cpu/cpu0/stats
entries: 1
[...]
read events: 0
To fix it, introduce 'page_removed' field to count total removed pages
since last reset, then use it to let read iterators reset themselves
instead of changing the 'read' pointer.
Link: https://lore.kernel.org/linux-trace-kernel/20230724054040.3489499-1-zhengyejian1@huawei.com
Cc: <mhiramat@kernel.org>
Cc: <vnagarnaik@google.com>
Fixes: 83f4031 ("ring-buffer: Make removal of ring buffer pages atomic")
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>1 parent 4b8b390 commit 2d09328
1 file changed
+12
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| 526 | + | |
| 527 | + | |
526 | 528 | | |
527 | 529 | | |
528 | 530 | | |
| |||
559 | 561 | | |
560 | 562 | | |
561 | 563 | | |
| 564 | + | |
562 | 565 | | |
563 | 566 | | |
564 | 567 | | |
| |||
1957 | 1960 | | |
1958 | 1961 | | |
1959 | 1962 | | |
| 1963 | + | |
| 1964 | + | |
1960 | 1965 | | |
1961 | 1966 | | |
1962 | 1967 | | |
| |||
1978 | 1983 | | |
1979 | 1984 | | |
1980 | 1985 | | |
1981 | | - | |
1982 | | - | |
1983 | | - | |
1984 | | - | |
1985 | | - | |
1986 | | - | |
1987 | 1986 | | |
1988 | 1987 | | |
1989 | 1988 | | |
| |||
4395 | 4394 | | |
4396 | 4395 | | |
4397 | 4396 | | |
| 4397 | + | |
4398 | 4398 | | |
4399 | 4399 | | |
4400 | 4400 | | |
| |||
4849 | 4849 | | |
4850 | 4850 | | |
4851 | 4851 | | |
4852 | | - | |
4853 | | - | |
4854 | | - | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
4855 | 4855 | | |
4856 | 4856 | | |
4857 | | - | |
| 4857 | + | |
| 4858 | + | |
4858 | 4859 | | |
4859 | 4860 | | |
4860 | 4861 | | |
| |||
5298 | 5299 | | |
5299 | 5300 | | |
5300 | 5301 | | |
| 5302 | + | |
5301 | 5303 | | |
5302 | 5304 | | |
5303 | 5305 | | |
| |||
0 commit comments