Re: [PATCH 1/2] tracing: add ring-buffer memory usage statistics in tracefs
From: sashiko-bot@kernel.org
Date: 2026-09-05 11:38:42
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Compilation failure due to evaluating a struct type in a boolean context. -- commit 59684c76ae178c23d488e6128dbc2d350cbbec1d Author: Xiang Gao [off-list ref] tracing: add ring-buffer memory usage statistics in tracefs This commit adds memory consumption statistics for tracing ring buffers to tracefs. It reports the memory consumed by the main and snapshot buffers across all instances, tracking the full pages backing the sub-buffers.
quoted hunk ↗ jump to hunk
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 5fc009edc1ec9..4579053d34ec4 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -6526,6 +6526,47 @@ unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu)
[ ... ]
+unsigned long ring_buffer_memory_size(struct trace_buffer *buffer, int cpu)
+{
+ struct ring_buffer_per_cpu *cpu_buffer;
+ unsigned long subbuf_size;
+ unsigned long size;
+
+ if (!cpumask_test_cpu(cpu, buffer->cpumask))
+ return 0;
+
+ /* Range and remote buffers use externally owned memory. */
+ if (buffer->range_addr_start || buffer->remote)
+ return 0;
+
+ cpu_buffer = buffer->buffers[cpu];
+ subbuf_size = PAGE_SIZE << buffer->subbuf_order;
+
+ /* Data sub-buffers plus the reader page. */
+ size = (cpu_buffer->nr_pages + 1) * subbuf_size;
+
+ /* The cached read page, if present, is a full sub-buffer page. */
+ if (cpu_buffer->free_page)[Severity: Low] Does this code cause a compilation failure? The free_page member of struct ring_buffer_per_cpu is an embedded struct (struct buffer_data_read_page), rather than a pointer. Evaluating it directly in a boolean context will cause a compiler error because a scalar value is required. Should this condition check a field within the struct instead, such as cpu_buffer->free_page.data?
+ size += subbuf_size; + + /* The mmap metadata page is a single system page. */ + if (cpu_buffer->meta_page) + size += PAGE_SIZE; + + return size; +}
-- Sashiko AI review · https://sashiko.dev/#/patchset/20260905112732.3705405-1-gaoxiang17@xiaomi.com?part=1