Virtual Memory

a virtual address

Think of the room numbers printed in a tenant's personal blueprint — 'room 412.' That number is real to the tenant and they use it every day, but it is not where anything physically sits in the building; it is a name that the building manager will translate. A virtual address is that kind of name: it is the address a program actually computes and uses, living in the program's own private numbering scheme rather than pointing directly at a real memory chip.

Concretely, when your program says 'load the value at address 0x7fff1234,' that number is a virtual address. The CPU does not send it straight to memory. Instead the MMU splits it into two parts — a virtual page number (the high bits, naming which page) and an offset (the low bits, naming which byte within the page) — looks the page number up in the page table to find the physical frame, and keeps the offset unchanged. The result is the physical address that the memory chips actually see. The program never knows or cares that this happened.

Why it matters: because every program gets its own complete virtual address space, two programs can both use address 0x400000 with no conflict, a program can be loaded anywhere physically without changing the addresses baked into it, and addresses that no page maps to simply do not exist for that program (touching one is a fault, which is how stray pointers get caught). The virtual address space is usually far larger than installed RAM — a 64-bit machine names an astronomically large space — and most of it is never backed by anything.

With 4 KiB pages, the virtual address 0x00403A1C splits as page number 0x403 and offset 0xA1C. Translation replaces only the page number; the offset 0xA1C survives unchanged into the physical address.

A virtual address = (page number to be translated) + (offset kept as-is).

'Virtual' does not mean 'fake' or 'slow' — a virtual address is what every instruction in a normal user program uses for memory, and translation is usually fast thanks to the TLB. It is the program's real, everyday address; only its mapping to hardware is indirect.

Also called
logical address邏輯位址