Part 4 of 7 · 2 min read
Shared pages
In plain words: If two processes use the same frame, both count it in their RSS. The sum over all processes then exceeds the real use of memory. The measure that corrects it is the proportional set size (PSS). Each shared page is divided by the number of processes that share it, so the sum of the PSS over all processes equals the real use. The file /proc/PID/smaps_rollup gives Rss and Pss together.
The test forked after step E, and the child did not write anything. The numbers for the parent, before the fork and after it:
| Moment | Rss | Pss |
|---|---|---|
| Before the fork | 205,164 kB | 203,981 kB |
| After the fork, child sharing every page | 205,292 kB | 137,995 kB |
After the fork, the RSS is the same, since the parent still has every page resident. The PSS fell by about 66,000 kB, because the anonymous pages (132,060 kB) are now shared with the child by copy-on-write (page 6 of Level 6) and each process is charged half. If the child writes to them, they are copied and the PSS rises again. The small difference of 1,200 kB before the fork comes from the C library pages, which are shared with every other process on the machine.
So PSS is the right measure for "what does this process cost", and RSS the right measure for "what is mapped by this process". Adding the RSS of many worker processes of a server, such as a web server that forks, gives a number far above the truth.
Proportional set size
The proportional set size (PSS) of a process is its resident memory in which each page shared with other processes is counted as a fraction, the page size divided by the number of processes that map it, so that the PSS of all processes together adds up to the memory actually used.
Example: a 100 MiB region shared equally by two processes adds 100 MiB to the RSS of each, and 50 MiB to the PSS of each.
Check yourself:
1. Why does the RSS stay the same after a fork, and the PSS fall?
2. What happens to the PSS when the child writes to a shared anonymous page?
3. Which measure is better for adding up the cost of 20 worker processes?