AlgoViz

Reading memory evidence at the right boundary

medium 6 min

Virtual size includes mapped ranges whether or not their pages are resident.

Video lesson · Chapter 1 of 8

Why adding up worker RSS overcounts

0:00 / 5:19

Theory

Read or listen first. About 1 min.

What it is

Virtual size includes mapped ranges whether or not their pages are resident. RSS measures resident pages seen through one process. Summing RSS across workers counts a shared page repeatedly. Proportional set size divides shared pages among their mappings, while cgroup accounting measures the group’s charge under a different set of rules.

Why it exists

A prefork service triples its worker count and the RSS sum jumps. Before buying RAM compare proportional and private dirty memory, node availability, cgroup usage and pressure. Similar shared mappings can account for most of the apparent growth. Repeat after workers mutate shared pages because copy-on-write can turn that apparent cost into real private memory.

If private dirty pages and the group charge grow with tenant churn, investigate retained mutable data instead of shared mappings.

Why adding up worker RSS overcounts

Worker mappings → Shared library pages (map same pages). Shared library pages → Group accounting (account shared memory)
Worker mappings → Shared library pages (map same pages). Shared library pages → Group accounting (account shared memory)

Inside this chapter

Memory Analysis with free and vmstat
Available memory estimates how much can be used without swapping under current conditions. Vmstat samples activity over time, including paging and runnable work. Compare interval rows rather than only a boot average.
Process Memory Maps with pmap
A mapping list breaks a process down into anonymous regions, stacks and file-backed segments. Large mapped size alone does not show how many pages have been touched.
Understanding /proc/meminfo
Meminfo distinguishes several classes of memory, including file cache, dirty pages and reclaimable slab. Some fields overlap, so adding every line yields a meaningless total.
Buffers vs Cache in Linux Memory
Buffer and page caches serve kernel and file I/O. Some cached memory can be reclaimed. The cost depends on whether pages are clean, dirty or still actively used.

How it works

Step through the idea, or press Play.

Step 1 of 4

Map the worker. Separate file-backed segments, stack and heap in one process.

Understand it

Worked incident

Why adding up worker RSS overcounts

ObservationSum of worker RSS (MiB)Interpretation
Baseline200A single worker maps the shared dataset.
Incident600Three workers report the same resident shared pages in their own totals.
After intervention220Compare PSS and the group charge, then right-size the worker pool and watch private growth.
Illustrative measurements from the same workload at three checkpoints.

Choose the next investigation

If private dirty pages and the group charge grow with tenant churn, investigate retained mutable data instead of shared mappings.

Summary

The whole topic in one minute.

PSS divides each shared page across its mappings. The group’s actual charge and pressure provide an independent operational check.

If private dirty pages and the group charge grow with tenant churn, investigate retained mutable data instead of shared mappings.

Sources