From: sashiko-bot@kernel.org
To: "Xiang Gao" <gxxa03070307@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] tracing: add ring-buffer memory usage statistics in tracefs
Date: Fri, 11 Sep 2026 16:04:01 +0000 [thread overview]
Message-ID: <20260911160401.917071F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911155017.3377254-2-gaoxiang17@xiaomi.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Persistent memory-mapped trace buffers are incorrectly accounted as page-allocator memory, leading to double-counting in lost RAM calculations.
- [Low] Evaluation of a struct type as a boolean condition causes a hard compilation error.
--
commit 339a95b19ea8f13ff179992c9814bfee94fa38b3
Author: Xiang Gao <gxxa03070307@gmail.com>
tracing: add ring-buffer memory usage statistics in tracefs
This commit adds memory usage reporting for tracing ring buffers to calculate
memory footprint more accurately than relying on buffer capacity. It exposes
a new memory_usage_kb file in tracefs which sums up the page allocator memory
used by the data pages and reader pages.
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 9c03a555a6ba2..73e79c86035c2 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
[ ... ]
> @@ -6560,6 +6560,47 @@ unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu)
> }
> EXPORT_SYMBOL_GPL(ring_buffer_size);
>
> +/**
> + * ring_buffer_memory_size - return the memory used by the buffer (in bytes)
[ ... ]
> + */
> +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;
> +
> + /* Remote buffers use externally owned memory. */
> + if (buffer->remote)
> + return 0;
[Severity: Medium]
Does this check also need to exclude persistent memory-mapped trace buffers
where buffer->range_addr_start is set? Since those buffers also use
externally owned or reserved memory bypassing the page-allocator, not
skipping them here might result in double-counting their memory in lost
RAM calculations.
> +
> + cpu_buffer = buffer->buffers[cpu];
> + subbuf_size = PAGE_SIZE << READ_ONCE(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)
> + size += subbuf_size;
[Severity: Low]
Does evaluating cpu_buffer->free_page directly as a boolean condition
cause a compiler error here, since free_page is an embedded struct
(struct buffer_data_read_page) rather than a pointer? Should this check its
internal data pointer instead, such as if (cpu_buffer->free_page.data)?
> +
> + /* 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/20260911155017.3377254-1-gaoxiang17@xiaomi.com?part=1
next prev parent reply other threads:[~2026-09-11 16:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 11:27 [PATCH 0/2] tracing: add ring-buffer memory usage statistics Xiang Gao
2026-09-05 11:27 ` [PATCH 1/2] tracing: add ring-buffer memory usage statistics in tracefs Xiang Gao
2026-09-05 11:38 ` sashiko-bot
2026-09-07 9:26 ` Vincent Donnefort
2026-09-05 11:27 ` [PATCH 2/2] tracing: add per-CPU " Xiang Gao
2026-09-11 15:50 ` [PATCH v2 0/2] tracing: add ring-buffer memory usage statistics Xiang Gao
2026-09-11 15:50 ` [PATCH v2 1/2] tracing: add ring-buffer memory usage statistics in tracefs Xiang Gao
2026-09-11 16:04 ` sashiko-bot [this message]
2026-09-13 16:37 ` Donggeun Yoo
2026-09-11 15:50 ` [PATCH v2 2/2] tracing: add per-CPU " Xiang Gao
2026-09-11 17:22 ` [PATCH 0/2] tracing: add ring-buffer memory usage statistics Vincent Donnefort
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260911160401.917071F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=gxxa03070307@gmail.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.