Linux VmRSS 和常驻集大小如何匹配?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10400751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do VmRSS and resident set size match?
提问by lupz
I parse data from /proc/[pid]/statm
to get a clue about memory usage of a certain process. man proc
states that resident set size(measured in 'pages') is the same as VmRSS (KB??) in /proc/[pid]/status
. Since they have different values, I would like to understand the connection between these Values. Is there something like a factor I can read somewhere in /proc
(I thought of VmPTE but its sth. else...)? Which one of both should I parse to get the size of the used Memory for a certain process?
我解析数据/proc/[pid]/statm
以获取有关某个进程的内存使用情况的线索。man proc
指出常驻集大小(以“页面”为单位)与/proc/[pid]/status
. 由于它们具有不同的价值观,我想了解这些价值观之间的联系。是否有类似的因素我可以在某处读取/proc
(我想到了 VmPTE 但它……其他……)?我应该解析两者中的哪一个来获取某个进程使用的内存的大小?
#ex 1782 = firefox
~$ cat /proc/1782/statm
224621 46703 9317 11 0 98637 0
# \--- resident set size
~$ cat /proc/1782/status | grep Vm
VmPeak: 935584 kB
VmSize: 898484 kB
VmLck: 0 kB
VmHWM: 257608 kB
VmRSS: 186812 kB
VmData: 394328 kB
VmStk: 220 kB
VmExe: 44 kB
VmLib: 61544 kB
VmPTE: 1224 kB
VmSwap: 0 kB
采纳答案by Ray
My understanding is that VM is the amount of virtual memory and RSS is how much of it is resident in memory. So,
我的理解是 VM 是虚拟内存的数量,RSS 是它驻留在内存中的数量。所以,
virtual memory = part in physical memory + part on disk
虚拟内存 = 物理内存的一部分 + 磁盘的一部分
The part in physical memory is RSS. So, VSS should be greater than RSS. If they are close to equal, that means your process is sitting comfortably in memory. If VSS is much larger, that means there isn't enough memory and parts of it have to be swapped out to disk (i.e., because of a competing process, etc.).
物理内存中的部分是RSS。所以,VSS应该大于RSS。如果它们接近相等,则意味着您的进程在内存中处于舒适状态。如果 VSS 大得多,这意味着没有足够的内存,它的一部分必须换出到磁盘(即,由于竞争进程等)。
On my system, I can do a "man proc" and it lists the following:
在我的系统上,我可以执行“man proc”并列出以下内容:
* VmPeak: Peak virtual memory size.
* VmSize: Virtual memory size.
* VmLck: Locked memory size (see mlock(3)).
* VmHWM: Peak resident set size ("high water mark").
* VmRSS: Resident set size.
* VmData, VmStk, VmExe: Size of data, stack, and text segments.
If you want to report the peak memory usage, then you probably want virtual memory, which looks like VmPeak.
如果您想报告峰值内存使用情况,那么您可能需要虚拟内存,它看起来像 VmPeak。
Hope this helps!
希望这可以帮助!
回答by Takashi Oguma
The RSS value of /proc/<pid>/stat
is number of pages, whereas the VmRSS value of /proc/<pid>/status
is in kB.
的 RSS 值为/proc/<pid>/stat
页数,而 的 VmRSS 值/proc/<pid>/status
以 kB 为单位。
In your case, 46703 * 4kB (page size) = 186812 kB.
在您的情况下,46703 * 4kB(页面大小)= 186812 kB。
回答by Dr. Xperience
Man page for proc
states following in statm
context
proc
在statm
上下文中遵循状态的手册页
/proc/[pid]/statm
Provides information about memory usage, measured in pages. The columns are:
size (1) total program size
(same as VmSize in /proc/[pid]/status)
resident (2) resident set size
(same as VmRSS in /proc/[pid]/status)
share (3) shared pages (i.e., backed by a file)
text (4) text (code)
lib (5) library (unused in Linux 2.6)
data (6) data + stack
dt (7) dirty pages (unused in Linux 2.6)
But what it fails to state is that size
and resident
are expressed in number of pages.
但它没有说明的是,size
并resident
以页数表示。
~$ cat /proc/1782/statm
224621 46703 9317 11 0 98637 0
# \--- resident set size
Thus, 46703
is resident set size expressed in number of pages and 224621
is Virtual Memory Size expressed in number of pages as well.
因此,46703
常驻集大小以页数 224621
表示,虚拟内存大小也以页数表示。
Now to get them in KB multiply them with Page Size. You can get Page Size with getconf PAGESIZE
command or in C/C++
program by calling sysconf(_SC_PAGE_SIZE)
(defined in unistd.h). This will give you page size in bytes. Divide it with 1024 to get page size in KB.
现在要以 KB 为单位将它们与页面大小相乘。您可以通过getconf PAGESIZE
命令或在C/C++
程序中调用sysconf(_SC_PAGE_SIZE)
(在 unistd.h 中定义)获取页面大小。这将为您提供以字节为单位的页面大小。将其除以 1024 以获得以 KB 为单位的页面大小。
Example :
例子 :
$getconf PAGESIZE
4096
4096/1024 = 4 KB
4096/1024 = 4 KB
Thus, resident set size in KB is 46703 x 4 = 186812 kB (VmRSS).
Total Program size in KB is 224621 x 4 = 898484 kB (VmSize)
因此,以 KB 为单位的常驻集大小为 46703 x 4 = 186812 kB (VmRSS)。
以 KB 为单位的总程序大小为 224621 x 4 = 898484 kB (VmSize)