mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ring-buffer: Update pages_touched to reflect persistent  buffer content
@ 2025-02-14 17:35 Steven Rostedt
  2025-02-15 15:17 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2025-02-14 17:35 UTC (permalink / raw)
  To: LKML, Linux Trace Kernel
  Cc: Masami Hiramatsu, Mathieu Desnoyers, Vincent Donnefort

From: Steven Rostedt <rostedt@goodmis.org>

The pages_touched field represents the number of subbuffers in the ring
buffer that have content that can be read. This is used in accounting of
"dirty_pages" and "buffer_percent" to allow the user to wait for the
buffer to be filled to a certain amount before it reads the buffer in
blocking mode.

The persistent buffer never updated this value so it was set to zero, and
this accounting would take it as it had no content. This would cause user
space to wait for content even though there's enough content in the ring
buffer that satisfies the buffer_percent.

Cc: stable@vger.kernel.org
Fixes: 5f3b6e839f3ce ("ring-buffer: Validate boot range memory events")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 0419d41a2060..bb6089c2951e 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1850,6 +1850,11 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
 				cpu_buffer->cpu);
 			goto invalid;
 		}
+
+		/* If the buffer has content, update pages_touched */
+		if (ret)
+			local_inc(&cpu_buffer->pages_touched);
+
 		entries += ret;
 		entry_bytes += local_read(&head_page->page->commit);
 		local_set(&cpu_buffer->head_page->entries, ret);
-- 
2.47.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ring-buffer: Update pages_touched to reflect persistent buffer content
  2025-02-14 17:35 [PATCH] ring-buffer: Update pages_touched to reflect persistent buffer content Steven Rostedt
@ 2025-02-15 15:17 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2025-02-15 15:17 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Linux Trace Kernel, Masami Hiramatsu, Mathieu Desnoyers,
	Vincent Donnefort

On Fri, 14 Feb 2025 12:35:12 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> The pages_touched field represents the number of subbuffers in the ring
> buffer that have content that can be read. This is used in accounting of
> "dirty_pages" and "buffer_percent" to allow the user to wait for the
> buffer to be filled to a certain amount before it reads the buffer in
> blocking mode.
> 
> The persistent buffer never updated this value so it was set to zero, and
> this accounting would take it as it had no content. This would cause user
> space to wait for content even though there's enough content in the ring
> buffer that satisfies the buffer_percent.

Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> 
> Cc: stable@vger.kernel.org
> Fixes: 5f3b6e839f3ce ("ring-buffer: Validate boot range memory events")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/ring_buffer.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 0419d41a2060..bb6089c2951e 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -1850,6 +1850,11 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
>  				cpu_buffer->cpu);
>  			goto invalid;
>  		}
> +
> +		/* If the buffer has content, update pages_touched */
> +		if (ret)
> +			local_inc(&cpu_buffer->pages_touched);
> +
>  		entries += ret;
>  		entry_bytes += local_read(&head_page->page->commit);
>  		local_set(&cpu_buffer->head_page->entries, ret);
> -- 
> 2.47.2
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-15 15:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-14 17:35 [PATCH] ring-buffer: Update pages_touched to reflect persistent buffer content Steven Rostedt
2025-02-15 15:17 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®