Linux-kernel mailing list archive 2000-32,: Re: When to use kmem_cache_alloc()?

# Re: When to use kmem_cache_alloc()?

Andi Kleen (ak@suse.de)
Mon, 7 Aug 2000 17:20:28 +0200

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Oscar Roozen: "/dev/random blocks forever on 2.2.12 and 2.2.16"
- Previous message: Mark Hemment: "Re: [PATCH] signal_struct slab cache"
- In reply to: Erik Mouw: "When to use kmem_cache_alloc()?"

On Mon, Aug 07, 2000 at 02:59:24PM +0000, Erik Mouw wrote:
> Hi,
>
> Is there a general guideline that says when kmem_cache_alloc() is
> preferred over kmalloc()?

kmem_cache_alloc makes sense when you allocate multiple objects with the
same size. It currently always uses an own page so you probably should have
more than ~2K bytes of objects at least to avoid wasting memory. It also
makes sense when your object sizes fit poorly into the power-of-2 kmalloc
sizes or when you need very fast allocation. In case your objects require
initialization it may also make sense to use the slab constructor/deconstructor
feature in this case.

kmem_cache_alloc creates less fragmentation than kmalloc because objects with
similar livetime are clustered together.

Hope this helps,

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

- Next message: Oscar Roozen: "/dev/random blocks forever on 2.2.12 and 2.2.16"
- Previous message: Mark Hemment: "Re: [PATCH] signal_struct slab cache"
- In reply to: Erik Mouw: "When to use kmem_cache_alloc()?"