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
.
我试图弄清楚我在Linux上运行的软件是否存在内存泄漏问题。我已经尝试测量/ proc / meminfo中的可用物理内存(见下文),但可以理解哪个字段代表可用内存,以及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
5 个解决方案
#1
21
This is simpler command to check memory usage:
这是检查内存使用情况的简单命令:
free
#2
4
/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).
/ proc / meminfo用于整个系统内存信息。 / proc / [pid] / status具有单个进程的内存使用信息。 (它还在/ proc / [pid] / stat中以更多机器可解析的格式)。
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.
特别是,VmData(数据段的大小)和VmStk(堆栈段的大小)最有可能对您有用。或者只使用ps或top而不是直接尝试自己读取数据。
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.
其他数字可能只是令人困惑,因为共享内存,各种缓冲区等使整个系统内存使用变得复杂。
#3
3
If you're looking for memory leaks, use Valgrind.
如果您正在寻找内存泄漏,请使用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.
要快速检查应用程序的内存使用情况,请使用getrusage()(需要最近的Linux内核)并查看ru_maxrss值。 / proc / meminfo提供有关整个系统的信息。
#4
1
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.
如果您正在查看您的软件是否有内存泄漏,请查看“ps”或“top”来查看您的程序。查看虚拟大小(VSS)是否随时间增加。
To debug such memory issues, use Valgrind or (my personal favorite) dmalloc.
要调试此类内存问题,请使用Valgrind或(我个人最喜欢的)dmalloc。
#5
0
Your question is asking something different, but since this is the #2 Google hit for “linux physical memory”—
你的问题是问一些不同的东西,但是因为这是“linux物理内存”的第二次搜索 -
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.
在x86上运行的较新内核版本在/ proc / meminfo末尾有DirectMap4k,DirectMap2M和潜在的DirectMap4M和DirectMap1G字段。将它们相加并乘以1024似乎可以得出物理RAM的字节数。
#1
21
This is simpler command to check memory usage:
这是检查内存使用情况的简单命令:
free
#2
4
/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).
/ proc / meminfo用于整个系统内存信息。 / proc / [pid] / status具有单个进程的内存使用信息。 (它还在/ proc / [pid] / stat中以更多机器可解析的格式)。
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.
特别是,VmData(数据段的大小)和VmStk(堆栈段的大小)最有可能对您有用。或者只使用ps或top而不是直接尝试自己读取数据。
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.
其他数字可能只是令人困惑,因为共享内存,各种缓冲区等使整个系统内存使用变得复杂。
#3
3
If you're looking for memory leaks, use Valgrind.
如果您正在寻找内存泄漏,请使用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.
要快速检查应用程序的内存使用情况,请使用getrusage()(需要最近的Linux内核)并查看ru_maxrss值。 / proc / meminfo提供有关整个系统的信息。
#4
1
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.
如果您正在查看您的软件是否有内存泄漏,请查看“ps”或“top”来查看您的程序。查看虚拟大小(VSS)是否随时间增加。
To debug such memory issues, use Valgrind or (my personal favorite) dmalloc.
要调试此类内存问题,请使用Valgrind或(我个人最喜欢的)dmalloc。
#5
0
Your question is asking something different, but since this is the #2 Google hit for “linux physical memory”—
你的问题是问一些不同的东西,但是因为这是“linux物理内存”的第二次搜索 -
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.
在x86上运行的较新内核版本在/ proc / meminfo末尾有DirectMap4k,DirectMap2M和潜在的DirectMap4M和DirectMap1G字段。将它们相加并乘以1024似乎可以得出物理RAM的字节数。