what is the difference between kmalloc and vmalloc?

Vivek Dasgupta vivek.a.dasgupta at gmail.com
Thu Nov 22 01:23:43 EST 2012


kmalloc allocates physically contiguous memory, while vmalloc
allocates memory which is only virtually contiguous and not
necessarily physically contiguous.

Usually physically contiguous memory is required for hardware devices
(dma etc) , thus kmalloc is useful for allocating such memory. And
though this is not always the requirement, still kmalloc is preferred
, because it is better in terms of performance, because vmalloc can
result in greater TLB thrashing .

vmalloc is useful when very large amounts of memory is to be
allocated, because when memory becomes heavily fragmented, you may not
get success while allocating large memory via kmalloc.

Slab layer serves like a cache for commonly used data structures,
again with a view to reduce fragmentation, and to speed up operations.
To allocate objects from slab you will have to use functions like
kmem_cache_create() and kmem_cache_alloc() ..

thanks
Vivek

On Thu, Nov 22, 2012 at 8:42 AM, horse_rivers <horse_rivers at 126.com> wrote:
>
> thanks!
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



More information about the Kernelnewbies mailing list