2016-11-15 07:28:29

by Takao Indoh

[permalink] [raw]
Subject: [PATCH] perf/ring_buffer: Fix invalid page order

In rb_alloc_aux_page(), a page order is set to MAX_ORDER when order is
greater than MAX_ORDER, but page order should be less than MAX_ORDER,
therefore alloc_pages_node fails at least once. This patch fixes page
order so that it can be always less than MAX_ORDER.

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

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 257fa46..3f76fdd 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -502,8 +502,8 @@ static struct page *rb_alloc_aux_page(int node, int order)
{
struct page *page;

- if (order > MAX_ORDER)
- order = MAX_ORDER;
+ if (order >= MAX_ORDER)
+ order = MAX_ORDER - 1;

do {
page = alloc_pages_node(node, PERF_AUX_GFP, order);
--
1.8.3.1


2016-11-15 08:48:21

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH] perf/ring_buffer: Fix invalid page order


* Takao Indoh <[email protected]> wrote:

> In rb_alloc_aux_page(), a page order is set to MAX_ORDER when order is
> greater than MAX_ORDER, but page order should be less than MAX_ORDER,
> therefore alloc_pages_node fails at least once. This patch fixes page
> order so that it can be always less than MAX_ORDER.
>
> Signed-off-by: Takao Indoh <[email protected]>
> ---
> kernel/events/ring_buffer.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
> index 257fa46..3f76fdd 100644
> --- a/kernel/events/ring_buffer.c
> +++ b/kernel/events/ring_buffer.c
> @@ -502,8 +502,8 @@ static struct page *rb_alloc_aux_page(int node, int order)
> {
> struct page *page;
>
> - if (order > MAX_ORDER)
> - order = MAX_ORDER;
> + if (order >= MAX_ORDER)
> + order = MAX_ORDER - 1;
>
> do {
> page = alloc_pages_node(node, PERF_AUX_GFP, order);

I'm wondering under what circumstances this allocation failure was seen in
practice - why did others not hit this?

Thanks,

Ingo

2016-11-15 09:11:27

by Takao Indoh

[permalink] [raw]
Subject: Re: [PATCH] perf/ring_buffer: Fix invalid page order

On 2016/11/15 17:48, Ingo Molnar wrote:
>
> * Takao Indoh <[email protected]> wrote:
>
>> In rb_alloc_aux_page(), a page order is set to MAX_ORDER when order is
>> greater than MAX_ORDER, but page order should be less than MAX_ORDER,
>> therefore alloc_pages_node fails at least once. This patch fixes page
>> order so that it can be always less than MAX_ORDER.
>>
>> Signed-off-by: Takao Indoh <[email protected]>
>> ---
>> kernel/events/ring_buffer.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
>> index 257fa46..3f76fdd 100644
>> --- a/kernel/events/ring_buffer.c
>> +++ b/kernel/events/ring_buffer.c
>> @@ -502,8 +502,8 @@ static struct page *rb_alloc_aux_page(int node, int order)
>> {
>> struct page *page;
>>
>> - if (order > MAX_ORDER)
>> - order = MAX_ORDER;
>> + if (order >= MAX_ORDER)
>> + order = MAX_ORDER - 1;
>>
>> do {
>> page = alloc_pages_node(node, PERF_AUX_GFP, order);
>
> I'm wondering under what circumstances this allocation failure was seen in
> practice - why did others not hit this?

I found this when I ran perf with -m,2048. I think in the most cases
users use default buffer size hence they does not notice.

Thanks,
Takao Indoh