From: Steven Rostedt <rostedt@goodmis.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org,
mathieu.desnoyers@efficios.com, kernel-team@android.com,
linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH 1/6] ring-buffer: Fix subbuf resize concurrency
Date: Mon, 10 Aug 2026 18:27:03 -0400 [thread overview]
Message-ID: <20260810182703.6b348465@gandalf.local.home> (raw)
In-Reply-To: <20260810125633.3344684-2-vdonnefort@google.com>
On Mon, 10 Aug 2026 13:56:28 +0100
Vincent Donnefort <vdonnefort@google.com> wrote:
> +static __always_inline unsigned int rb_subbuf_size(struct trace_buffer *buffer)
> +{
> + return PAGE_SIZE << buffer->subbuf_order;
> +}
> @@ -3513,7 +3524,7 @@ rb_event_index(struct ring_buffer_per_cpu *cpu_buffer, struct ring_buffer_event
> {
> unsigned long addr = (unsigned long)event;
>
> - addr &= (PAGE_SIZE << cpu_buffer->buffer->subbuf_order) - 1;
> + addr &= (unsigned long)rb_subbuf_size(cpu_buffer->buffer) - 1;
This one is fine because it already sits in a helper function.
>
> return addr - BUF_PAGE_HDR_SIZE;
> }
> @@ -4102,7 +4113,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
> new_index = rb_event_index(cpu_buffer, event);
> old_index = new_index + rb_event_ts_length(event);
> addr = (unsigned long)event;
> - addr &= ~((PAGE_SIZE << cpu_buffer->buffer->subbuf_order) - 1);
> + addr &= ~((unsigned long)rb_subbuf_size(cpu_buffer->buffer) - 1);
>
> bpage = READ_ONCE(cpu_buffer->tail_page);
>
> @@ -5012,7 +5023,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
> struct buffer_page *bpage = cpu_buffer->commit_page;
> struct buffer_page *start;
>
> - addr &= ~((PAGE_SIZE << cpu_buffer->buffer->subbuf_order) - 1);
> + addr &= ~((unsigned long)rb_subbuf_size(cpu_buffer->buffer) - 1);
>
> /* Do the likely case first */
> if (likely(bpage->page == (void *)addr)) {
I really hate the above open coded typecasting to get the address correct.
Seems very fragile to me. As it is getting the address of the sub buffer,
let's add another helper function:
/**
* rb_subbuf_addr - Return the address of the start of a subbuffer
* @cpu_buffer: The cpu buffer that @addr is on
* @addr: An address of an event on a subbuffer
*
* Returns: The start of the subbuffer for where @addr sits
*/
static __always_inline unsigned long rb_subbuf_addr(struct ring_buffer_per_cpu *cpu_buffer,
unsigned long addr)
{
return addr & ~((unsigned long)(rb_subbuf_size(cpu_buffer->buffer) - 1));
}
And use that for these locatons.
-- Steve
next prev parent reply other threads:[~2026-08-10 22:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 12:56 [PATCH 0/6] ring-buffer: Fixes for subbuf resizing and persistent buffers Vincent Donnefort
2026-08-10 12:56 ` [PATCH 1/6] ring-buffer: Fix subbuf resize concurrency Vincent Donnefort
2026-08-10 22:27 ` Steven Rostedt [this message]
2026-08-10 12:56 ` [PATCH 2/6] ring-buffer: Dynamically calculate max_data_size Vincent Donnefort
2026-08-10 12:56 ` [PATCH 3/6] ring-buffer: Free cpu_buffer->free_page with subbuf_order Vincent Donnefort
2026-08-10 12:56 ` [PATCH 4/6] ring-buffer: Remove trace_buffer::cpus Vincent Donnefort
2026-08-10 12:56 ` [PATCH 5/6] ring-buffer: Remove ring_buffer_per_cpu::mapped Vincent Donnefort
2026-08-10 12:56 ` [PATCH 6/6] ring-buffer: Make nr_pages unsigned int 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=20260810182703.6b348465@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=vdonnefort@google.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;
as well as URLs for NNTP newsgroup(s).