Re: [PATCH] slab: deal with NULL pointers passed to kmem_cache_free

From: JÃrn Engel
Date: Mon Mar 19 2007 - 18:09:33 EST


On Mon, 19 March 2007 14:10:38 -0700, Andrew Morton wrote:
>
> Would prefer to do:
>
> static inline void kmem_cache_free_if_not_null(struct kmem_cache *cachep,
> void *objp)
> {
> if (objp)
> kmem_cache_free(cachep, objp);
> }
>
> so that we don't add extra overhead to all the thousands of existing,
> well-behaved callsites.

In principle, this would work. But two things need changing, imho:
1. Don't inline the function. kmem_cache_free() has only about 34 NULL
callers, if my grep is reliable, so this case is arguable. But in
general, out-of-line functions are better than many extra
conditionals pulled in through the inline one.
2. Switch the names. According to Rusty's benchmark, the easiest way to
use and interface should be the correct one. Every new driver
written by a rookie will call kmem_cache_free(), simply because the
name seems simpler.

void kmem_cache_free_fast(struct kmem_cache *cachep, void *objp)
{
/* old kmem_cache_free() */
}

void kmem_cache_free(struct kmem_cache *cachep, void *objp)
{
if (likely(objp))
kmem_cache_free_fast(cachep, objp);
}

JÃrn

--
Correctness comes second.
Features come third.
Performance comes last.
Maintainability is easily forgotten.
-
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/