* [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
@ 2026-09-07 9:42 Vincent Donnefort
2026-09-07 9:44 ` Vincent Donnefort
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Vincent Donnefort @ 2026-09-07 9:42 UTC (permalink / raw)
To: rostedt, mhiramat, linux-trace-kernel
Cc: mathieu.desnoyers, kernel-team, linux-kernel, Vincent Donnefort
Since commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring
buffer readers"), "capacity" refers to the memory available for events
(excluding subbuffer headers) while "size" refers to the raw allocation.
ring_buffer_size() actually calculates this event capacity. Rename it to
ring_buffer_capacity() to align with this convention.
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index afc7daa6ee7d..9e23ab66176b 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -165,7 +165,7 @@ void ring_buffer_iter_reset(struct ring_buffer_iter *iter);
int ring_buffer_iter_empty(struct ring_buffer_iter *iter);
bool ring_buffer_iter_dropped(struct ring_buffer_iter *iter);
-unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu);
+unsigned long ring_buffer_capacity(struct trace_buffer *buffer, int cpu);
unsigned long ring_buffer_max_event_size(struct trace_buffer *buffer);
void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu);
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 9c03a555a6ba..2940ff763354 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -6547,18 +6547,23 @@ void ring_buffer_iter_advance(struct ring_buffer_iter *iter)
EXPORT_SYMBOL_GPL(ring_buffer_iter_advance);
/**
- * ring_buffer_size - return the size of the ring buffer (in bytes)
+ * ring_buffer_capacity - return the capacity of the ring buffer (in bytes)
* @buffer: The ring buffer.
- * @cpu: The CPU to get ring buffer size from.
+ * @cpu: The CPU to get ring buffer capacity from.
+ *
+ * Capacity is the total memory available for recording event data in the
+ * ring buffer. It excludes subbufer headers.
+ *
+ * Returns the capacity in bytes, or 0 if the CPU is not set in the buffer mask.
*/
-unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu)
+unsigned long ring_buffer_capacity(struct trace_buffer *buffer, int cpu)
{
if (!cpumask_test_cpu(cpu, buffer->cpumask))
return 0;
return rb_subbuf_capacity(buffer) * buffer->buffers[cpu]->nr_pages;
}
-EXPORT_SYMBOL_GPL(ring_buffer_size);
+EXPORT_SYMBOL_GPL(ring_buffer_capacity);
/**
* ring_buffer_max_event_size - return the max data size of an event
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8658cad53cb5..f0251788ec75 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4712,9 +4712,9 @@ void trace_set_buffer_entries(struct array_buffer *buf, unsigned long val)
static void update_buffer_entries(struct array_buffer *buf, int cpu)
{
if (cpu == RING_BUFFER_ALL_CPUS) {
- trace_set_buffer_entries(buf, ring_buffer_size(buf->buffer, 0));
+ trace_set_buffer_entries(buf, ring_buffer_capacity(buf->buffer, 0));
} else {
- per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_size(buf->buffer, cpu);
+ per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_capacity(buf->buffer, cpu);
}
}
@@ -8476,7 +8476,7 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int
/* Allocate the first page for all buffers */
trace_set_buffer_entries(&tr->array_buffer,
- ring_buffer_size(tr->array_buffer.buffer, 0));
+ ring_buffer_capacity(tr->array_buffer.buffer, 0));
return 0;
}
base-commit: df2908090cda368b01ff43709f51890076c56157
--
2.55.0.979.g7e5102b832-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
2026-09-07 9:42 [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity() Vincent Donnefort
@ 2026-09-07 9:44 ` Vincent Donnefort
2026-09-07 9:51 ` sashiko-bot
2026-09-07 14:41 ` Masami Hiramatsu
2 siblings, 0 replies; 5+ messages in thread
From: Vincent Donnefort @ 2026-09-07 9:44 UTC (permalink / raw)
To: rostedt, mhiramat, linux-trace-kernel
Cc: mathieu.desnoyers, kernel-team, linux-kernel
On Mon, Sep 07, 2026 at 10:42:38AM +0100, Vincent Donnefort wrote:
> Since commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring
> buffer readers"), "capacity" refers to the memory available for events
> (excluding subbuffer headers) while "size" refers to the raw allocation.
> ring_buffer_size() actually calculates this event capacity. Rename it to
> ring_buffer_capacity() to align with this convention.
>
> Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
>
> diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
> index afc7daa6ee7d..9e23ab66176b 100644
> --- a/include/linux/ring_buffer.h
> +++ b/include/linux/ring_buffer.h
> @@ -165,7 +165,7 @@ void ring_buffer_iter_reset(struct ring_buffer_iter *iter);
> int ring_buffer_iter_empty(struct ring_buffer_iter *iter);
> bool ring_buffer_iter_dropped(struct ring_buffer_iter *iter);
>
> -unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu);
> +unsigned long ring_buffer_capacity(struct trace_buffer *buffer, int cpu);
> unsigned long ring_buffer_max_event_size(struct trace_buffer *buffer);
>
> void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu);
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 9c03a555a6ba..2940ff763354 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -6547,18 +6547,23 @@ void ring_buffer_iter_advance(struct ring_buffer_iter *iter)
> EXPORT_SYMBOL_GPL(ring_buffer_iter_advance);
>
> /**
> - * ring_buffer_size - return the size of the ring buffer (in bytes)
> + * ring_buffer_capacity - return the capacity of the ring buffer (in bytes)
> * @buffer: The ring buffer.
> - * @cpu: The CPU to get ring buffer size from.
> + * @cpu: The CPU to get ring buffer capacity from.
> + *
> + * Capacity is the total memory available for recording event data in the
> + * ring buffer. It excludes subbufer headers.
Of course, I manage to do a typo... "subbuffer"
--
Vincent
> + *
> + * Returns the capacity in bytes, or 0 if the CPU is not set in the buffer mask.
> */
> -unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu)
> +unsigned long ring_buffer_capacity(struct trace_buffer *buffer, int cpu)
> {
> if (!cpumask_test_cpu(cpu, buffer->cpumask))
> return 0;
>
> return rb_subbuf_capacity(buffer) * buffer->buffers[cpu]->nr_pages;
> }
> -EXPORT_SYMBOL_GPL(ring_buffer_size);
> +EXPORT_SYMBOL_GPL(ring_buffer_capacity);
>
> /**
> * ring_buffer_max_event_size - return the max data size of an event
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 8658cad53cb5..f0251788ec75 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -4712,9 +4712,9 @@ void trace_set_buffer_entries(struct array_buffer *buf, unsigned long val)
> static void update_buffer_entries(struct array_buffer *buf, int cpu)
> {
> if (cpu == RING_BUFFER_ALL_CPUS) {
> - trace_set_buffer_entries(buf, ring_buffer_size(buf->buffer, 0));
> + trace_set_buffer_entries(buf, ring_buffer_capacity(buf->buffer, 0));
> } else {
> - per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_size(buf->buffer, cpu);
> + per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_capacity(buf->buffer, cpu);
> }
> }
>
> @@ -8476,7 +8476,7 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int
>
> /* Allocate the first page for all buffers */
> trace_set_buffer_entries(&tr->array_buffer,
> - ring_buffer_size(tr->array_buffer.buffer, 0));
> + ring_buffer_capacity(tr->array_buffer.buffer, 0));
>
> return 0;
> }
>
> base-commit: df2908090cda368b01ff43709f51890076c56157
> --
> 2.55.0.979.g7e5102b832-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
2026-09-07 9:42 [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity() Vincent Donnefort
2026-09-07 9:44 ` Vincent Donnefort
@ 2026-09-07 9:51 ` sashiko-bot
2026-09-07 14:41 ` Masami Hiramatsu
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-09-07 9:51 UTC (permalink / raw)
To: Vincent Donnefort; +Cc: linux-trace-kernel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Typo in the newly added docstring for ring_buffer_capacity().
--
commit 0916229b26fe9d5e8fd8143432df2554e399aa85
Author: Vincent Donnefort <vdonnefort@google.com>
ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
"capacity" refers to the memory available for events while "size" refers to
the raw allocation. ring_buffer_size() actually calculates event capacity, so
rename it to ring_buffer_capacity() to match this convention.
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 9c03a555a6ba2..2940ff7633542 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
[ ... ]
> @@ -6547,18 +6547,23 @@ void ring_buffer_iter_advance(struct ring_buffer_iter *iter)
> EXPORT_SYMBOL_GPL(ring_buffer_iter_advance);
>
> /**
> - * ring_buffer_size - return the size of the ring buffer (in bytes)
> + * ring_buffer_capacity - return the capacity of the ring buffer (in bytes)
> * @buffer: The ring buffer.
> - * @cpu: The CPU to get ring buffer size from.
> + * @cpu: The CPU to get ring buffer capacity from.
> + *
> + * Capacity is the total memory available for recording event data in the
> + * ring buffer. It excludes subbufer headers.
[Severity: Low]
This isn't a bug, but there is a typo here (subbufer instead of subbuffer).
> + *
> + * Returns the capacity in bytes, or 0 if the CPU is not set in the buffer mask.
> */
> -unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu)
> +unsigned long ring_buffer_capacity(struct trace_buffer *buffer, int cpu)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907094238.3624013-1-vdonnefort@google.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
2026-09-07 9:42 [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity() Vincent Donnefort
2026-09-07 9:44 ` Vincent Donnefort
2026-09-07 9:51 ` sashiko-bot
@ 2026-09-07 14:41 ` Masami Hiramatsu
2026-09-07 16:39 ` Vincent Donnefort
2 siblings, 1 reply; 5+ messages in thread
From: Masami Hiramatsu @ 2026-09-07 14:41 UTC (permalink / raw)
To: Vincent Donnefort
Cc: rostedt, linux-trace-kernel, mathieu.desnoyers, kernel-team,
linux-kernel
On Mon, 7 Sep 2026 10:42:38 +0100
Vincent Donnefort <vdonnefort@google.com> wrote:
> Since commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring
> buffer readers"), "capacity" refers to the memory available for events
> (excluding subbuffer headers) while "size" refers to the raw allocation.
> ring_buffer_size() actually calculates this event capacity. Rename it to
> ring_buffer_capacity() to align with this convention.
I think this is OK, but I have a question.
[...]
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 8658cad53cb5..f0251788ec75 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -4712,9 +4712,9 @@ void trace_set_buffer_entries(struct array_buffer *buf, unsigned long val)
> static void update_buffer_entries(struct array_buffer *buf, int cpu)
> {
> if (cpu == RING_BUFFER_ALL_CPUS) {
> - trace_set_buffer_entries(buf, ring_buffer_size(buf->buffer, 0));
> + trace_set_buffer_entries(buf, ring_buffer_capacity(buf->buffer, 0));
> } else {
> - per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_size(buf->buffer, cpu);
> + per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_capacity(buf->buffer, cpu);
nit: Don't we need to re-word this "entries" with "capacity" too?
Actually, this "entries" is a bit odd because
- ring_buffer_entries() returns the number of events.
- trace_set_buffer_entries() sets the buffer capacity in bytes.
It seems we call it as "entries" historical reason, but now it becomes the
source of confusion. Maybe we should change it too. (but in the separate patch)
Thanks,
> }
> }
>
> @@ -8476,7 +8476,7 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int
>
> /* Allocate the first page for all buffers */
> trace_set_buffer_entries(&tr->array_buffer,
> - ring_buffer_size(tr->array_buffer.buffer, 0));
> + ring_buffer_capacity(tr->array_buffer.buffer, 0));
>
> return 0;
> }
>
> base-commit: df2908090cda368b01ff43709f51890076c56157
> --
> 2.55.0.979.g7e5102b832-goog
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity()
2026-09-07 14:41 ` Masami Hiramatsu
@ 2026-09-07 16:39 ` Vincent Donnefort
0 siblings, 0 replies; 5+ messages in thread
From: Vincent Donnefort @ 2026-09-07 16:39 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: rostedt, linux-trace-kernel, mathieu.desnoyers, kernel-team,
linux-kernel
On Mon, Sep 07, 2026 at 11:41:46PM +0900, Masami Hiramatsu wrote:
> On Mon, 7 Sep 2026 10:42:38 +0100
> Vincent Donnefort <vdonnefort@google.com> wrote:
>
> > Since commit 8a5f63637890 ("ring-buffer: Fix subbuf resize race with ring
> > buffer readers"), "capacity" refers to the memory available for events
> > (excluding subbuffer headers) while "size" refers to the raw allocation.
> > ring_buffer_size() actually calculates this event capacity. Rename it to
> > ring_buffer_capacity() to align with this convention.
>
> I think this is OK, but I have a question.
>
> [...]
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index 8658cad53cb5..f0251788ec75 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> > @@ -4712,9 +4712,9 @@ void trace_set_buffer_entries(struct array_buffer *buf, unsigned long val)
> > static void update_buffer_entries(struct array_buffer *buf, int cpu)
> > {
> > if (cpu == RING_BUFFER_ALL_CPUS) {
> > - trace_set_buffer_entries(buf, ring_buffer_size(buf->buffer, 0));
> > + trace_set_buffer_entries(buf, ring_buffer_capacity(buf->buffer, 0));
> > } else {
> > - per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_size(buf->buffer, cpu);
> > + per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_capacity(buf->buffer, cpu);
>
> nit: Don't we need to re-word this "entries" with "capacity" too?
>
> Actually, this "entries" is a bit odd because
>
> - ring_buffer_entries() returns the number of events.
> - trace_set_buffer_entries() sets the buffer capacity in bytes.
>
> It seems we call it as "entries" historical reason, but now it becomes the
> source of confusion. Maybe we should change it too. (but in the separate patch)
>
> Thanks,
Yes, I believe you're right, this "entries" here seems only used for
buffer_size_kb, buffer_total_size_kb and resize_buffer_duplicate_size() so we
can probably use "capacity" there too, it'll be less confusing than "entries".
I'll respin a v2 with that additional patch. (and a fix to the typo)
--
Vincent
>
> > }
> > }
> >
> > @@ -8476,7 +8476,7 @@ int allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int
> >
> > /* Allocate the first page for all buffers */
> > trace_set_buffer_entries(&tr->array_buffer,
> > - ring_buffer_size(tr->array_buffer.buffer, 0));
> > + ring_buffer_capacity(tr->array_buffer.buffer, 0));
> >
> > return 0;
> > }
> >
> > base-commit: df2908090cda368b01ff43709f51890076c56157
> > --
> > 2.55.0.979.g7e5102b832-goog
> >
>
>
> --
> Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-07 16:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 9:42 [PATCH v1] ring-buffer: Rename ring_buffer_size() to ring_buffer_capacity() Vincent Donnefort
2026-09-07 9:44 ` Vincent Donnefort
2026-09-07 9:51 ` sashiko-bot
2026-09-07 14:41 ` Masami Hiramatsu
2026-09-07 16:39 ` Vincent Donnefort
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox