login
Header Space

 
 

kmalloc() vs vmalloc()

October 17, 2004 - 2:13pm
Submitted by vertigo on October 17, 2004 - 2:13pm.
Linux

Hello
What's the difference between kmalloc and vmalloc ?

Thanx
Michal

kmalloc vs vmalloc

October 17, 2004 - 3:03pm

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. :)

kmalloc vs vmalloc

January 17, 2006 - 3:54pm
AnandV (not verified)

Hi All,
When we want a big chunk (8Kb) of memory does Kmalloc allocates Physically conguious memory or it will be discrete

Regards
Anand

kmalloc always allocates cont

January 18, 2006 - 4:13am

kmalloc always allocates contiguous chunks.

Regards,
Narendra Kiran Chinnam.

8Kb not a big chunk! That th

January 19, 2006 - 7:22am
Anonymous (not verified)

8Kb not a big chunk!
That the kmalloc can malloc max chunk is 128K !

Wouldn't anything above 4k be

January 19, 2006 - 7:48am
Anonymous (not verified)

Wouldn't anything above 4k be a 'big' chunk in that it's more than a single page, which means a set of neighbouring pages must be found?

Finding two consequent pages

January 19, 2006 - 12:01pm

Finding two consequent pages (8k) is not a big problem unless the memory is almost extinct/too fragmented.

Regards,
Narendra Kiran Chinnam.

Most hardware is able to do s

January 19, 2006 - 2:51pm

Most hardware is able to do scatter-gather with DMA, so big contiguous areas aren't needed often.

What to do if we want to

August 27, 2007 - 3:12am
Neha (not verified)

What to do if we want to allocate chunks of more than 128k?????????????

use buddy allocator.

August 27, 2007 - 10:19pm
jungseung (not verified)

u can make new-size slab with slab allocator
or use buddy allocator directly.

contiguous issues

August 28, 2007 - 3:49am
Anonymous (not verified)

hmmm..does this mean that if you allocate size less than the maximum for kmalloc(128kb) using vmalloc, would it still be contiguous in physical memory?

Maybe, but it is not

April 7, 2008 - 2:20am
Anonymous (not verified)

Maybe, but it is not guaranteed to. Always assume vmalloc returns physically-discontiguous memory regions.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary