2019-09-27 08:25:39

by Yunfeng Ye

[permalink] [raw]
Subject: [PATCH 1/2] perf/ring_buffer: Modify the parameter type of perf_mmap_free_page()

In perf_mmap_free_page(), the unsigned long type is converted to the
pointer type, but where the call is made, the pointer type is converted
to the unsigned long type. There is no need to do these operations.

Modify the parameter type of perf_mmap_free_page() to pointer type.

Signed-off-by: Yunfeng Ye <[email protected]>
---
kernel/events/ring_buffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index ffb59a4..abc145c 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -799,9 +799,9 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
return NULL;
}

-static void perf_mmap_free_page(unsigned long addr)
+static void perf_mmap_free_page(void *addr)
{
- struct page *page = virt_to_page((void *)addr);
+ struct page *page = virt_to_page(addr);

page->mapping = NULL;
__free_page(page);
@@ -811,9 +811,9 @@ void rb_free(struct ring_buffer *rb)
{
int i;

- perf_mmap_free_page((unsigned long)rb->user_page);
+ perf_mmap_free_page(rb->user_page);
for (i = 0; i < rb->nr_pages; i++)
- perf_mmap_free_page((unsigned long)rb->data_pages[i]);
+ perf_mmap_free_page(rb->data_pages[i]);
kfree(rb);
}

--
2.7.4


2019-09-27 08:27:37

by Yunfeng Ye

[permalink] [raw]
Subject: [PATCH 2/2] perf/ring_buffer: Matching the memory allocate and free, in rb_alloc()

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 <[email protected]>
---
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

2019-10-14 08:17:58

by Yunfeng Ye

[permalink] [raw]
Subject: [PATCH 2/2] perf/ring_buffer: Matching the memory allocate and free, in rb_alloc()

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 <[email protected]>
---
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


2019-10-14 08:18:02

by Yunfeng Ye

[permalink] [raw]
Subject: [PATCH 1/2] perf/ring_buffer: Modify the parameter type of perf_mmap_free_page()

In perf_mmap_free_page(), the unsigned long type is converted to the
pointer type, but where the call is made, the pointer type is converted
to the unsigned long type. There is no need to do these operations.

Modify the parameter type of perf_mmap_free_page() to pointer type.

Signed-off-by: Yunfeng Ye <[email protected]>
---
kernel/events/ring_buffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index ffb59a4..abc145c 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -799,9 +799,9 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
return NULL;
}

-static void perf_mmap_free_page(unsigned long addr)
+static void perf_mmap_free_page(void *addr)
{
- struct page *page = virt_to_page((void *)addr);
+ struct page *page = virt_to_page(addr);

page->mapping = NULL;
__free_page(page);
@@ -811,9 +811,9 @@ void rb_free(struct ring_buffer *rb)
{
int i;

- perf_mmap_free_page((unsigned long)rb->user_page);
+ perf_mmap_free_page(rb->user_page);
for (i = 0; i < rb->nr_pages; i++)
- perf_mmap_free_page((unsigned long)rb->data_pages[i]);
+ perf_mmap_free_page(rb->data_pages[i]);
kfree(rb);
}

--
2.7.4

Subject: [tip: perf/core] perf/ring_buffer: Matching the memory allocate and free, in rb_alloc()

The following commit has been merged into the perf/core branch of tip:

Commit-ID: d7e78706e43107fa269fe34b1a69e653f5ec9f2c
Gitweb: https://git.kernel.org/tip/d7e78706e43107fa269fe34b1a69e653f5ec9f2c
Author: Yunfeng Ye <[email protected]>
AuthorDate: Mon, 14 Oct 2019 16:15:57 +08:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Thu, 17 Oct 2019 21:31:55 +02:00

perf/ring_buffer: Matching the memory allocate and free, in rb_alloc()

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 <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
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 @@ fail:
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;

Subject: [tip: perf/core] perf/ring_buffer: Modify the parameter type of perf_mmap_free_page()

The following commit has been merged into the perf/core branch of tip:

Commit-ID: 8a9f91c51ea72b126864e0db616b1bac12261200
Gitweb: https://git.kernel.org/tip/8a9f91c51ea72b126864e0db616b1bac12261200
Author: Yunfeng Ye <[email protected]>
AuthorDate: Mon, 14 Oct 2019 16:14:59 +08:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Thu, 17 Oct 2019 21:31:55 +02:00

perf/ring_buffer: Modify the parameter type of perf_mmap_free_page()

In perf_mmap_free_page(), the unsigned long type is converted to the
pointer type, but where the call is made, the pointer type is converted
to the unsigned long type. There is no need to do these operations.

Modify the parameter type of perf_mmap_free_page() to pointer type.

Signed-off-by: Yunfeng Ye <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
kernel/events/ring_buffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index ffb59a4..abc145c 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -799,9 +799,9 @@ fail:
return NULL;
}

-static void perf_mmap_free_page(unsigned long addr)
+static void perf_mmap_free_page(void *addr)
{
- struct page *page = virt_to_page((void *)addr);
+ struct page *page = virt_to_page(addr);

page->mapping = NULL;
__free_page(page);
@@ -811,9 +811,9 @@ void rb_free(struct ring_buffer *rb)
{
int i;

- perf_mmap_free_page((unsigned long)rb->user_page);
+ perf_mmap_free_page(rb->user_page);
for (i = 0; i < rb->nr_pages; i++)
- perf_mmap_free_page((unsigned long)rb->data_pages[i]);
+ perf_mmap_free_page(rb->data_pages[i]);
kfree(rb);
}