Virtual memory
The conceptWhy two programs can both use address 4096 without clashing
Every process sees its own private range of memory addresses, called its virtual address space. When your browser and your music app both store something at address 4096, they are really writing to two different spots in RAM.
Program addresses aren't real RAM locations. The OS cuts each address space into pages (usually 4,096 bytes) and RAM into same-sized frames. A per-process page table records which frame holds each page.
On every access, CPU hardware called the MMU (memory management unit) splits the address into page number and offset, then swaps the page number for the frame from the table. The offset is kept: pages and frames match in size.
What it’s forTurns an address a program uses into the real RAM address the hardware reads.
physical = frame(⌊v ÷ P⌋) × P + (v mod P)
- v
- the virtual address the program asked for
- P
- the page size, usually 4,096 bytes
- frame( )
- the page-table lookup: which RAM frame holds this page, for this process only
- v mod P
- the offset, how far into the page the byte sits
What it givesThe real RAM address, which differs for each process even when v is the same.
- v = 8,200, P = 4,096 → page 2, offset 8
- This process's table says page 2 is in frame 5
- 5 × 4,096 + 8 = 20,488