Linux total available memory

atomicbaum picture atomicbaum · Dec 1, 2011 · Viewed 13.9k times · Source

I'm trying to figure out a good formula for finding out how much memory is available. I'm using the following formula currently: freeMem = MemFree + Buffers + Cached - Shmem. However, according to this formula my embedded system is losing memory. Now I'm wondering if I have a memory leak so I enabled kmemleak in the kernel. According to mpatrol, valgrind, and coverity I do not have any leaks in user space. Is there a leak in kernel space or is my formula off? Note that I do not have any swap for this device.

MYBOX> cat /proc/meminfo
MemTotal:        2073348 kB
MemFree:         1388180 kB
Buffers:          137016 kB
Cached:            88772 kB
SwapCached:            0 kB
Active:           589124 kB
Inactive:          44380 kB
Active(anon):     410236 kB
Inactive(anon):     1992 kB
Active(file):     178888 kB
Inactive(file):    42388 kB
Unevictable:           0 kB
Mlocked:               0 kB
HighTotal:       1310716 kB
HighFree:         811828 kB
LowTotal:         762632 kB
LowFree:          576352 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                64 kB
Writeback:             0 kB
AnonPages:        407712 kB
Mapped:            26140 kB
Shmem:              4516 kB
Slab:              40408 kB
SReclaimable:       8320 kB
SUnreclaim:        32088 kB
KernelStack:        1480 kB
PageTables:         1464 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1036672 kB
Committed_AS:     660508 kB
VmallocTotal:     237344 kB
VmallocUsed:      104556 kB
VmallocChunk:     126296 kB

Answer

Quentin Casasnovas picture Quentin Casasnovas · Dec 1, 2011

Leaking memory from userland would not show anyway in /proc/meminfo because as far as the kernel is concerned it is memory allocated (no matter if you use free() in your userland app or not, it's either allocated with the mmap() syscall or brk()/sbrk() and the kernel keeps track of the pages allocated in userland, otherwise we would be in serious trouble ;).

I don't clearly understand how you came up with your belief that your are leaking memory? Here is a good link redhat/meminfo if you haven't read it already which explains what each statistic really means.