mm: faster kmalloc_array(), kcalloc()
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. Link: http://lkml.kernel.org/r/20160627213454.GA2440@p183.telecom.by Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
72baeef0c2
commit
91c6a05f72
@@ -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)
|
if (size != 0 && n > SIZE_MAX / size)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (__builtin_constant_p(n) && __builtin_constant_p(size))
|
||||||
|
return kmalloc(n * size, flags);
|
||||||
return __kmalloc(n * size, flags);
|
return __kmalloc(n * size, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user