ring-buffer: Skip si_mem_available() for persistent and remote buffers

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.

Link: https://patch.msgid.link/[email protected]
Fixes: be68d63a13 ("ring-buffer: Add ring_buffer_alloc_range()")
Fixes: 2e67fabd8b ("ring-buffer: Introduce ring-buffer remotes")
Signed-off-by: Vincent Donnefort <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
This commit is contained in:
Vincent Donnefort authored and Steven Rostedt committed 2026-10-14 19:03:40 -04:00
1 parent 2cd88c498e
commit c9fc60c18b
1 file changed
+21 -20
+21 -20
View File
@@ -2445,20 +2445,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;
}
/*
* If a user thread allocates too much, and si_mem_available()
@@ -2472,15 +2482,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);