All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiang Gao <gxxa03070307@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Vincent Donnefort <vdonnefort@google.com>,
	Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Cc: 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, Xiang Gao <gaoxiang17@xiaomi.com>
Subject: [PATCH v3 0/2] tracing: add ring-buffer memory usage statistics
Date: Wed, 16 Sep 2026 14:33:20 +0800	[thread overview]
Message-ID: <20260916063322.472172-1-gaoxiang17@xiaomi.com> (raw)
In-Reply-To: <20260911155017.3377254-1-gaoxiang17@xiaomi.com>

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.

Patch 1 adds:

  /sys/kernel/tracing/trace_stats/memory_usage_kb

reporting:

  buffers: ...
  snapshot_buffers: ...

covering the global trace array and all instances across all CPUs.

Patch 2 adds the per-CPU view under
trace_stats/per_cpu/cpuN/memory_usage_kb.

The values account for the full pages backing the data sub-buffers and
reader page, plus the cached read page and mmap metadata page when
present. Slab-allocated ring-buffer metadata is not included.

Changes since v2:
- Account for the bootstrapping temp_buffer (Donggeun Yoo).
- Rebase onto latest mainline; adapt to free_page becoming struct
  buffer_data_read_page.

Tested on arm64 QEMU with global buffer resize, snapshot alloc/free,
instance create/remove, and per-CPU aggregation, all against the
baseline that includes temp_buffer (3 pages per CPU).

Xiang Gao (2):
  tracing: add ring-buffer memory usage statistics in tracefs
  tracing: add per-CPU memory usage statistics in tracefs

 Documentation/trace/ftrace.rst |  15 +++++
 include/linux/ring_buffer.h    |   1 +
 kernel/trace/ring_buffer.c     |  41 ++++++++++++
 kernel/trace/trace.c           | 118 +++++++++++++++++++++++++++++++++
 4 files changed, 175 insertions(+)

-- 
2.34.1


  parent reply	other threads:[~2026-09-16  6:33 UTC|newest]

Thread overview: 24+ 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
2026-09-13 16:37     ` Donggeun Yoo
2026-09-11 15:50   ` [PATCH v2 2/2] tracing: add per-CPU " Xiang Gao
2026-09-16  6:33   ` Xiang Gao [this message]
2026-09-16  6:33     ` [PATCH v3 1/2] tracing: add ring-buffer " Xiang Gao
2026-09-16  6:50       ` sashiko-bot
2026-09-16  6:33     ` [PATCH v3 2/2] tracing: add per-CPU " Xiang Gao
2026-09-21 11:30     ` [PATCH v4 0/2] tracing: add ring-buffer memory usage statistics Xiang Gao
2026-09-21 11:30       ` [PATCH v4 1/2] tracing: add ring-buffer memory usage statistics in tracefs Xiang Gao
2026-09-22  9:41         ` Vincent Donnefort
2026-09-24  1:27           ` Masami Hiramatsu
2026-09-24  8:54             ` Vincent Donnefort
2026-09-25  1:09               ` Masami Hiramatsu
2026-09-21 11:30       ` [PATCH v4 2/2] tracing: add per-CPU " Xiang Gao
2026-09-22  9:42         ` Vincent Donnefort
2026-09-24  1:36         ` Masami Hiramatsu
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=20260916063322.472172-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 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.