From: Xiang Gao <gxxa03070307@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Vincent Donnefort <vdonnefort@google.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lorenzo Stoakes <ljs@kernel.org>, gao xu <gaoxu2@honor.com>,
yinchuang1@xiaomi.com, linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org, Xiang Gao <gaoxiang17@xiaomi.com>
Subject: [PATCH v5 0/4] tracing: add ring-buffer memory usage statistics
Date: Thu, 5 Nov 2026 22:02:17 +0800 [thread overview]
Message-ID: <20261105140221.44614-1-gaoxiang17@xiaomi.com> (raw)
Report the memory consumed by the tracing ring buffers, rather than the
usable data capacity exposed by buffer_size_kb. Android low-memory
diagnostics need this to attribute the memory used by tracing when
calculating lost RAM.
The buffers can be spread across the global trace array, dynamically
created instances, and snapshot buffers. Userspace currently has to
discover and sum every instance, and snapshot memory is not exposed by
the per-instance totals.
This series adds:
/sys/kernel/tracing/trace_stats/memory_usage_kb
reporting:
global:
instances:
snapshots:
persistents:
remotes:
total_system:
total_carveout:
global, instances, and snapshots come from the page allocator.
persistents use reserved memory. remotes are not yet reported and are
always zero. total_system is the page-allocator memory, while
total_carveout is reserved memory that was never in the free pool. A
per-CPU view is provided under trace_stats/per_cpu/cpuN/.
The memory source is split into system and carveout only for now. A
finer-grained attribute (host/guest/reserved/device) can be added when
remotes are enumerated, since guest and device memory do not exist in
the current accounting.
Changes since v4:
- Categorize the report by buffer type and memory source.
- Make ring_buffer_memory_size() generic so it returns a size for any
buffer type instead of zero for remote buffers.
- Skip the backup instance, whose vmalloc memory is already accounted in
VmallocUsed.
- Rebase on v7.4-rc1.
- Split the documentation into its own patch.
Xiang Gao (4):
ring-buffer: add ring_buffer_memory_size()
tracing: add aggregate buffer memory usage statistics
tracing: add per-CPU buffer memory usage statistics
Documentation: document trace_stats memory_usage_kb
Documentation/trace/ftrace.rst | 22 ++++
include/linux/ring_buffer.h | 1 +
kernel/trace/ring_buffer.c | 37 +++++++
kernel/trace/trace.c | 188 +++++++++++++++++++++++++++++++++
4 files changed, 248 insertions(+)
--
2.34.1
next reply other threads:[~2026-11-05 14:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 14:02 Xiang Gao [this message]
2026-11-05 14:02 ` [PATCH v5 1/4] ring-buffer: add ring_buffer_memory_size() Xiang Gao
2026-11-05 14:02 ` [PATCH v5 2/4] tracing: add aggregate buffer memory usage statistics Xiang Gao
2026-11-05 14:02 ` [PATCH v5 3/4] tracing: add per-CPU " Xiang Gao
2026-11-05 14:02 ` [PATCH v5 4/4] Documentation: document trace_stats memory_usage_kb Xiang Gao
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=20261105140221.44614-1-gaoxiang17@xiaomi.com \
--to=gxxa03070307@gmail.com \
--cc=donggeunyoo.kernel@gmail.com \
--cc=gaoxiang17@xiaomi.com \
--cc=gaoxu2@honor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=vdonnefort@google.com \
--cc=yinchuang1@xiaomi.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®