Virtual Memory & Memory Mapping

the memory management unit (MMU)

/ EM-EM-YOO /

The MMU is the dedicated piece of hardware inside the CPU that does address translation automatically, on every memory access, without the operating system or your program being involved per-access. It is the building manager made of silicon: the instant a virtual address is used, the MMU looks up where it really lives and forwards the access to the right physical frame.

Concretely, when the CPU executes an instruction that reads or writes memory, the address it produces is virtual. Before the request reaches the RAM, the MMU intercepts it, splits it into page number and offset, finds the frame (first checking the TLB, then walking the page table if needed), checks the permission bits, and emits the physical address. If everything is fine, the access completes and software never notices. If the page is not present or the permissions forbid the access, the MMU does not silently fail — it raises a fault and hands control to the OS, which decides whether to fix it (load the page) or kill the program (an illegal access).

The reason translation can be hidden and fast is entirely that it is hardware. Doing this in software for every load and store would be unthinkably slow. The OS does not perform translations; it sets up the tables and handles the exceptions, and the MMU does the relentless per-access work. This division — OS sets policy, MMU enforces it billions of times a second — is the heart of how virtual memory is practical at all.

When your code runs mov eax, [rbx] with rbx holding 0x404820, the CPU hands 0x404820 to the MMU; the MMU translates it to, say, physical 0x71c820 and fetches that word into eax — all in hardware, with no system call.

The MMU translates every access; the OS only set up the tables.

The OS does not translate addresses itself — it programs the MMU (fills the page tables, loads cr3) and the MMU does the work. When the MMU cannot translate or the permissions disagree, it raises a fault; the OS handles the fault, it does not do the routine translation.

Also called
MMU記憶體管理單元