2

Possible Duplicate:
What is the difference between vmalloc and kmalloc?

Please tell in detail explanation

Community
  • 1
  • 1
Muthuraman
  • 143
  • 2
  • 9
  • cody Gray, before posting this question i not look on that this iste? – Muthuraman Dec 04 '10 at 10:20
  • 1
    With regards to your last comment, are you saying that you posted this question before searching this site, or are you asking a question? If there's something the question that I linked to leaves unanswered for you, please edit your question. Otherwise, I expect this will get closed as a duplicate pretty quickly. – Cody Gray - on strike Dec 04 '10 at 11:01
  • @Cody Gray: i need in detail memory allocation comparison.... – Muthuraman Dec 08 '10 at 11:37
  • Can you explain what's still unclear about the two answers that have been posted, or the answers in the other similar question? "In detail memory allocation comparison" doesn't really tell me anything useful. – Cody Gray - on strike Dec 08 '10 at 11:39
  • @Cody Gray: How memory allocation performed by using kmalloc and vmalloc? – Muthuraman Dec 09 '10 at 05:40

2 Answers2

3

kmalloc allocates physically contiguous memory, memory which pages are laid consecutively in physical RAM. vmalloc allocates memory which is contiguous in kernel virtual memory space (that means pages allocated that way are not contiguous in RAM, but the kernel sees them as one block).

kmalloc is the preffered way, as long as you don't need very big areas. The trouble is, if you want to do DMA from/to some hardware device, you'll need to use kmalloc, and you'll probably need bigger chunk. The solution is to allocate memory as soon as possible, before memory gets fragmented.

If you only allocate small chunks (page or few pages), just use kmalloc and don't worry about details. :)

Above answer has been copied from source - http://kerneltrap.org/node/4020

Sachin Shanbhag
  • 54,530
  • 11
  • 89
  • 103
1

kmalloc returns physically contiguous memory, kmalloc memory is reserved and locked, it cannot be swapped, Memory is subject to fragmentation, If you don't need contiguous mapping in kernel space, you can use vmalloc to avoid the fragmentation problem.

Sankar Ganesh PMP
  • 11,927
  • 11
  • 57
  • 90