linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux trace kernel <linux-trace-kernel@vger.kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: Re: [PATCH] ring-buffer: Fix memory leak of free page
Date: Mon, 11 Dec 2023 21:23:19 +0900	[thread overview]
Message-ID: <20231211212319.d1a714d0139e4fd893183b9e@kernel.org> (raw)
In-Reply-To: <20231210221250.7b9cc83c@rorschach.local.home>

On Sun, 10 Dec 2023 22:12:50 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Reading the ring buffer does a swap of a sub-buffer within the ring buffer
> with a empty sub-buffer. This allows the reader to have full access to the
> content of the sub-buffer that was swapped out without having to worry
> about contention with the writer.
> 
> The readers call ring_buffer_alloc_read_page() to allocate a page that
> will be used to swap with the ring buffer. When the code is finished with
> the reader page, it calls ring_buffer_free_read_page(). Instead of freeing
> the page, it stores it as a spare. Then next call to
> ring_buffer_alloc_read_page() will return this spare instead of calling
> into the memory management system to allocate a new page.
> 
> Unfortunately, on freeing of the ring buffer, this spare page is not
> freed, and causes a memory leak.
> 

Oops, Looks good to me.

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

Thanks,

> Cc: stable@vger.kernel.org
> Fixes: 73a757e63114d ("ring-buffer: Return reader page back into existing ring buffer")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/ring_buffer.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index a38e5a3c6803..dd37d21d6e55 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -1790,6 +1790,8 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
>  		free_buffer_page(bpage);
>  	}
>  
> +	free_page((unsigned long)cpu_buffer->free_page);
> +
>  	kfree(cpu_buffer);
>  }
>  
> -- 
> 2.42.0
> 


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

      reply	other threads:[~2023-12-11 12:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11  3:12 [PATCH] ring-buffer: Fix memory leak of free page Steven Rostedt
2023-12-11 12:23 ` Masami Hiramatsu [this message]

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=20231211212319.d1a714d0139e4fd893183b9e@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --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;
as well as URLs for NNTP newsgroup(s).