Virtual Memory & Memory Mapping

address translation

Address translation is the act of turning a virtual address into a physical one — the building manager looking up 'apartment 12' in this tenant's private directory and finding 'floor 7, unit 3'. It happens on every single memory access, billions of times a second, which is why it must be done in hardware and made fast.

Here is the method in plain steps. The system fixes a page size, almost always 4 KiB (4096 bytes). A virtual address is then split into two parts: the high bits are the virtual page number, and the low 12 bits are the offset within the page. To translate, the hardware takes the virtual page number, looks it up in the page table to find which physical frame it currently lives in, and then glues that frame number back onto the unchanged offset. So virtual address 0x401__7c8 (page 0x401, offset 0x7c8) becomes physical address frame__7c8 where 'frame' came from the table. The offset never changes — translation only relocates whole pages, never bytes within a page.

Because looking through the page table on every access would be ruinously slow, two accelerators sit in front of it: the MMU does the lookup in hardware, and the TLB caches recent translations so most accesses skip the table walk entirely. When a wanted translation is missing or forbidden, the hardware raises a page fault and hands control to the OS. Translation is invisible when it works and only becomes noticeable as a cost when the TLB misses or a page fault occurs.

With 4 KiB pages, virtual address 0x00401abc splits into page number 0x401 and offset 0xabc. If the page table maps page 0x401 to physical frame 0x0d2, the physical address is 0x0d2abc — note the offset 0xabc is carried over unchanged.

Replace the page number, keep the offset — that is the whole trick.

The low bits (the offset) are NOT translated; only the page number is. A common confusion is thinking the whole address is remapped byte-by-byte — it is not, which is exactly why page size and alignment matter.

Also called
paging translationvirtual-to-physical mapping位址對映