Handling TLB Miss
Handling TLB Miss
When a TLB miss occurs, the system must determine how to find the correct virtual → physical address translation.
There are two possible approaches:
-
Hardware-managed TLB
-
Software-managed TLB (OS-managed)
Let’s break both down clearly.
Hardware-Managed TLB
In this approach:
The hardware handles everything when a TLB miss occurs.
What Happens on a Miss?
-
Hardware detects TLB miss.
-
Hardware walks the page table in memory.
-
It finds the correct page-table entry (PTE).
-
It updates the TLB automatically.
-
It retries the instruction.
The operating system is not directly involved in handling the miss.
What Hardware Needs
To do this, hardware must know:
-
π Where the page table is stored
→ via a page-table base register -
π The exact format of the page table
-
π How to walk multi-level page tables
π Example Architecture
A classic example:
-
Intel x86 architecture
-
Uses hardware page-table walking
-
The current page table base is stored in the CR3 register
-
✅ Advantages
-
Faster miss handling (no OS trap overhead)
-
Transparent to OS during miss
❌ Disadvantages
-
Hardware complexity
-
Fixed page-table structure (less flexibility)
Software-Managed TLB
In modern RISC architectures, the approach is different.
The OS handles the TLB miss.
π Example Architectures
-
MIPS R10000
-
SPARC v9
These use software-managed TLBs.
What Happens on a Miss?
Instead of walking the page table, the hardware:
-
Raises a TLB_MISS exception
-
Switches to kernel mode
-
Jumps to a trap handler in the OS
Then:
-
The OS looks up the page table.
-
The OS inserts the translation into the TLB using privileged instructions.
-
The OS returns from the trap.
-
The instruction is retried — now resulting in a TLB hit.
⚠ Important Detail: Retrying the Instruction
This is subtle but crucial.
There are two types of traps:
| Type | Resume At |
|---|---|
| System call | Next instruction |
| TLB miss | Same instruction |
For a TLB miss:
The instruction must be re-executed.
Why?
Because the first attempt failed due to missing translation.After the TLB is updated, retrying will succeed.
Thus, hardware must save the correct PC depending on trap type.
Avoiding Infinite TLB Miss Loops
Here’s a tricky problem:
What if the TLB miss handler itself causes TLB misses?
That would create an infinite loop.
Solutions include:
-
π Keep TLB handler in physical memory (no translation needed)
-
π Reserve permanent “wired” TLB entries for the handler
-
π Ensure handler code always hits in TLB
⚖ Hardware vs Software TLB Management
| Feature | Hardware-Managed | Software-Managed |
|---|---|---|
| Who walks page table? | Hardware | OS |
| Hardware complexity | High | Lower |
| OS flexibility | Low | High |
| Page table format | Fixed | Flexible |
Why Software Management Is Attractive
✅ Flexibility
The OS can use:
-
Multi-level page tables
-
Inverted page tables
-
Hashed page tables
-
Any custom structure
No hardware redesign needed.
✅ Simpler Hardware
On a miss, hardware just:
The OS handles the rest.
Big Picture
When a TLB miss happens, someone must:
-
Find the correct page-table entry
-
Update the TLB
-
Retry the instruction
Depending on the architecture:
-
π₯ Hardware does it (e.g., Intel x86)
-
π§© OS does it (e.g., MIPS, SPARC)
Key Insight
Hardware-managed TLB → Faster, but rigid
Software-managed TLB → More flexible, simpler hardware
Modern system design often prefers:
Simpler hardware + smarter OS
Comments
Post a Comment