Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH -mm] relayfs: support larger relay buffer

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


mhiramat at redhat

Apr 15, 2008, 8:27 AM

Post #1 of 5 (158 views)
Permalink
[PATCH -mm] relayfs: support larger relay buffer

Use vmalloc() and memset() instead of kcalloc() to allocate a page* array
when the array size is bigger than one page. This enables relayfs to support
bigger relay buffers than 64MB on 4k-page system, 512MB on 16k-page system.

Signed-off-by: Masami Hiramatsu <mhiramat [at] redhat>
---
This is useful for a 64-bit system which has a plenty of memory (tens of
giga bytes) and a large kernel memory space.

I tested it on x86-64 and ia64.

kernel/relay.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

Index: 2.6.25-rc8-mm2/kernel/relay.c
===================================================================
--- 2.6.25-rc8-mm2.orig/kernel/relay.c
+++ 2.6.25-rc8-mm2/kernel/relay.c
@@ -104,12 +104,20 @@ static int relay_mmap_buf(struct rchan_b
static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)
{
void *mem;
- unsigned int i, j, n_pages;
+ unsigned int i, j, n_pages, pa_size;

*size = PAGE_ALIGN(*size);
n_pages = *size >> PAGE_SHIFT;
+ pa_size = n_pages * sizeof(struct page *);

- buf->page_array = kcalloc(n_pages, sizeof(struct page *), GFP_KERNEL);
+ if (pa_size > PAGE_SIZE) {
+ buf->page_array = vmalloc(pa_size);
+ if (buf->page_array)
+ memset(buf->page_array, 0, pa_size);
+ } else {
+ buf->page_array = kcalloc(n_pages, sizeof(struct page *),
+ GFP_KERNEL);
+ }
if (!buf->page_array)
return NULL;

@@ -130,7 +138,10 @@ static void *relay_alloc_buf(struct rcha
depopulate:
for (j = 0; j < i; j++)
__free_page(buf->page_array[j]);
- kfree(buf->page_array);
+ if (pa_size > PAGE_SIZE)
+ vfree(buf->page_array);
+ else
+ kfree(buf->page_array);
return NULL;
}

@@ -189,7 +200,10 @@ static void relay_destroy_buf(struct rch
vunmap(buf->start);
for (i = 0; i < buf->page_count; i++)
__free_page(buf->page_array[i]);
- kfree(buf->page_array);
+ if (buf->page_count * sizeof(struct page *) > PAGE_SIZE)
+ vfree(buf->page_array);
+ else
+ kfree(buf->page_array);
}
chan->buf[buf->cpu] = NULL;
kfree(buf->padding);
--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat [at] redhat


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


zanussi at comcast

Apr 15, 2008, 9:22 PM

Post #2 of 5 (149 views)
Permalink
Re: [PATCH -mm] relayfs: support larger relay buffer [In reply to]

On Tue, 2008-04-15 at 11:27 -0400, Masami Hiramatsu wrote:
> Use vmalloc() and memset() instead of kcalloc() to allocate a page* array
> when the array size is bigger than one page. This enables relayfs to support
> bigger relay buffers than 64MB on 4k-page system, 512MB on 16k-page system.
>
> Signed-off-by: Masami Hiramatsu <mhiramat [at] redhat>
> ---
> This is useful for a 64-bit system which has a plenty of memory (tens of
> giga bytes) and a large kernel memory space.
>
> I tested it on x86-64 and ia64.
>

Hi,

It looks ok to me, but it might be a little cleaner and avoid some
duplication if you add the new code as a couple of functions instead.
Just a suggestion...

Tom

> kernel/relay.c | 22 ++++++++++++++++++----
> 1 file changed, 18 insertions(+), 4 deletions(-)
>
> Index: 2.6.25-rc8-mm2/kernel/relay.c
> ===================================================================
> --- 2.6.25-rc8-mm2.orig/kernel/relay.c
> +++ 2.6.25-rc8-mm2/kernel/relay.c
> @@ -104,12 +104,20 @@ static int relay_mmap_buf(struct rchan_b
> static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)
> {
> void *mem;
> - unsigned int i, j, n_pages;
> + unsigned int i, j, n_pages, pa_size;
>
> *size = PAGE_ALIGN(*size);
> n_pages = *size >> PAGE_SHIFT;
> + pa_size = n_pages * sizeof(struct page *);
>
> - buf->page_array = kcalloc(n_pages, sizeof(struct page *), GFP_KERNEL);
> + if (pa_size > PAGE_SIZE) {
> + buf->page_array = vmalloc(pa_size);
> + if (buf->page_array)
> + memset(buf->page_array, 0, pa_size);
> + } else {
> + buf->page_array = kcalloc(n_pages, sizeof(struct page *),
> + GFP_KERNEL);
> + }
> if (!buf->page_array)
> return NULL;
>
> @@ -130,7 +138,10 @@ static void *relay_alloc_buf(struct rcha
> depopulate:
> for (j = 0; j < i; j++)
> __free_page(buf->page_array[j]);
> - kfree(buf->page_array);
> + if (pa_size > PAGE_SIZE)
> + vfree(buf->page_array);
> + else
> + kfree(buf->page_array);
> return NULL;
> }
>
> @@ -189,7 +200,10 @@ static void relay_destroy_buf(struct rch
> vunmap(buf->start);
> for (i = 0; i < buf->page_count; i++)
> __free_page(buf->page_array[i]);
> - kfree(buf->page_array);
> + if (buf->page_count * sizeof(struct page *) > PAGE_SIZE)
> + vfree(buf->page_array);
> + else
> + kfree(buf->page_array);
> }
> chan->buf[buf->cpu] = NULL;
> kfree(buf->padding);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


penberg at cs

Apr 16, 2008, 1:33 AM

Post #3 of 5 (150 views)
Permalink
Re: [PATCH -mm] relayfs: support larger relay buffer [In reply to]

On Tue, Apr 15, 2008 at 6:27 PM, Masami Hiramatsu <mhiramat [at] redhat> wrote:
> Use vmalloc() and memset() instead of kcalloc() to allocate a page* array
> when the array size is bigger than one page. This enables relayfs to support
> bigger relay buffers than 64MB on 4k-page system, 512MB on 16k-page system.
>
> Signed-off-by: Masami Hiramatsu <mhiramat [at] redhat>
> ---
> @@ -130,7 +138,10 @@ static void *relay_alloc_buf(struct rcha
> depopulate:
> for (j = 0; j < i; j++)
> __free_page(buf->page_array[j]);
> - kfree(buf->page_array);
> + if (pa_size > PAGE_SIZE)

You can use is_vmalloc_addr() here.

> + vfree(buf->page_array);
> + else
> + kfree(buf->page_array);
> return NULL;
> }
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


mhiramat at redhat

Apr 16, 2008, 7:36 AM

Post #4 of 5 (149 views)
Permalink
Re: [PATCH -mm] relayfs: support larger relay buffer [In reply to]

Hi Pekka,

Pekka Enberg wrote:
> On Tue, Apr 15, 2008 at 6:27 PM, Masami Hiramatsu <mhiramat [at] redhat> wrote:
>> Use vmalloc() and memset() instead of kcalloc() to allocate a page* array
>> when the array size is bigger than one page. This enables relayfs to support
>> bigger relay buffers than 64MB on 4k-page system, 512MB on 16k-page system.
>>
>> Signed-off-by: Masami Hiramatsu <mhiramat [at] redhat>
>> ---
>> @@ -130,7 +138,10 @@ static void *relay_alloc_buf(struct rcha
>> depopulate:
>> for (j = 0; j < i; j++)
>> __free_page(buf->page_array[j]);
>> - kfree(buf->page_array);
>> + if (pa_size > PAGE_SIZE)
>
> You can use is_vmalloc_addr() here.

Thank you for your good advice!
I'll use that.

>
>> + vfree(buf->page_array);
>> + else
>> + kfree(buf->page_array);
>> return NULL;
>> }
>>

--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat [at] redhat

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


mhiramat at redhat

Apr 16, 2008, 9:19 AM

Post #5 of 5 (147 views)
Permalink
Re: [PATCH -mm] relayfs: support larger relay buffer [In reply to]

Hi Tom,

Tom Zanussi wrote:
> On Tue, 2008-04-15 at 11:27 -0400, Masami Hiramatsu wrote:
>> Use vmalloc() and memset() instead of kcalloc() to allocate a page* array
>> when the array size is bigger than one page. This enables relayfs to support
>> bigger relay buffers than 64MB on 4k-page system, 512MB on 16k-page system.
>>
>> Signed-off-by: Masami Hiramatsu <mhiramat [at] redhat>
>> ---
>> This is useful for a 64-bit system which has a plenty of memory (tens of
>> giga bytes) and a large kernel memory space.
>>
>> I tested it on x86-64 and ia64.
>>
>
> Hi,
>
> It looks ok to me, but it might be a little cleaner and avoid some
> duplication if you add the new code as a couple of functions instead.
> Just a suggestion...

Sure, that is a good idea, I'll renew my patch.
Thank you,

--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat [at] redhat

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.