Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is RSS and VSZ in Linux memory management

Tags:

linux

What are RSS and VSZ in Linux memory management? In a multithreaded environment how can both of these can be managed and tracked?

like image 573
tuban Avatar asked Oct 24 '11 19:10

tuban


People also ask

What is RSS in Linux memory?

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 does VSZ stand for Linux?

VSZ is short for Virtual Memory Size. It's the total amount of memory a process may hypothetically access. It accounts for the size of the binary itself, any linked libraries, and any stack or heap allocations. When a process is started, VSZ memory becomes RSS memory, over which we'll go now.

What is RSS in ps command Linux?

PS service RSS stands for Resident Set Size and shows how much RAM is utilized at the time the command is output. It also should be noted that it shows the entire stack of physically allocated memory.

What is VSS and RSS in top command?

From the page... Vss = virtual set size. Rss = resident set size.


2 Answers

RSS is the Resident Set Size and is used to show how much memory is allocated to that process and is in RAM. It does not include memory that is swapped out. It does include memory from shared libraries as long as the pages from those libraries are actually in memory. It does include all stack and heap memory.

VSZ is the Virtual Memory Size. It includes all memory that the process can access, including memory that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.

So if process A has a 500K binary and is linked to 2500K of shared libraries, has 200K of stack/heap allocations of which 100K is actually in memory (rest is swapped or unused), and it has only actually loaded 1000K of the shared libraries and 400K of its own binary then:

RSS: 400K + 1000K + 100K = 1500K VSZ: 500K + 2500K + 200K = 3200K 

Since part of the memory is shared, many processes may use it, so if you add up all of the RSS values you can easily end up with more space than your system has.

The memory that is allocated also may not be in RSS until it is actually used by the program. So if your program allocated a bunch of memory up front, then uses it over time, you could see RSS going up and VSZ staying the same.

There is also PSS (proportional set size). This is a newer measure which tracks the shared memory as a proportion used by the current process. So if there were two processes using the same shared library from before:

PSS: 400K + (1000K/2) + 100K = 400K + 500K + 100K = 1000K 

Threads all share the same address space, so the RSS, VSZ and PSS for each thread is identical to all of the other threads in the process. Use ps or top to view this information in linux/unix.

There is way more to it than this, to learn more check the following references:

  • http://manpages.ubuntu.com/manpages/en/man1/ps.1.html
  • https://web.archive.org/web/20120520221529/http://emilics.com/blog/article/mconsumption.html

Also see:

  • A way to determine a process's "real" memory usage, i.e. private dirty RSS?
like image 184
jmh Avatar answered Oct 13 '22 03:10

jmh


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

Note that in these days of commonplace virtual machines, physical memory from the machine's view point may not really be actual physical memory.

like image 30
caf Avatar answered Oct 13 '22 03:10

caf