HomeARM CourseDay 21
DAY 21 · SYSTEM & MEMORY

The MMU & Virtual Memory

By EcrioniX · Updated Jun 6, 2026

How can two programs both use address 0x8000 without colliding? How can a program "see" more memory than the chip physically has? The answer to both is one of the most elegant ideas in computing: virtual memory, made real by the MMU. This is the hardware that turns a microcontroller into a computer that can run Linux.

1. The big idea: a layer of indirection

Every address your program uses is a virtual address. It is not the real location in RAM. Between the CPU and memory sits the MMU (Memory Management Unit), which translates each virtual address into a physical address on the fly, for every single access.

That one layer of indirection buys an astonishing amount:

2. Pages and page tables

Translating every byte individually would be impossible, so memory is divided into fixed-size chunks called pages (commonly 4 KB). The MMU only needs to map page → page. The map itself is the page table, stored in memory: one entry per virtual page giving its physical frame plus permission bits.

Virtual address → physical address Virtual address[ page number | offset ] Page tablepage→frame + perms(+ TLB cache) Physical address[ frame | offset ] The offset passes straight through; only the page number is translated. Real ARM uses multi-level tables (e.g. L1/L2/L3) to keep the table small.
Figure — The low bits (offset within a page) pass through unchanged; the MMU only translates the page number.

A flat table for a 4 GB space would be huge, so ARM uses multi-level page tables (a tree). The CPU register TTBR (Translation Table Base Register) points to the current process's top-level table — switching it is how the OS switches address spaces on a context switch.

3. The TLB — making it fast

Walking a multi-level table means several memory reads per access — far too slow if done every time. So the MMU caches recent translations in the TLB (Translation Lookaside Buffer), a small, very fast lookup. Most accesses hit the TLB and translate in effectively one cycle; a miss triggers a page-table walk to fetch and cache the mapping.

💡 Hotel front desk

The page table is the hotel's full guest register in the back office. The TLB is the receptionist's sticky notes for the guests who came by in the last minute. Most lookups are answered instantly from the notes; only an unfamiliar name needs a trip to the back office.

4. Page faults & demand paging

What if a virtual page isn't currently in RAM, or you touch one you're not allowed to? The MMU raises a page fault — an exception (Day 17) handled by the OS. The OS decides what to do:

This is how a system "runs more than its RAM": rarely used pages live on disk and are paged in on demand.

5. MMU vs MPU

MPU (Day 20)MMU (today)
Translationnone (physical only)virtual → physical
Granularitya few regionsfine-grained pages
Per-process spacenoyes
Typical coreCortex-M / RCortex-A
Runsbare-metal / RTOSLinux, Android, rich OS

The MPU only protects; the MMU translates and protects. That extra power is exactly what a general-purpose OS needs.

✅ The mental model

The MMU sits between CPU and RAM and translates every virtual address to a physical one using page tables, cached by the TLB for speed. This gives each process a private address space, lets the OS use disk as overflow via page faults, and is the dividing line between a microcontroller (MPU) and a full computer (MMU).

🎯 Day 21 takeaways

Quick check

  1. Why does the offset within a page not need translating?
  2. What does the TLB cache, and what happens on a TLB miss?
  3. Name one useful thing a page fault lets the OS do.

FAQ

What is an MMU?

Hardware that translates virtual addresses to physical ones via page tables, giving each process a private address space.

What is the TLB?

A fast cache of recent virtual-to-physical translations; a miss triggers a page-table walk.

MMU vs MPU?

The MPU only protects fixed physical regions; the MMU also translates with fine-grained pages and per-process spaces.

Previous
← Day 20: The MPU

← Back to the full course roadmap