Systems study
Offline — showing the cached copy.
Home / Operating Systems / 4. Virtual memory

4. Virtual memory

One-liner. Every process sees its own contiguous address space, mapped to physical pages on demand.

Memorize

  • The MMU walks page tables (4-level on x86-64, 5-level optional) to translate virtual → physical.
  • The TLB caches translations; a context switch may flush it (PCID mitigates).
  • Pages are typically 4 KB; huge pages (2 MB/1 GB) cut TLB pressure.
  • Demand paging: memory is allocated on first touch; a minor fault maps a page, a major fault reads from disk.
  • COW makes fork cheap: pages are shared read-only until written.
  • RSS = resident physical memory; VSZ = virtual size (mostly meaningless).
  • Overcommit decides whether malloc can succeed without swap; the OOM killer is the backstop.
  • mmap maps files or anonymous memory; mlock pins pages (used by databases).
ADDRESS TRANSLATION VIRTUAL ADDRESS process page ta… MMU/TLB cached translat… PHYSICAL PAGES RAM frames swap when evict… BACKING file on disk anonymous swap mmap
Address translation

Trap. Treating VSZ as memory usage — a JVM or Go process can reserve terabytes of virtual space. Do this. Watch RSS/anonymous memory and page-fault rates, not VSZ.

Check

What is the difference between a minor and a major page fault?