Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760981Ab2BNUpY (ORCPT ); Tue, 14 Feb 2012 15:45:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:41658 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757250Ab2BNUpU (ORCPT ); Tue, 14 Feb 2012 15:45:20 -0500 Date: Tue, 14 Feb 2012 12:45:18 -0800 From: Andrew Morton To: Christoph Lameter Cc: Xi Wang , Dan Carpenter , Jesper Juhl , Jens Axboe , Pekka Enberg , linux-kernel@vger.kernel.org, Matt Mackall , David Rientjes Subject: Re: Uninline kcalloc Message-Id: <20120214124518.f42bc03e.akpm@linux-foundation.org> In-Reply-To: References: <4F33C7D7.1060801@kernel.dk> <32FA0BD0-7C0D-4ED4-B375-4736FC70AC05@gmail.com> <4F33CEAE.60400@gmail.com> <20120209150652.5b1d19dc.akpm@linux-foundation.org> <20120213194446.GD26353@mwanda> <20120214072017.GF26353@mwanda> <8F83835C-366C-46AC-A50A-3F680B7D2D83@gmail.com> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2740 Lines: 78 On Tue, 14 Feb 2012 13:33:40 -0600 (CST) Christoph Lameter wrote: > Subject: Uninline kcalloc > > kcalloc is not used in performance critical ways. So it does not need to > be inline. If we would add diagnostics to track the overflow occurrences > then such code would be replicated at all call sites in the kernel. Uninlining kcalloc() seems reasonable. But if we're going to uninline kcalloc() then we also should uninline kmalloc_array(). And yes, it's still called kmalloc_array() in my tree. I've been following this discussion for N days waiting for a reason for changing the original patch and I ain't seen one yet. From: Xi Wang Subject: slab: introduce kmalloc_array() Introduce a kmalloc_array() wrapper that performs integer overflow checking without zeroing the memory. Suggested-by: Andrew Morton Suggested-by: Jens Axboe Signed-off-by: Xi Wang Cc: Pekka Enberg Cc: Dan Carpenter Signed-off-by: Andrew Morton --- include/linux/slab.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff -puN include/linux/slab.h~slab-introduce-kmalloc_array include/linux/slab.h --- a/include/linux/slab.h~slab-introduce-kmalloc_array +++ a/include/linux/slab.h @@ -190,7 +190,7 @@ size_t ksize(const void *); #endif /** - * kcalloc - allocate memory for an array. The memory is set to zero. + * kmalloc_array - allocate memory for an array. * @n: number of elements. * @size: element size. * @flags: the type of memory to allocate. @@ -240,11 +240,22 @@ size_t ksize(const void *); * for general use, and so are not documented here. For a full list of * potential flags, always refer to linux/gfp.h. */ -static inline void *kcalloc(size_t n, size_t size, gfp_t flags) +static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) { if (size != 0 && n > ULONG_MAX / size) return NULL; - return __kmalloc(n * size, flags | __GFP_ZERO); + return __kmalloc(n * size, flags); +} + +/** + * kcalloc - allocate memory for an array. The memory is set to zero. + * @n: number of elements. + * @size: element size. + * @flags: the type of memory to allocate (see kmalloc). + */ +static inline void *kcalloc(size_t n, size_t size, gfp_t flags) +{ + return kmalloc_array(n, size, flags | __GFP_ZERO); } #if !defined(CONFIG_NUMA) && !defined(CONFIG_SLOB) _ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/