最大居民集大小没有意义 [英] Maximum resident set size does not make sense
问题描述
我正在尝试测量Linux中正在运行的程序的内存消耗.我编写了一个C程序来分配1G内存,然后用时间输出其最大驻留集大小":
I am trying to measure memory consumption of a running program in Linux. I wrote a C program to allocate 1G memory, then use time to output its "Maximum resident set size":
/usr/bin/time -f '%Uu %Ss %er %MkB %x %C' ./takeMem 1000000000
0.85u 0.81s 1.68r **3910016kB** 0 ./takeMem 1000000000
从man time
,我应该解释为该程序的最大驻留集大小"占用3.9G内存,尽管该程序仅分配了1G内存.这没有道理.
From man time
, I should interpret that "Maximum resident set size" for such program take 3.9G memory although the program allocated only 1G memory. It does NOT make sense.
有人知道是什么原因导致最大居民集大小"这么高吗?
Can anybody known what happened to cause "Maximum resident set size" that high?
C代码非常简单:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int memLength = atoi(argv[1]);
fprintf(stderr, "Allocating %d memory...", memLength);
unsigned char* p = new unsigned char[memLength];
fprintf(stderr, "Done\n");
while (true) {
int i = rand() % memLength;
char v = rand() % 256;
p[i] = v;
}
return 0;
}
推荐答案
前一段时间,我偶然发现了这个问题.这是GNU时代的一个错误,值太大了4倍,因为它假定页面大小并将其转换为kB,即使它最初已经是kB. 您可能要检查:
I stumbled across this a while ago. It's a bug in GNU time, values are 4 times too large, as it assumes a size in pages and converts it into kB, even though it is kB already in the first place. You might wanna check:
http://forums.whirlpool.net.au/archive/1693957
这篇关于最大居民集大小没有意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!