Re: Make kzalloc a macro

From: Denis Vlasenko
Date: Sat Sep 24 2005 - 05:56:54 EST


On Friday 23 September 2005 18:58, Christoph Lameter wrote:
> How about this patch making kzalloc a macro?
>
> ---
>
> Make kzalloc a macro and use __GFP_ZERO for zeroed slab allocations
>
> kzalloc is right now a function call. The optimization that the kmalloc macro
> provides does not work for kzalloc invocations. kmalloc also determines the
> slab to use at compile time and fails the compilation if the size is too big.
> kzalloc cannot do not.
>
>
> -extern void *kzalloc(size_t, unsigned int __nocast);
> +#define kzalloc(__size, __flags) kmalloc(__size, (__flags) | __GFP_ZERO)

Why macro and not an inline function?

> +static inline void *obj_checkout(kmem_cache_t *cachep, unsigned int __nocast flags, void *objp)
> +{
> + if (likely(objp)) {
> + objp = cache_alloc_debugcheck_after(cachep, flags, objp,
> + __builtin_return_address(0));
> + if (unlikely(flags & __GFP_ZERO))

Why unlikely?

> + memset(objp, 0, obj_reallen(cachep));
> + else
> + prefetchw(objp);
> + }
> + return objp;
> +}
--
vda
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/