Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does maximum resident set size mean?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
  int i = 0;
  struct rusage r_usage;
  while (++i <= 10) {
    void *m = malloc(20*1024*1024);
    memset(m,0,20*1024*1024);
    getrusage(RUSAGE_SELF,&r_usage);
    printf("Memory usage = %ld\n",r_usage.ru_maxrss);
    sleep (3);
  }
  printf("\nAllocated memory, sleeping ten seconds after which we will check again...\n\n");
  sleep (10);
  getrusage(RUSAGE_SELF,&r_usage);
  printf("Memory usage = %ld\n",r_usage.ru_maxrss);


  return 0;
}

The above code uses ru_maxrss attribute of rusage structure. It gives the value of maximum resident set size. What does it mean? Each time the program is executed it gives a different value. So please explain the output of this code?

enter image description here

enter image description here

These are screenshots of two executions of the same code which give different outputs, how can these numbers be explained or what can be interpreted from these two outputs?

like image 472
codeczar Avatar asked Mar 20 '20 17:03

codeczar


People also ask

What does the Resident Set Size indicate?

The resident set size (RSS) is the amount of space of physical memory (RAM) held by a process. The value is typically specified in bytes or pages. If the full amount of space required by a process exceeds the RSS, the remaining portion is typically stored in swap.

What is Resident Set Size Linux?

2.1. Resident Set Size. 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. Also, it includes all heap and stack memory.

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.

What is RSS and VSZ memory?

RSS is Resident Set Size (physically resident memory - this is currently occupying space in the machine's physical memory), and VSZ is Virtual Memory Size (address space allocated - this has addresses allocated in the process's memory map, but there isn't necessarily any actual memory behind it all right now).


1 Answers

Resident set size (RSS) means, roughly, the total amount of physical memory assigned to a process at a given point in time. It does not count pages that have been swapped out, or that are mapped from a file but not currently loaded into physical memory.

"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.

It can vary from one run to the next if, for instance, the OS decided to swap out different amounts of your program's memory at different times. This decision would depend in part on what the rest of the system is doing, and where else physical memory is needed.

like image 147
Nate Eldredge Avatar answered Nov 01 '22 13:11

Nate Eldredge