All of
 help / color / mirror / Atom feed
From: Alexey Dobriyan <>
Subject: [PATCH] mm: faster kmalloc_array(), kcalloc()
Date: Tue, 28 Jun 2016 00:34:55 +0300	[thread overview]
Message-ID: <> (raw)

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 <>

 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);

                 reply	other threads:[~2016-06-27 21:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \
    --subject='Re: [PATCH] mm: faster kmalloc_array(), kcalloc()' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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.