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
forkcheap: pages are shared read-only until written. - RSS = resident physical memory; VSZ = virtual size (mostly meaningless).
- Overcommit decides whether
malloccan succeed without swap; the OOM killer is the backstop. mmapmaps files or anonymous memory;mlockpins pages (used by databases).
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?
Why
Major faults involve I/O and dominate latency; minor faults are page-table work.