VIRT:Virtual memory used by the task, it includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used. 进程的虚拟内存使用,包括该进程的代码,数据段,共享lib 以及 swap 出磁盘的内存。一般情况下,不用特别关注该指标,VIRT并不意味着物理内存。(64-bit的操作系统,虚拟地址空间大小为128T,可近似认为"无限";32-bit的操作系统,虚拟空间大小为2G)
Buffer: 对磁盘数据的缓存,既可以用在写,也可以用在读。
Cache: 对文件数据的缓存,既可以用在写,也可以用在读。
2.2 Linux 内存分配
一般 Unix 系统中,用户态的程序通过malloc()调用申请内存。如果返回值是 NULL, 说明此时操作系统没有空闲内存。这种情况下,用户程序可以选择直接退出并打印异常信息或尝试进行 GC 回收内存。然而 Linux 系统总会先满足用户程序malloc请求,并分配一片虚拟内存地址。只有在程序第一次touch到这片内存时,操作系统才会分配物理内存给进程。具体我们可以看下如下demo:
1.调用 malloc,但不touch:
代码语言:javascript
复制
#include <stdio.h>
#include <stdlib.h>
int main (void) {
int n = 0;
while (1) {
if (malloc(1<<20) == NULL) {
printf("malloc failure after %d MiB\n", n);
return 0;
}
printf ("got %d MiB\n", ++n);
}
}
2. 调用 malloc,并touch:
代码语言:javascript
复制
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (void) {
int n = 0;
char *p;
while (1) {
if ((p = malloc(1<<20)) == NULL) {
printf("malloc failure after %d MiB\n", n);
return 0;
}
memset (p, 0, (1<<20));
printf ("got %d MiB\n", ++n);
}
}
Difference with Linux VmRSS and the total commited memory of Java NativeMemoryTraking (NMT):https://stackoverflow.com/questions/58430156/difference-with-linux-vmrss-and-the-total-commited-memory-of-java-nativememorytr
Memory Footprint of A Java Process: https://vimeo.com/364039638
Why does a JVM report more committed memory than the linux process resident set size?: https://stackoverflow.com/questions/31173374/why-does-a-jvm-report-more-committed-memory-than-the-linux-process-resident-set