Mehul
Mehul

Reputation: 53

kmalloc fails eventhough lowfree is around 523MB

I am currently working on one embedded development board.
I have ported 3.0.31 kernel with my personal patches on it.

When I am trying to insert my module, it fails to allocate 4MB memory using kmalloc().

Below is output of $ cat /proc/meminfo command executed on development board.

MemTotal:         899252 kB  
MemFree:          524136 kB  
Buffers:            3540 kB  
Cached:            20124 kB  
SwapCached:            0 kB  
Active:            37308 kB  
Inactive:          21008 kB  
Active(anon):      34852 kB  
Inactive(anon):      160 kB  
Active(file):       2456 kB  
Inactive(file):    20848 kB  
Unevictable:           0 kB  
Mlocked:               0 kB  
HighTotal:         31744 kB  
HighFree:            308 kB  
LowTotal:         867508 kB  
LowFree:          523828 kB  <--------
SwapTotal:             0 kB  
SwapFree:              0 kB  
Dirty:                 0 kB  
Writeback:             0 kB  
AnonPages:         33232 kB  
Mapped:             6336 kB  
Shmem:               360 kB  
Slab:              64652 kB  
SReclaimable:       2972 kB  
SUnreclaim:        61680 kB  
KernelStack:        1528 kB  
PageTables:         1884 kB  
NFS_Unstable:          0 kB  
Bounce:                0 kB  
WritebackTmp:          0 kB  
CommitLimit:      449624 kB  
Committed_AS:     532552 kB  
VmallocTotal:     122880 kB  
VmallocUsed:       38440 kB  
VmallocChunk:      70436 kB

According to my understanding, LowFree parameter indicates free memory in kernel space which is around 523MB in this case.

There is a lot free space available in kernel space then why module fails in kmalloc of 4MB?

Upvotes: 2

Views: 2434

Answers (1)

Santosh A
Santosh A

Reputation: 5351

The kmalloc() function returns physically contiguous memory which also is virtually contiguous.

Allocating physically contiguous memory has one downside: Due to fragmention it is often hard to find physically contiguous blocks of memory, especially for large allocations.

Allocating memory that is only virtually contiguous has a much larger chance of success. If you do not need physically contiguous memory, use vmalloc()

Take a look at this examples, where kmalloc fail's at ~4MB. Kmalloc fails ~4MB

For more details refer : KMALLOC size allocation

Upvotes: 4

Related Questions