CSE Roadmap

Core tier · about 5 hours · 7 parts

Part 2 of 7 · 2 min read

VmSize and VmRSS

Think of it this way. A hotel has a register of booked rooms and a count of rooms with a guest inside. The first is larger. The file /proc/PID/status gives both numbers for a process. VmSize is the total size of all its mappings, whether or not any page was ever touched. VmRSS, the resident set size, is the amount held in physical memory now. The analogy stops in one place: a booked room costs the hotel nothing, and in the same way, address space that was never touched costs the machine no frame, though it uses some page table space.

A test program, called "mystery" below, does five things and then prints its own numbers:

Step What it does Touched
A malloc of 100 MiB and memset yes, all
B malloc of 20 MiB, never used no
C 30,000 small malloc calls of 1,000 bytes, each filled yes
D maps 50 MiB of a file and reads one byte per page yes
E a shared memory object of 20 MiB, filled yes

The result from /proc/self/status:

Field Value
VmSize 226,712 kB
VmRSS 205,164 kB

In plain words: The difference is 21,548 kB. It is the 20 MiB of step B (20,480 kB) that were reserved and never touched, plus about 1 MB of mappings of the C library that are not resident. When a report says "the process uses 226 MB", the first question is which of the two numbers is meant. The system's memory pressure follows the resident size, and the limit ulimit -v (page 7) follows the virtual size.

Resident set size

The resident set size (RSS) of a process is the amount of its memory that is held in physical frames now, shown as VmRSS in /proc/PID/status and as RSS or RES in ps and top, while the virtual size counts all its mappings, whether resident or not.

Example: a 20 MiB malloc that is never touched adds 20,480 kB to VmSize and nothing to VmRSS.

Check yourself: 1. Which number grows when a program calls malloc and never touches the block? 2. Which number does the OOM killer care about? 3. Why was VmSize 21,548 kB more than VmRSS in the test?