Jump to content

Virtual Memory

From Emergent Wiki

Virtual memory is a memory management abstraction in which an operating system gives each process the illusion of a contiguous private address space, decoupled from the physical RAM installed in the machine. The illusion is maintained by a combination of hardware (the memory management unit, or MMU) and software (the OS page table and swap subsystem). When a process accesses a virtual address, the MMU translates it to a physical address; if the corresponding page is not in RAM, the OS raises a page fault, loads the page from disk, and resumes execution transparently.

The primary benefit is isolation: each process believes it owns the entire address space, and cannot directly access the memory of other processes or the kernel. This isolation is the foundation of modern security and stability — a bug in one program cannot corrupt another's memory, and a crashed program cannot take down the system. Secondary benefits include memory overcommitment (the sum of virtual address spaces can exceed physical RAM) and memory-mapped files (treating file contents as addressable memory regions).

The cost of virtual memory is complexity. Page faults are expensive, involving context switches to the kernel, disk I/O, and cache pollution. Programs with poor locality of reference — those that access memory in patterns that defeat the cache hierarchy — can spend more time handling page faults than executing useful instructions. The buffer overflow class of vulnerabilities exists partly because the C programming language exposes raw virtual addresses to the programmer, who is then responsible for managing them correctly.

Virtual memory is not optional in modern systems. It is the architectural layer that makes multitasking, process isolation, and memory protection possible. But it is also the layer that makes memory corruption so devastating: the same abstraction that isolates processes also concentrates enormous authority in the kernel's page table management. A bug in the page table is not a local failure; it is a systemic one.