virtual memory
Virtual memory is a memory management technique in which the operating system gives each running program its own private range of addresses and maps those addresses onto physical memory behind the scenes.
Programs read and write virtual addresses, never physical ones. Memory is split into fixed-size blocks called pages, usually 4 KiB or larger, and the operating system keeps a page table for every process that records where each page actually lives. A hardware component called the memory management unit (MMU) uses that table to translate each address on the fly.
This layer of indirection gives the operating system several capabilities:
- Isolation: Each process sees only its own address space, so a bug in one program can’t overwrite another program’s memory.
- Overcommitment: Pages that haven’t been used recently can be written out to disk, so programs can collectively use more memory than the machine physically has.
- Lazy loading: A page receives physical memory only when first touched. Accessing a page that isn’t currently in physical memory triggers a page fault, and the operating system loads or allocates it before resuming the program.
- Sharing: Several processes can map the same physical pages, which lets them share library code or a memory-mapped file without copying it.
In the simulator below, click a page in either process to watch the MMU translate its address. A page that’s already in RAM is a hit, while any other page triggers a page fault that loads it into RAM and, when RAM is full, evicts the least recently used page to disk.
The trade-off is overhead. Every translation costs time, so processors keep recent ones in a small cache called the translation lookaside buffer (TLB). When the pages a program actively uses no longer fit in physical memory, the system spends most of its time moving pages to and from disk, a condition called thrashing.
The idea dates to the Atlas computer at the University of Manchester, commissioned in 1962, which introduced paging. Python’s mmap module maps a file straight into a process’s address space, and MemoryError signals that an operation has run out of memory.
Related Resources
Tutorial
Memory Management in Python
Take a deep dive into Python memory management and learn how CPython allocates and frees memory for your objects with arenas, pools, and blocks.
For additional information on related topics, take a look at the following resources:
- Python mmap: Improved File I/O With Memory Mapping (Tutorial)
- Python mmap: Doing File I/O With Memory Mapping (Course)
- Pointers in Python: What's the Point? (Tutorial)
- Your Guide to the CPython Source Code (Tutorial)
- How Python Manages Memory (Course)
- Memory Management in Python (Quiz)
- Pointers and Objects in Python (Course)
- Your Guide to the CPython Source Code (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Nov. 11, 2026