mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunfeng Ye <yeyunfeng@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@redhat.co>, <namhyung@kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] perf/ring_buffer: Matching the memory allocate and free, in rb_alloc()
Date: Fri, 27 Sep 2019 16:24:47 +0800	[thread overview]
Message-ID: <68211803-de9a-cae1-2627-6a5e5ae0853b@huawei.com> (raw)
In-Reply-To: <4d308608-54e2-05fa-5a1a-9cb7b4986bd1@huawei.com>

Currently perf_mmap_alloc_page() is used to allocate memory in
rb_alloc(), but using free_page() to free memory in the failure path.

It's better to use perf_mmap_free_page() instead.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 kernel/events/ring_buffer.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index abc145c..246c83a 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -754,6 +754,14 @@ static void *perf_mmap_alloc_page(int cpu)
 	return page_address(page);
 }

+static void perf_mmap_free_page(void *addr)
+{
+	struct page *page = virt_to_page(addr);
+
+	page->mapping = NULL;
+	__free_page(page);
+}
+
 struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
 {
 	struct ring_buffer *rb;
@@ -788,9 +796,9 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)

 fail_data_pages:
 	for (i--; i >= 0; i--)
-		free_page((unsigned long)rb->data_pages[i]);
+		perf_mmap_free_page(rb->data_pages[i]);

-	free_page((unsigned long)rb->user_page);
+	perf_mmap_free_page(rb->user_page);

 fail_user_page:
 	kfree(rb);
@@ -799,14 +807,6 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
 	return NULL;
 }

-static void perf_mmap_free_page(void *addr)
-{
-	struct page *page = virt_to_page(addr);
-
-	page->mapping = NULL;
-	__free_page(page);
-}
-
 void rb_free(struct ring_buffer *rb)
 {
 	int i;
-- 
2.7.4


  reply	other threads:[~2019-09-27  8:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-27  8:22 [PATCH 1/2] perf/ring_buffer: Modify the parameter type of perf_mmap_free_page() Yunfeng Ye
2019-09-27  8:24 ` Yunfeng Ye [this message]
2019-10-14  8:15   ` [PATCH 2/2] perf/ring_buffer: Matching the memory allocate and free, in rb_alloc() Yunfeng Ye
2019-10-18 12:48     ` [tip: perf/core] " tip-bot2 for Yunfeng Ye
2019-10-14  8:14 ` [PATCH 1/2] perf/ring_buffer: Modify the parameter type of perf_mmap_free_page() Yunfeng Ye
2019-10-18 12:48   ` [tip: perf/core] " tip-bot2 for Yunfeng Ye

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=68211803-de9a-cae1-2627-6a5e5ae0853b@huawei.com \
    --to=yeyunfeng@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.co \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®