Re: [PATCH TRIVIAL] mm: Fix build warning in kmem_cache_create()

From: David Rientjes
Date: Mon Jul 16 2012 - 15:58:13 EST


On Mon, 16 Jul 2012, Christoph Lameter wrote:

> > > struct kmem_cache *kmem_cache_create(const char *name, size_t size,
> > > size_t align,
> > > unsigned long flags, void (*ctor)(void *))
> > > {
> > > struct kmem_cache *s = NULL;
> > >
> > > #ifdef CONFIG_DEBUG_VM
> > > if (!name || in_interrupt() || size < sizeof(void *) ||
> > > size > KMALLOC_MAX_SIZE) {
> > > printk(KERN_ERR "kmem_cache_create(%s) integrity check"
> > > " failed\n", name);
> > > goto out;
> > > }
> > > #endif
> > >
> >
> > Agreed, this shouldn't depend on CONFIG_DEBUG_VM.
>
> These checks are useless for regular kernel operations. They are
> only useful when developing code and should only be enabled during
> development. There is no point in testing the size and the name which are
> typically constant when a slab is created with a stable kernel.
>

Sounds like a response from someone who is very familiar with slab
allocators. The reality, though, is that very few people are going to be
doing development with CONFIG_DEBUG_VM enabled unless they notice problems
beforehand.

Are you seriously trying to optimize kmem_cache_create()? These checks
certainly aren't going to hurt your perfromance and it seems appropriate
to do some sanity checking before blowing up in unexpected ways. It's
also the way it's been done for years before extracting common allocator
functions to their own file.
--
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/