public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Optimize relay_alloc_page_array() slightly by using vzalloc rather than vmalloc and memset
@ 2010-10-30 20:26 Jesper Juhl
  2010-10-30 21:47 ` Mathieu Desnoyers
  0 siblings, 1 reply; 19+ messages in thread
From: Jesper Juhl @ 2010-10-30 20:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Tom Zanussi, Karim Yaghmour, Mathieu Desnoyers,
	Paul Mundt

Hi,

We can optimize kernel/relay.c::relay_alloc_page_array() slightly by using 
vzalloc. The patch makes these changes:

 - use vzalloc instead of vmalloc+memset.
 - remove redundant local variable 'array'.
 - declare local 'pa_size' as const.

Cuts down nicely on both source and object-code size.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
Compile tested only.

 relay.c |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index c7cf397..859ea5a 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -70,17 +70,10 @@ static const struct vm_operations_struct relay_file_mmap_ops = {
  */
 static struct page **relay_alloc_page_array(unsigned int n_pages)
 {
-	struct page **array;
-	size_t pa_size = n_pages * sizeof(struct page *);
-
-	if (pa_size > PAGE_SIZE) {
-		array = vmalloc(pa_size);
-		if (array)
-			memset(array, 0, pa_size);
-	} else {
-		array = kzalloc(pa_size, GFP_KERNEL);
-	}
-	return array;
+	const size_t pa_size = n_pages * sizeof(struct page *);
+	if (pa_size > PAGE_SIZE)
+		return vzalloc(pa_size);
+	return kzalloc(pa_size, GFP_KERNEL);
 }
 
 /*



-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-11-01 18:36 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-30 20:26 [PATCH] Optimize relay_alloc_page_array() slightly by using vzalloc rather than vmalloc and memset Jesper Juhl
2010-10-30 21:47 ` Mathieu Desnoyers
2010-10-30 21:50   ` Jesper Juhl
2010-10-31 18:39     ` Mathieu Desnoyers
2010-11-01  0:46       ` Andrew Morton
2010-11-01  6:58         ` Pekka Enberg
2010-11-01 11:27         ` Mathieu Desnoyers
2010-11-01 12:26           ` Américo Wang
2010-11-01 13:38         ` Mathieu Desnoyers
2010-11-01 12:22       ` Américo Wang
2010-11-01 13:00         ` el es
2010-11-01 12:48   ` Jens Axboe
2010-11-01 13:08     ` Mathieu Desnoyers
2010-11-01 13:34       ` Jens Axboe
2010-11-01 13:41       ` Pekka Enberg
2010-11-01 13:42         ` Jens Axboe
2010-11-01 16:00           ` Mathieu Desnoyers
2010-11-01 18:02             ` Jesper Juhl
2010-11-01 18:26               ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox