kmem_cache_zalloc
Quoted 3 lines · In article <[email protected]> Christoph Hellwig…
I'd really go for k(mem_)zalloc, but a
kmem_cache_allocleads people toward writing bad code. The purpose of the slab allocator is to allow caching readily constructed objects, a_zallocdestroys them on alloc.
I thought that the life span of an object is between kmem_cache_alloc and kmem_cache_free. If you are expecting caching beyond this, you may not get correct data. kmem_cache allocator is supposed to quickly allocate fixed size structures avoiding the need for frequent splitting and coalescing in the allocator.
Am I missing something here ?
Thanks
Signature · 2 lines
Dipankar Sarma <[email protected]> http://lse.sourceforge.net Linux Technology Center, IBM Software Lab, Bangalore, India.
Quoted 7 lines · [email protected] said:
I thought that the life span of an object is between
kmem_cache_allocandkmem_cache_free. If you are expecting caching beyond this, you may not get correct data.kmem_cacheallocator is supposed to quickly allocate fixed size structures avoiding the need for frequent splitting and coalescing in the allocator.Am I missing something here ?
Yes. Slab objects can be initialised once when a new page is added to the slab, and returned to the slab in reusable form so that you don't have the cost of complete initialisation on each allocation.
So if for example you have a semaphore in your slab object, instead of initialising it on each kmem_cache_alloc() you do it once when the new pages are added to the slab. Then you just make sure it's unlocked each time you free a slab object.
--
dwmw2
Quoted 11 lines · David Woodhouse
Quoted 7 lines · [email protected] said:
I thought that the life span of an object is between
kmem_cache_allocandkmem_cache_free. If you are expecting caching beyond this, you may not get correct data.kmem_cacheallocator is supposed to quickly allocate fixed size structures avoiding the need for frequent splitting and coalescing in the allocator.Am I missing something here ?
Quoted 8 lines
Yes. Slab objects can be initialised once when a new page is added to the slab, and returned to the slab in reusable form so that you don't have the cost of complete initialisation on each allocation.
So if for example you have a semaphore in your slab object, instead of initialising it on each
kmem_cache_alloc()you do it once when the new pages are added to the slab. Then you just make sure it's unlocked each time you free a slab object.
Ok. That makes clear why hch thought kmem_cache_alloc() can lead to people writing bad code.
Thanks
Signature · 2 lines
Dipankar Sarma <[email protected]> http://lse.sourceforge.net Linux Technology Center, IBM Software Lab, Bangalore, India.