Hi, This is a resend of the RFC for exposing tracing buffer memory statistics under tracefs.
The motivation is Android lost-RAM attribution: tracing buffer memory is not represented as a separate category, so it can be counted as lost RAM. The memory can be spread across the global trace array, dynamically created instances, and snapshot buffers, and userspace currently has to discover and sum every instance. The patch adds: /sys/kernel/tracing/trace_stats/total_memory_kb reporting: total: buffers_mem: snapshot_buffers_mem: The values cover the global trace array and all instances across all CPUs. A per-CPU view is provided under: /sys/kernel/tracing/trace_stats/per_cpu/cpuN/total_memory_kb These *_mem values report the full pages backing the data sub-buffers and reader page, unlike buffer_size_kb / buffer_total_size_kb which report usable data capacity. The new trace_stats directory is distinct from the existing trace_stat directory used for function and branch counters. For example, with 4 CPUs and 2 sub-buffers per CPU on a 4 KiB page system: buffer_size_kb = (4096 - 16) * 2 / 1024 = 7 kB (one CPU) buffer_total_size_kb = 7 * 4 = 28 kB (one array) buffers_mem = (2 + 1) * 4096 * 4 / 1024 = 48 kB The extra memory in buffers_mem comes from the per-page header and the reader page. Slab-allocated ring-buffer metadata is not included. One open question is whether reporting page memory only is acceptable for the initial version. Thanks, Xiang
