kmalloc() vs vmalloc()

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

Hello
What's the difference between kmalloc and vmalloc ?

Thanx
Michal

kmalloc vs vmalloc

on
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

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

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

on
January 18, 2006 - 4:13am

kmalloc always allocates contiguous chunks.

Regards,
Narendra Kiran Chinnam.

8Kb not a big chunk! That th

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

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

Wouldn't anything above 4k be

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

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

on
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

on
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

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

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

use buddy allocator.

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

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

contiguous issues

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

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

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

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.