Module 10 — Memory Management Unit (MMU)
Learning Objectives
After completing this module, you will understand:
- Why an MMU is required
- Virtual Memory
- Physical Memory
- Virtual Address
- Physical Address
- Address Translation
- Memory Protection
- Process Isolation
- Page Tables
- TLB (Introduction)
- Linux Memory Layout
- ARM MMU
- Embedded Systems with and without MMU
1. Why Do We Need an MMU?
Let's begin with a problem.
Suppose RAM is8 GB
Two programs start.
Program A
int a = 10;
Compiler generatesAddress = 0x1000
Program B
int x = 20;
Compiler also generatesAddress = 0x1000
Problem
Both programs use0x1000
Who owns that memory?
Without an MMU,
both would overwrite each other.
System crashes.
Without MMU
No protection.
With MMU
Program A sees0x1000
Program B also sees0x1000
But
Internally
MMU translates them.
Both programs think they own address 0x1000, but they actually use different physical memory.
Real-Life Analogy
Imagine an apartment building.
Every apartment has aKitchen
- Apartment 101 Kitchen
- Apartment 102 Kitchen
- Apartment 103 Kitchen
Every apartment calls it"Kitchen"
But physically
they're different rooms.
The MMU performs this mapping.
2. What is the MMU?
The MMU is dedicated hardware inside (or tightly integrated with) the CPU.
Responsibilities:
- Virtual → Physical address translation
- Memory protection
- Access permission checking
- Page table walking (or assisting with it)
- Cache/TLB interaction
Diagram
The CPU generally works with virtual addresses. The MMU translates them before memory is accessed.
3. Virtual Address
A Virtual Address is
the address used by a program.
Example
int a = 10;
Debugger&a0x1000
This is not necessarily the real RAM location.
It is virtual.
Physical Address
The actual location in RAM.
Example
CPU never exposes raw physical memory directly to user programs.
Visualization
4. Address Translation
Suppose CPU executes
x = y + z;
NeedsVirtual Address 0x400100
MMU checks translation
RAM access0xA300100
CPU receives the data.
This translation happens automatically on every memory access in systems with an MMU.
5. Why Virtual Memory?
Suppose
Computer16 GB RAM
Process A
Needs4 GB
Process B
Needs4 GB
Process C
Needs2 GB
Every process wants memory beginning at0x00000000
The MMU makes this possible.
Program A
Program B
Same virtual address.
Different physical memory.
6. Process Isolation
One of the biggest advantages.
Suppose
Chrome crashes.
Without MMU
With MMU
Every process has its own address space.
Diagram
Completely isolated.
7. Memory Protection
Suppose
Program tries
*(0x00000000)=10;
MMU checks permissions.
This prevents applications from corrupting the OS or other processes.
8. Read / Write / Execute Permissions
Each memory region can have permissions.
Example
- Read
- Write
- Execute
Examples
| Memory | Permissions |
|---|---|
| Code | Read + Execute |
| Data | Read + Write |
| Stack | Read + Write |
| Kernel Code | Kernel only |
This supports security features such as preventing execution from writable data pages.
9. Linux Process Memory Layout
Typical process
We'll study this in much more detail during the virtual memory module.
10. Embedded Systems Without MMU
Many microcontrollers
do not have an MMU.
Example
ARM Cortex-M
Memory
Application accesses
physical addresses directly.
Advantages
- Simple
- Fast
- Low cost
- Deterministic timing
Disadvantages
- No virtual memory
- No process isolation
- Limited memory protection (though many Cortex-M devices include an MPU)
11. Embedded Systems With MMU
Application processors
ARM Cortex-A
Linux
Android
QNX
Windows
Need
MMU
Because
- Multiple processes
- Virtual memory
- Shared libraries
- Paging
- Memory protection
12. ARM Example
The CPU accesses physical memory only after translation.
13. Context Switching
The operating system switches the active page tables (or their root pointer) during a context switch so the MMU translates addresses for the correct process.
We'll revisit this in detail when studying page tables.
14. ADAS Example
The driver may work with physical addresses for DMA, while user-space applications typically use virtual addresses mapped by the kernel.
Why Operating Systems Need MMU
Without MMU
No
- Linux
- Windows
- Android
- macOS
- Process isolation
- Virtual memory
- Shared libraries
- Memory protection
- Demand paging
The MMU is one of the fundamental hardware features that enables modern multitasking operating systems.
Interview Questions
Beginner
- What is the MMU?
- Why do we need virtual memory?
- Difference between virtual and physical addresses?
- What is address translation?
Intermediate
- Explain process isolation.
- Explain memory protection.
- Why does every process think it starts at address 0?
- Why can't one process access another's memory?
Senior
- Explain how the MMU translates addresses.
- Why is the MMU required for Linux?
- How does the OS switch between process address spaces?
- Why do many microcontrollers not include an MMU?
- Compare Cortex-M and Cortex-A memory management.
Common Mistakes
- ❌ Thinking virtual addresses are stored in RAM. RAM stores data; virtual addresses are part of the CPU's memory access mechanism.
- ❌ Assuming the MMU allocates memory. The operating system allocates memory; the MMU translates addresses and enforces permissions.
- ❌ Believing physical addresses are visible to user applications. Normally they are not.
- ❌ Thinking the MMU is optional for desktop operating systems. Modern desktop operating systems fundamentally depend on it.
Summary
The Memory Management Unit is specialized hardware that translates virtual addresses into physical addresses while enforcing memory protection. It enables every process to have its own private address space, preventing interference between programs and forming the foundation of modern operating systems such as Linux, Windows, Android, and macOS.
Mini Quiz
- Why do computers need an MMU?
- What is the difference between a virtual address and a physical address?
- How can two processes both use address 0x1000 safely?
- How does the MMU provide process isolation?
- Why does writing to an invalid address often produce a segmentation fault?
- Why do Cortex-M microcontrollers typically operate without an MMU?
- Why do Cortex-A processors require an MMU?
Concept Mastery Assessment — Module 10
Verify your conceptual understanding with 12 targeted technical assessment questions. Instant feedback and explanations are provided for every choice.