All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]micro optimization of kcalloc
@ 2006-03-20 14:45 Oliver Neukum
  2006-03-20 15:14 ` Benjamin LaHaise
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Oliver Neukum @ 2006-03-20 14:45 UTC (permalink / raw)
  To: linux-kernel

Hi,

this optimises away a division in kcalloc by letting the compiler
do it. It is redone to allow size==0.

	Regards
		Oliver

Signed-off-by: Oliver Neukum <oliver@neukum.name>

--- linux-2.6.16-rc6-vanilla/include/linux/slab.h	2006-03-11 23:12:55.000000000 +0100
+++ linux-2.6.16-rc6/include/linux/slab.h	2006-03-20 14:39:36.000000000 +0100
@@ -118,7 +118,7 @@
  */
 static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
 {
-	if (n != 0 && size > INT_MAX / n)
+	if (unlikely(size != 0 && n > INT_MAX / size ))
 		return NULL;
 	return kzalloc(n * size, flags);
 }

^ permalink raw reply	[flat|nested] 10+ messages in thread
* [PATCH]micro optimization of kcalloc
@ 2006-03-20 13:08 Oliver Neukum
  0 siblings, 0 replies; 10+ messages in thread
From: Oliver Neukum @ 2006-03-20 13:08 UTC (permalink / raw)
  To: linux-kernel

Hi,

this transforms the limit check of kcalloc() so that size becomes the
divisor. This saves some kernel code, because size is always a constant,
thus turning the check into a simple comparison saving a full division.
This saved 18K in allyesconfig's kernel size.

	Regards
		Oliver

Signed-off-by: Oliver Neukum <oliver@neukum.name>

--- a/include/linux/slab.h	2006-03-11 23:12:55.000000000 +0100
+++ b/include/linux/slab.h	2006-03-20 09:00:41.000000000 +0100
@@ -118,7 +118,7 @@
  */
 static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
 {
-	if (n != 0 && size > INT_MAX / n)
+	if (unlikely(n > INT_MAX / size ))
 		return NULL;
 	return kzalloc(n * size, flags);
 }

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

end of thread, other threads:[~2006-03-22  5:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-20 14:45 [PATCH]micro optimization of kcalloc Oliver Neukum
2006-03-20 15:14 ` Benjamin LaHaise
2006-03-20 15:33   ` Oliver Neukum
2006-03-20 15:32     ` Benjamin LaHaise
2006-03-20 16:15   ` Pekka Enberg
2006-03-20 18:44     ` David Lang
2006-03-22  5:40       ` Valdis.Kletnieks
2006-03-20 15:37 ` Pekka Enberg
2006-03-20 15:51 ` Pekka Enberg
  -- strict thread matches above, loose matches on Subject: below --
2006-03-20 13:08 Oliver Neukum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.