Linux Trace Kernel
 help / color / mirror / Atom feed
From: Xiang Gao <gxxa03070307@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Xiang Gao <gaoxiang17@xiaomi.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	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
Subject: [RFC] tracing: aggregate ring-buffer memory statistics
Date: Tue, 25 Aug 2026 22:10:15 +0800	[thread overview]
Message-ID: <20260825141015.3539553-1-gaoxiang17@xiaomi.com> (raw)

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

             reply	other threads:[~2026-08-25 14:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 14:10 Xiang Gao [this message]
     [not found] ` <93406afe7c684d649f11b05d7b6b7b7b@xiaomi.com>
2026-08-27 15:35   ` [External Mail][RFC] tracing: aggregate ring-buffer memory statistics Steven Rostedt
2026-08-27 15:38 ` [RFC] " Steven Rostedt
     [not found]   ` <15c244f5bc8f4858b8ffa2974a46d009@xiaomi.com>
     [not found]     ` <88d476d443e74672957a5e0d1f8bf9ba@xiaomi.com>
2026-09-02 13:15       ` [External Mail]Re: " Steven Rostedt
     [not found]         ` <ca552a4c093b4498b2e308d266d5ab6f@xiaomi.com>
2026-09-02 14:39           ` Steven Rostedt
     [not found]             ` <e4c4d3f20b1445869ba329e561f6d042@xiaomi.com>
2026-09-02 14:48               ` Steven Rostedt

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=20260825141015.3539553-1-gaoxiang17@xiaomi.com \
    --to=gxxa03070307@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=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