Here is a thing that happens regularly: someone looks at ps aux, sees a process using 800 MB of RSS, panics, adds more RAM, and the problem doesn’t change. Or they add up all the RSS values for their processes, get a number larger than the physical RAM installed, and think something is badly wrong.
Neither of these people is stupid. The RSS column in ps is just wrong. Not buggy-wrong, wrong by design, because it’s measuring the wrong thing. Every shared page (libc, libssl, every shared library your process loaded) is counted in full for every process that maps it. Fifty processes all linked against the same libc get fifty full copies of libc’s pages charged to their RSS. The actual physical cost is one copy.
For the resident memory attributable to a process, read PSS: Proportional Set Size. It’s in /proc/<pid>/smaps_rollup on kernels that provide that file. Almost nobody reads it.
What the kernel is tracking
Every process has a set of virtual memory areas (VMAs). Each VMA has a type and a backing:
- Anonymous: heap, stack,
mmap(MAP_ANONYMOUS), no file backing, this is “your” memory - File-backed: shared libraries,
mmap’d files, executable text segment - Shared: mapped with
MAP_SHARED, potentially shared with other processes
For each page in each VMA, the kernel knows how many processes have it mapped. PSS takes each page’s size and divides by the number of processes sharing it, then sums across all pages. A page shared by four processes contributes page_size / 4 to each process’s PSS. A private anonymous page contributes its full size.
The result: sum PSS across a set of processes and you get a useful estimate of the resident pages attributable to that set, with shared pages split among all processes mapping them. It is not total machine memory: it leaves out kernel memory and unmapped cache, and a system-wide total needs every accessible process. Do the same with RSS and you double-count shared pages.
Reading smaps_rollup
cat /proc/<pid>/smaps_rollup
Output looks like this:
00400000-7ffdc0000000 ---p 00000000 00:00 0 [rollup]
Rss: 184320 kB
Pss: 31408 kB
Pss_Anon: 28160 kB
Pss_File: 3248 kB
Pss_Shmem: 0 kB
Shared_Clean: 156160 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 28160 kB
Referenced: 184320 kB
Anonymous: 28160 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
ShmemPmdMapped: 0 kB
FilePmdMapped: 0 kB
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
Locked: 0 kB
The fields that matter:
Rss: 184 MB of resident pages, counting shared pages at full cost. The ps RSS column comes from the faster /proc counters and can differ slightly from this more precise Rss field.
Pss: 31 MB. This is the process’s proportional share of resident pages. The gap from RSS comes from pages mapped by other processes too; the rollup alone cannot tell you that every shared page belongs to a library.
Pss_Anon: the proportional share of resident anonymous pages. It includes anonymous pages shared after fork, so it is not a private-heap counter. Sustained growth is a clue to investigate, not proof of a leak.
Pss_File: your proportional share of file-backed mappings (shared libraries, mmap’d files). A process that has loaded forty shared libraries will have a larger Pss_File than one that statically linked everything, even if the actual unique work they do is similar.
Shared_Clean: clean resident pages mapped by more than one process. File-backed pages can be dropped and read back from storage; clean anonymous pages are a different case. This field alone does not say how cheaply the kernel can reclaim them.
Shared_Dirty: dirty resident pages mapped by more than one process. mmap(MAP_SHARED) writable mappings are one possible source. Reclaim depends on backing and swap, so this is not a direct measure of disk writes owed.
Private_Dirty: dirty resident pages mapped by only this process. Heap and stack often show up here, though other mappings can too. This is useful for spotting unique memory, but page reclaim and OOM pressure need more than this one field.
Anonymous: resident anonymous pages counted without proportional sharing. It can exceed Pss_Anon when anonymous pages are shared, for example after fork.
USS: the paranoid number
USS (Unique Set Size) isn’t a field in smaps_rollup, but you can estimate resident USS as Private_Clean + Private_Dirty. These pages are mapped only by this process. Killing it can release them, but that sum is not a promise about how much free will rise: other process and kernel allocations, file cache, and swapping all matter.
awk '/^Private_(Clean|Dirty):/{sum += $2} END {print sum " kB"}' /proc/<pid>/smaps_rollup
USS helps estimate which process holds unique resident pages. PSS helps compare the resident cost of processes sharing libraries. Neither number predicts the OOM killer’s choice or accounts for a cgroup’s full memory charge.
Scripting it: PSS for all processes
#!/bin/sh
# PSS for every process, sorted descending
for pid in /proc/[0-9]*/smaps_rollup; do
p=${pid%/smaps_rollup}
p=${p##/proc/}
pss=$(awk '/^Pss:/{print $2}' "$pid" 2>/dev/null) || continue
comm=$(cat /proc/$p/comm 2>/dev/null)
[ -n "$pss" ] && printf "%8d kB %s (%s)\n" "$pss" "$comm" "$p"
done | sort -rn | head -20
This ranks processes by proportional resident pages. Run it beside ps aux --sort=-%mem and the order can change when processes share many pages. A process can exit between reads; unreadable entries are skipped. Reading every smaps_rollup walks page mappings and costs more than reading ps, so this is a diagnostic snapshot, not a tight monitoring loop.
# Total PSS across readable processes (mapped resident pages only)
awk '/^Pss:/{sum+=$2} END{print sum/1024 " MB"}' /proc/*/smaps_rollup 2>/dev/null
This totals PSS for the processes whose rollups you can read. It will not match free -m’s used figure, which includes memory outside process mappings. Permissions, short-lived processes, and shared pages mapped by processes you cannot inspect also limit the snapshot.
Per-region breakdown: full smaps
smaps_rollup aggregates all VMAs. If you need per-region breakdown (which library is costing the most, where the anonymous heap segments are, what’s swapped), read /proc/<pid>/smaps directly:
cat /proc/<pid>/smaps
Each VMA gets its own block with the same fields. The file can be large (hundreds of entries for a process with many loaded libraries), but you can grep it:
# Find the heap
grep -A 20 '\[heap\]' /proc/<pid>/smaps
# Find all anonymous segments sorted by size
awk '/^[0-9a-f]+-[0-9a-f]+ /{vma=$0} /^Private_Dirty:/{print $2, vma}' /proc/<pid>/smaps | sort -rn | head -20
When does this actually matter
Most of the time you are debugging the wrong thing. If you suspect a leak, watch Pss_Anon and Private_Dirty under comparable load. Growth tells you to inspect allocations; it does not prove a leak. An allocator may retain freed pages, and anonymous pages can be shared. The MADV_FREE and RSS walkthrough shows another way a growing resident number can mislead you.
For capacity planning (“how many instances of this service can I run on this box”), compare PSS at a representative load and account separately for kernel memory, page cache, and cgroup limits. RSS overcounts pages shared by processes; USS leaves those pages out. PSS assigns a fraction to each mapper, but that fraction changes when the number of mappers changes.
The OOM killer uses its own accounting (/proc/<pid>/oom_score_adj, /proc/<pid>/oom_score), which approximates RSS with adjustments; it is not PSS-based, so the process the OOM killer kills is not necessarily the one with the highest PSS. If you are tuning OOM behavior, read oom_score and adjust oom_score_adj explicitly, do not assume the highest-PSS process will be killed first.
The kernel’s /proc documentation defines the rollup and its proportional anonymous, file, and shmem fields. For the broader memory model, Kerrisk’s The Linux Programming Interface (Amazon affiliate link; RodHat may earn a commission) covers mappings and virtual memory in Chapters 49 and 50; Stevens’ Advanced Programming in the UNIX Environment (Amazon affiliate link; RodHat may earn a commission) covers process memory layout in Chapter 7.
