Re: lib/idr.c: initialize struct idr_layer

From: Pekka Enberg
Date: Sun Jan 27 2008 - 16:36:05 EST


Hi Vegard,

On Jan 27, 2008 11:30 PM, Vegard Nossum <vegard.nossum@xxxxxxxxx> wrote:
> > Depends on how you track object initialization. An object returned by
> > kmem_cache_alloc() is always initialized if the cache it comes from has a
> > constructor.
>
> I think there's a pretty big chance I'm wrong (or misunderstanding
> something) here, so I'll just ask:
> setup_object() from mm/slub.c is what calls the ctor. Shouldn't this
> be called from slab_alloc() as well? (I'm marking the data
> "uninitialized" there before returning the object.) Otherwise you
> might get back an object that is initialized with the previous owner's
> data. Or is this intentional?

It's intentional. The caller of kmem_cache_free() is expected to put
the object in such a state that it can be recycled immediately when
kmem_cache_alloc() for that cache is called. You can find the design
rationale for that in Bonwick's original paper on slab:
http://citeseer.ist.psu.edu/bonwick94slab.html

Pekka
--
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/