开发者

how to determine the available physical memory in linux

I'm trying to figure if my software running on linux suffers from memory leak. I've tried to measure the available physical memory as found in /proc/meminfo (see below) but could understand which field(s) represents the available memory and what is the relation between MemFree, Cached, Buffers, Active, Inactive.

开发者_高级运维
cat /proc/meminfo
MemTotal:       124128 kB
MemFree:         62872 kB
Buffers:             0 kB
Cached:          15624 kB
SwapCached:          0 kB
Active:          38724 kB
Inactive:        11148 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:               0 kB
Writeback:           0 kB
AnonPages:       34272 kB
Mapped:          14640 kB
Slab:             5564 kB
SReclaimable:      424 kB
SUnreclaim:       5140 kB
PageTables:        504 kB
NFS_Unstable:        0 kB
Bounce:              0 kB
WritebackTmp:        0 kB
CommitLimit:     62064 kB
Committed_AS:    57936 kB
VmallocTotal:   655360 kB
VmallocUsed:      1016 kB
VmallocChunk:   654328 kB 


This is simpler command to check memory usage:

free


/proc/meminfo is for overall system memory information. /proc/[pid]/status has the memory usage info for an individual process. (it's also in /proc/[pid]/stat in a more machine parseable format).

In particular, VmData (size of data segment) and VmStk (size of stack segments) are most likely of use to you. Or just use ps or top instead of trying to read the data directly yourself.

The other numbers are likely to just be confusing, because the overall system memory usage is complicated by shared memory, various kinds of buffers, etc.


If you're looking for memory leaks, use Valgrind.

For a quick check of your application's memory use, use getrusage() (requires a recent linux kernel) and look at the ru_maxrss value. /proc/meminfo gives information about the system as a whole.


If you're looking to see if your software has a memory leak, look at either 'ps' or 'top' to look at your program. See if the virtual size (VSS) increases over time.

To debug such memory issues, use Valgrind or (my personal favorite) dmalloc.


Your question is asking something different, but since this is the #2 Google hit for “linux physical memory”—

Newer kernel versions running on x86 have DirectMap4k, DirectMap2M, and potentially DirectMap4M and DirectMap1G fields at the end of /proc/meminfo. Adding them up and multiplying by 1024 seems to give the number of bytes of physical RAM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜