All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: faster kmalloc_array(), kcalloc()
@ 2016-06-27 21:34 Alexey Dobriyan
  0 siblings, 0 replies; only message in thread
From: Alexey Dobriyan @ 2016-06-27 21:34 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

When both arguments to kmalloc_array() or kcalloc() are known at
compile time then their product is known at compile time
but search for kmalloc cache happens at runtime not at compile time.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/linux/slab.h |    2 ++
 1 file changed, 2 insertions(+)

--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -565,6 +565,8 @@ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
 {
 	if (size != 0 && n > SIZE_MAX / size)
 		return NULL;
+	if (__builtin_constant_p(n) && __builtin_constant_p(size))
+		return kmalloc(n * size, flags);
 	return __kmalloc(n * size, flags);
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-27 21:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-27 21:34 [PATCH] mm: faster kmalloc_array(), kcalloc() Alexey Dobriyan

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.