CSE Roadmap

Core tier · about 5 hours · 7 parts

Part 3 of 7 · 2 min read

The kinds of resident memory

The resident size is not one lump. Linux splits it into three parts, shown in /proc/PID/status:

Field Meaning Value in the test Source in the test
RssAnon anonymous pages: heap, stack, anonymous mappings 132,060 kB A (102,400) + C (about 29,500) + small items
RssFile pages of mapped files, such as program code and libraries 52,624 kB D (51,200) + the C library (about 1,400)
RssShmem pages of shared memory objects 20,480 kB E

In plain words: The three add up to the total: 132,060 + 52,624 + 20,480 = 205,164 kB, equal to VmRSS. The split decides what can be done about the memory.

  • Anonymous pages have no file. They can leave memory only by swap (page 7), so they are the pages that make a process grow without bound, and the pages that a leak consists of.
  • File-backed pages can always be dropped and read again from the file (page 4). A large RssFile is cheap to the system: the kernel takes the frames back when it needs them, and it is shared with the other programs that map the same file.
  • Shared memory pages belong to a memory object (page 5). They stay as long as the object exists, and every process that maps them counts them in its own RssShmem.

For the field VmData, a related number of 152,548 kB appeared. It counts the private writable mappings, here the heap and the anonymous blocks, including the 20 MiB block B that was not touched. This is one more place where a reserved but unused block shows up.

RssAnon, RssFile and RssShmem

RssAnon, RssFile and RssShmem are the three parts of a process's resident set in /proc/PID/status: anonymous pages with no file, pages of mapped files, and pages of shared memory objects. Their sum is VmRSS.

Example: in the test, 132,060 + 52,624 + 20,480 kB gave 205,164 kB, the whole resident size.

Check yourself: 1. Which of the three parts can the kernel drop without swap space? 2. Which part is a leak made of? 3. Why does a database that maps a large file show a big RssFile and still not endanger the machine?