CSE Roadmap

Core tier · about 5 hours · 7 parts

Part 5 of 7 · 2 min read

The map of a process

In plain words: The next question is where the memory lies in the address space. pmap -x PID prints each mapping with its size, resident size and dirty size, taken from /proc/PID/smaps. For the test program, the largest lines, sorted by resident size, are:

Mapping Size (kB) Resident (kB) Dirty (kB) What it is
anonymous, one block 122,888 102,408 102,408 A and B, adjacent in the address space
file big.dat, read-only 51,200 51,200 0 D
anonymous, the heap 29,568 29,532 29,532 C
shared object mys 20,480 20,480 20,480 E
libc.so.6, code 1,572 1,044 0 the C library

The table tells the story of page 1 in numbers. The first line has a size 20,480 kB larger than its resident size: that is block B, reserved and not used. The heap line (the brk region) and the anonymous mapping are different lines, as page 1 explained. The file mapping has no dirty pages, because nothing wrote to it, so the kernel can drop them. A line with a large dirty size is memory that would need swap or a write-back.

The allocator has its own view. The call mallinfo2 reported arena 29,568 kB (the heap of brk), hblkhd 122,888 kB (blocks that malloc mapped separately) and uordblks 29,537 kB in use in the arena. The numbers match the table: the heap arena is the line of 29,568 kB, and the mapped blocks are the 122,888 kB line. If arena is much larger than uordblks, the heap holds a lot of free space that was not returned to the kernel (heap fragmentation, page 1).

smaps

/proc/PID/smaps is a file that lists every mapping of a process with its size, resident size, proportional size, dirty and clean pages, and the pages in huge pages, and pmap -x and /proc/PID/smaps_rollup show the same data in compact forms.

Example: the line of the 50 MiB file mapping showed 51,200 kB resident and 0 kB dirty.

Read it as

A mapping whose size is much larger than its resident size is address space that is reserved and unused. A mapping with a large dirty size is memory that cannot be dropped for free.

Check yourself: 1. Why does the first mapping have a size larger than its resident size? 2. What does a dirty size of 0 on a file mapping tell you? 3. What does it mean if arena is much larger than uordblks?