Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum resident set size does not make sense

Tags:

linux

memory

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 

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?

The C code is quite simple:

#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; } 
like image 441
zhanxw Avatar asked Apr 05 '12 20:04

zhanxw


People also ask

What is maximum Resident Set Size?

"Maximum RSS" means the maximum of the RSS since the process's birth, i.e. the largest it has ever been. So this number tells you the largest amount of physical memory your process has ever been using at any one instant.

What does the Resident Set Size indicate?

This is a measure of how much memory a process is consuming in our physical RAM, to load all of its pages after its execution. This includes memory allocated from shared libraries, given they are still present in memory.

What is RSS and VMS in memory?

rss is the Resident Set Size, which is the actual physical memory the process is using. vms is the Virtual Memory Size which is the virtual memory that process is using.

What is a resident set in a virtual memory machine?

In computing, resident set size (RSS) is the portion of memory occupied by a process that is held in main memory (RAM). The rest of the occupied memory exists in the swap space or file system, either because some parts of the occupied memory were paged out, or because some parts of the executable were never loaded.


1 Answers

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://groups.google.com/group/gnu.utils.help/browse_thread/thread/bb530eb072f86e18/83599c4828de175b

http://forums.whirlpool.net.au/archive/1693957

like image 87
bug313 Avatar answered Sep 29 '22 19:09

bug313