tdao
tdao

Reputation: 17678

Can /proc/meminfo indicate some hints on memory leak?

Is it a good idea to periodically cat /proc/meminfo for a hint if there exists a memory leak in the system.

If so, which metric should I focus on, given that the suspect memory leak is in a kernel module:

> cat /proc/meminfo

MemTotal:     16344972 kB
MemFree:      13634064 kB
MemAvailable: 14836172 kB
Buffers:          3656 kB
Cached:        1195708 kB
SwapCached:          0 kB
Active:         891636 kB
Inactive:      1077224 kB
HighTotal:    15597528 kB
HighFree:     13629632 kB
LowTotal:       747444 kB
LowFree:          4432 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:             968 kB
Writeback:           0 kB
AnonPages:      861800 kB
Mapped:         280372 kB
Shmem:             644 kB
Slab:           284364 kB
SReclaimable:   159856 kB
SUnreclaim:     124508 kB
PageTables:      24448 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
WritebackTmp:        0 kB
CommitLimit:   7669796 kB
Committed_AS:   100056 kB
VmallocTotal:   112216 kB
VmallocUsed:       428 kB
VmallocChunk:   111088 kB
AnonHugePages:   49152 kB

Upvotes: 1

Views: 3185

Answers (1)

osgx
osgx

Reputation: 94345

Better way to start is free command-line tool, which uses the same file /proc/meminfo: http://man7.org/linux/man-pages/man1/free.1.html

free - Display amount of free and used memory in the system. free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo

free tool has "used" and "free" memory columns with two values each, but the truth is that in Linux (and Unix, and probably in Windows too) there is Page cache mechanism of caching data from HDD in RAM.

Actually, this is just a cache and when your application asks and use more memory, page cache will be partially discarded (if the cached data was not modified), or flushed to HDD (if data was modified) and OS will give memory to your application.

In Linux, memory, used by page cache is reported as not free, but in "buffers" / "cache" columns, and is accounted in first row of "used"

   buffers
          Memory used by kernel buffers (Buffers in /proc/meminfo)

   cache  Memory used by the page cache and slabs (Cached and
          SReclaimable in /proc/meminfo)

Example of free output:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          1504       1491         13          0         91        764
-/+ buffers/cache:        635        869
Swap:         2047          6       2041

First row of "free" column is free RAM, not used by anything. Second row (second value) is free RAM + cached+buffers.

You can read more at

Upvotes: 4

Related Questions