kmalloc vs vmalloc vs malloc

本文转载至:http://embeddedude.blogspot.com/2014/03/kmalloc-vs-vmalloc-vs-malloc.html

malloc is used for user space memory allocation.
kmalloc and vmalloc are used for kernel space correspondingly.
vmalloc is just like malloc, which allocates a virtual continuous memory
kmalloc carrys 2 parameters, 2nd one is used for most of case without any specific request.

GFP_ATOMIC
The allocation is high-priority and does not sleep. This is the flag to use in interrupt handlers, bottom halves and other situations where you cannot sleep.
GFP_KERNEL This is a normal allocation and might block. This is the flag to use in process context code when it is safe to sleep.
Besides, it allocates physically contiguous memory   (also virtually contiguous) , which is DMAable by a subsystem.

side notes from  http://www.roman10.net/linux-kernel-programmingmemory-allocation/
Most of the memory allocations in Linux kernel are done using kmalloc, due to the following reasons:
  • On many architectures, hardware devices don’t understand virtual address. Therefore, their device drivers can only allocate memory using kmalloc.
  • kmalloc has better performance in most cases because physically contiguous memory region is more efficient than virtually contiguous memory. The reason behind this is not covered here, interested readers can search for Linux memory management articles.
But w hen a large chunk of memory is needed, vmalloc is used often as it doesn’t require physically contiguous memory and the kernel can satisfy the request with much less effort than using kmalloc.
http://www.win.tue.nl/~aeb/linux/lk/lk-9.html holds more analysis.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值