Linux Trace Kernel
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org,
	mathieu.desnoyers@efficios.com, kernel-team@android.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] ring-buffer: Skip si_mem_available() for persistent and remote buffers
Date: Thu, 15 Oct 2026 09:39:31 +0100	[thread overview]
Message-ID: <atCRQ3HRmWgKEJGl@google.com> (raw)
In-Reply-To: <20261014175126.49c26f93@gandalf.local.home>

On Wed, Oct 14, 2026 at 05:51:26PM -0400, Steven Rostedt wrote:
> On Tue, 13 Oct 2026 11:20:46 +0100
> Vincent Donnefort <vdonnefort@google.com> wrote:
> 
> > Persistent and remote buffer memory is pre-allocated by the time
> > __rb_allocate_pages() is called. Skip si_mem_available() to avoid
> > wrongly failing the allocation under memory pressure.
> > 
> > For the same reason, unset user_thread.
> > 
> > Fixes: be68d63a139b ("ring-buffer: Add ring_buffer_alloc_range()")
> > Fixes: 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes")
> > Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
> > ---
> >  kernel/trace/ring_buffer.c | 41 +++++++++++++++++++-------------------
> >  1 file changed, 21 insertions(+), 20 deletions(-)
> > 
> > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> > index 04bb94c29f58..b3a30a0413a5 100644
> > --- a/kernel/trace/ring_buffer.c
> > +++ b/kernel/trace/ring_buffer.c
> > @@ -2442,20 +2442,30 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
> >  	struct trace_buffer *buffer = cpu_buffer->buffer;
> >  	struct ring_buffer_cpu_meta *meta = NULL;
> >  	struct buffer_page *bpage, *tmp;
> > -	bool user_thread = current->mm != NULL;
> >  	struct ring_buffer_desc *desc = NULL;
> > +	bool user_thread = false;
> >  	long i;
> >  
> > -	/*
> > -	 * Check if the available memory is there first.
> > -	 * Note, si_mem_available() only gives us a rough estimate of available
> > -	 * memory. It may not be accurate. But we don't care, we just want
> > -	 * to prevent doing any allocation when it is obvious that it is
> > -	 * not going to succeed.
> > -	 */
> > -	i = si_mem_available();
> > -	if (i < nr_pages)
> > -		return -ENOMEM;
> > +	if (buffer->range_addr_start) {
> > +		meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
> > +	} else if (buffer->remote) {
> > +		desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
> > +		if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
> > +			return -EINVAL;
> > +	} else {
> > +		/*
> > +		 * Check if the available memory is there first.
> > +		 * Note, si_mem_available() only gives us a rough estimate of available
> > +		 * memory. It may not be accurate. But we don't care, we just want
> > +		 * to prevent doing any allocation when it is obvious that it is
> > +		 * not going to succeed.
> > +		 */
> > +		i = si_mem_available();
> > +		if (i < nr_pages)
> > +			return -ENOMEM;
> > +
> > +		user_thread = current->mm != NULL;
> 
> Not caused by this patch but we need to update this to:
> 
> 		user_thread = is_user_task(current);
> 
> I may add that.

I can send a v3 if that helps.

-- 
Vincent

> 
> -- Steve
> 
> > +	}
> >  
> >  	/*
> >  	 * If a user thread allocates too much, and si_mem_available()
> > @@ -2469,15 +2479,6 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
> >  	if (user_thread)
> >  		set_current_oom_origin();
> >  
> > -	if (buffer->range_addr_start)
> > -		meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
> > -
> > -	if (buffer->remote) {
> > -		desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
> > -		if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
> > -			return -EINVAL;
> > -	}
> > -
> >  	for (i = 0; i < nr_pages; i++) {
> >  
> >  		bpage = alloc_cpu_page(cpu_buffer->cpu);
> 

  reply	other threads:[~2026-10-15  8:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 10:20 [PATCH v2 0/2] ring-buffer: Fixes for available memory estimation Vincent Donnefort
2026-10-13 10:20 ` [PATCH v2 1/2] ring-buffer: Skip si_mem_available() for persistent and remote buffers Vincent Donnefort
2026-10-14 21:51   ` Steven Rostedt
2026-10-15  8:39     ` Vincent Donnefort [this message]
2026-10-15 12:52       ` Steven Rostedt
2026-10-13 10:20 ` [PATCH v2 2/2] ring-buffer: Use subbuf_order in available memory estimation Vincent Donnefort
2026-10-14 23:22   ` Masami Hiramatsu

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=atCRQ3HRmWgKEJGl@google.com \
    --to=vdonnefort@google.com \
    --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=rostedt@goodmis.org \
    /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