htop
并top
显示比机器上存在的物理内存更多的常驻内存消耗:
htop 输出:
最高输出:
免费输出:
这怎么可能?
编辑1:
pmap 输出:https ://gist.github.com/ixaxaar/1571308666360f65dc66
htop
并top
显示比机器上存在的物理内存更多的常驻内存消耗:
htop 输出:
最高输出:
免费输出:
这怎么可能?
编辑1:
pmap 输出:https ://gist.github.com/ixaxaar/1571308666360f65dc66
一个快速的实验表明,在一个分叉之后,RES 将计算来自父子节点的内存,即使在实践中每个页面都将被共享,直到一个进程修改它或死亡。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main ()
{
/* 100 MiB */
size_t size = 100 * 1024 * 1024;
char *ptr = malloc (size);
memset (ptr, 1, size);
int pid = fork ();
if (pid == 0)
{
puts ("Child");
}
else
{
puts ("Parent");
}
sleep (60);
puts ("Bye");
return 0;
}
如果我运行它然后查看 htop,我看到两个进程驻留“100M”。