Understanding VSZ, RSS, PSS, PageCache and Swap: A Linux Memory Primer
This article explains Linux memory metrics VSZ, RSS, and PSS, illustrates them with a roommate analogy, details PageCache and its role in I/O, describes swap behavior and the swappiness setting, and introduces zero‑copy techniques to reduce data copying and context switches.
What is RSS?
RSS (Resident Set Size) is the total memory a process actually occupies in RAM.
Example calculation: RSS = 1164 + 1846560 + 4048 + 3764 + 1905 = 1857441 KB ≈ 1.7 GB.
Analogy
Three roommates share a house, each representing a process; their living expenses represent memory usage. VSZ counts all possible costs, RSS counts actual costs, and PSS divides shared costs proportionally.
Differences
VSZ : total virtual memory size, includes pages not loaded into RAM; not a reliable indicator of real memory consumption.
RSS : actual pages loaded into physical memory, shows real memory usage.
PSS : proportionally accounts for shared libraries; each shared library’s cost is divided among the N processes using it.
What is Cache?
In Linux, “Cache” usually refers to PageCache, which caches file data in memory to speed up I/O. PageCache and buffer cache are now merged; they store file pages and block‑device data respectively.
Formula: PageCache = Buffers + Cached + SwapCached.
Use the free command to view buffers and cache.
Linux File I/O System
PageCache stores each file as a radix tree and improves read performance via readahead, loading multiple pages at once.
User thread requests data in the 0‑3 KB range; the kernel reads at least 0‑4 KB into a page.
Kernel also prefetches adjacent blocks (4‑8 KB, 8‑12 KB, 12‑16 KB), allocating extra pages.
This reduces I/O operations and increases throughput.
What is Swap?
Swap is disk space used as virtual memory when physical RAM is insufficient. The kernel moves rarely used pages to swap to avoid out‑of‑memory termination.
Swap is triggered when memory allocation fails or when a daemon monitors memory thresholds; the swappiness parameter (0‑100) controls aggressiveness.
High swappiness: frequent swapping of inactive processes.
Low swappiness: less swapping, better interactive performance.
Extension – Zero‑Copy
Zero‑copy reduces data copying and context switches. Without it, data moves four times between device, kernel, and user space, involving four context switches.
Device ↔︎ Memory: disk to PageCache, PageCache to socket.
Memory internal copies: kernel to user buffer, user buffer to kernel socket.
Four context switches for read/write syscalls.
Zero‑copy lets the CPU manage transfers while DMA handles the actual copying.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
