Re: about kmalloc and kmem_cache_alloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 4, 2010 at 8:03 PM, kernel.niko <kernel.niko@xxxxxxxxx> wrote:
> hi,everyone,
> I'm wandering how to use kmalloc and kmem_cache_alloc.
> as i know,kmalloc is based on kmem_cache_alloc ,so what's the different?

kmalloc should be used when you want to allocate byte sized memory as
opposed to allocating memory in units of pages, in which case you
should use alloc_pages(..).

kmem_cache_alloc is a part of the slab cache interface. This is used
for reusing objects in the kernel. Lets take mm_struct objects as an
example. On a live system, processes come & go. Every process needs a
mm_struct object. And when a process dies, you can throw away the
object. Instead of creating & throwing away objects, slab cache
maintains a cache of objects. When you free an object, instead of
deallocating it, you give it back to the cache. Next time, if  you
want to create a new object, slab cache gives you one object from the
slab cache. kmem_cache_alloc is one of the interface functions to use
the slab cache in the kernel. You might want to read about slab caches
in detail if you need more information.

Venkatram Tummala
> when to use kmalloc? and
> in what occasion,kmem_cache_alloc should be used?
> thanks.
>
> 2010-11-05
> ________________________________
> kernel.niko

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux