From: Alexey Dobriyan <adobriyan@xxxxxxxxx> Subject: 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@xxxxxxxxxxxxxxx Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Pekka Enberg <penberg@xxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/slab.h | 2 ++ 1 file changed, 2 insertions(+) diff -puN include/linux/slab.h~mm-faster-kmalloc_array-kcalloc include/linux/slab.h --- a/include/linux/slab.h~mm-faster-kmalloc_array-kcalloc +++ a/include/linux/slab.h @@ -565,6 +565,8 @@ static inline void *kmalloc_array(size_t { 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); } _ -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html