[PATCH v5 0/4] tracing: add ring-buffer memory usage statistics

From
Xiang Gao <hidden>
Date
2026-11-05 14:02:32
Also in
lkml
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
Thread (7 messages) 7 messages, 3 authors, last reply 2d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help