download

Why is virtual memory 2 GiB when RSS is 24 MiB?

Systems~8 minReviewed 2 Dec 2026Free · No sign-in

Question

Four worker processes run on a host with 4 KiB pages. At startup, each worker maps a 2,048 MiB scratch buffer and loads the same 16 MiB shared library. It then writes 1 byte into every page of the first 8 MiB of its scratch buffer. Your alert sees VSZ above 2,048 MiB, while RSS shows 24 MiB.

  1. Why is RSS only 24 MiB?
  2. How many minor page faults did writing those 8 MiB cause?
  3. Why does summing RSS across all 4 workers overstate real RAM use, and what metric fixes it?
Show hints (3)
  1. "RESERVED VERSUS RESIDENT"

    Virtual memory reserves address ranges in page tables. When does the kernel actually assign a physical RAM frame?

  2. "COUNT TOUCHED PAGES"

    Convert 8 MiB to KiB, then divide by the 4 KiB page size. Writing 1 byte in a page still faults the whole page.

  3. "SHARED LIBRARY MATH"

    Each worker counts the full 16 MiB library inside its own RSS. How many copies sit in physical RAM?

Show checked explanation

Because of demand paging. Mapping 2,048 MiB reserves virtual addresses (VSZ) without backing them in RAM until you touch them. Writing the first 8 MiB triggers 2,048 minor page faults, adding 8 MiB of private RAM plus the 16 MiB shared library for 24 MiB RSS. Summing RSS counts the shared library four times; use PSS instead.

"SOLUTION · PYTHON"
PAGE_KIB = 4


def memory_report(vsz_mib, touched_mib, shared_mib, workers):
    faults = (touched_mib * 1024) // PAGE_KIB
    rss_mib = touched_mib + shared_mib
    pss_mib = touched_mib + shared_mib / workers
    actual_ram_mib = workers * touched_mib + shared_mib
    return vsz_mib + shared_mib, faults, rss_mib, pss_mib, actual_ram_mib


vsz, faults, rss, pss, ram = memory_report(2048, 8, 16, 4)
print(f"VSZ={vsz}MiB faults={faults} RSS={rss}MiB PSS={pss:.0f}MiB")
print(f"sum_RSS={rss * 4}MiB actual_RAM={ram}MiB")
"OUTPUT"
VSZ=2064MiB faults=2048 RSS=24MiB PSS=12MiB
sum_RSS=96MiB actual_RAM=48MiB

Ran the memory math on CPython 3.12.10 (Windows x64) and checked lazy virtual allocation working-set growth via Win32 VirtualAlloc. Checked by an editor other than the author.

Walkthrough

The OS allocates physical RAM lazily, one page at a time. Calling mmap (or VirtualAlloc on Windows) for 2,048 MiB only records a virtual address range. No physical frames move until your code touches an address inside that range.

Each time the worker writes 1 byte into a new 4 KiB page, the CPU raises a minor page fault. The kernel grabs a zeroed physical frame, updates the page table, and resumes the instruction. Touching 8 MiB (8,192 KiB) across 4 KiB pages causes 8,192 / 4 = 2,048 minor page faults and commits 8 MiB of physical RAM. The remaining 2,040 MiB stays virtual only.

metricper workersum across 4 workerswhat it measures
VSZ (VmSize)2,064 MiB8,256 MiBTotal mapped virtual address space
RSS (VmRSS)24 MiB96 MiBPrivate RAM (8) + full shared library (16)
PSS12 MiB48 MiBPrivate RAM (8) + 1/4 share of library (4)

All 4 workers map the same 16 MiB shared library in physical RAM. RSS charges the full 16 MiB to every worker, so 4 * 24 = 96 MiB overstates true RAM usage by 48 MiB. Proportional Set Size (PSS) from /proc/<pid>/smaps splits shared pages by the number of processes mapping them: 8 + 16 / 4 = 12 MiB per worker, summing cleanly to the true 48 MiB of RAM.

Common mistakes

  • Paging on-call for high VSZ. Large mmap files, guard pages, and runtime arenas inflate VSZ without using physical RAM.
  • Adding up RSS across processes to estimate host memory usage. Shared libraries and memory-mapped files get counted once per process.
  • Assuming writing 1 byte allocates only 1 byte of RAM. Hardware page tables map memory in full pages, typically 4 KiB each.
  • Confusing minor and major page faults. A minor fault maps an in-memory or zero page; a major fault blocks to read data from disk.

Follow-up questions

  • "If a worker later fills the entire 2,048 MiB buffer on a 1 GiB container, when does it fail?" Not at mmap time under Linux default overcommit. It fails later during page faults, when resident memory hits the cgroup limit and the OOM killer terminates the process.
  • "Can RSS drop even if your application never calls free()?" Yes. Under memory pressure the kernel can evict clean file-backed pages or move anonymous pages to swap. Virtual mappings (VSZ) stay the same while RSS falls.
  • "Where on Linux do you read exact RSS and PSS?" Read /proc/<pid>/smaps_rollup or /proc/<pid>/smaps. The kernel documentation notes that VmRSS in /proc/<pid>/status is a fast approximation, whereas smaps walks the page tables directly.

What a strong answer covers

Explains demand paging with the exact 2,048-fault math, distinguishes virtual reservations from resident frames, and uses PSS to fix RSS double-counting of shared memory.

Open in interactive practice deck →

Original OfferVibe question. proc_pid_status(5) · Linux /proc memory metrics · mmap(2).
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.