Translation Lookaside Buffer (TLB) in Operating Systems - Time & Space Complexity
When using a Translation Lookaside Buffer (TLB), it is important to understand how quickly address translations happen as the number of memory accesses grows.
We want to know how the time to translate virtual addresses changes as more memory accesses occur.
Analyze the time complexity of the following TLB lookup process.
for each memory_access in program:
if virtual_address in TLB:
use physical_address from TLB
else:
walk page table to find physical_address
update TLB with new entry
access memory at physical_address
This code checks if the virtual address is in the TLB. If yes, it uses the fast translation. If not, it walks the page table, which is slower, then updates the TLB.
Look at what repeats for each memory access.
- Primary operation: Checking if the virtual address is in the TLB (a fast lookup).
- How many times: Once per memory access.
- Occasionally, a slower page table walk happens when the address is not in the TLB.
As the number of memory accesses grows, most lookups hit the TLB, so the time per access stays fast.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 fast TLB checks, few slow page walks |
| 100 | About 100 fast TLB checks, few slow page walks |
| 1000 | About 1000 fast TLB checks, few slow page walks |
Pattern observation: Most operations stay fast and grow linearly with input size, with occasional slower steps.
Time Complexity: O(n)
This means the total time grows roughly in direct proportion to the number of memory accesses, thanks to the fast TLB lookups.
[X] Wrong: "Every memory access takes the same slow time because of page table walks."
[OK] Correct: Most accesses are fast because the TLB stores recent translations, avoiding slow page table walks.
Understanding how TLB affects memory access time shows you can think about how hardware and software work together to keep programs running efficiently.
"What if the TLB size was doubled? How would that affect the time complexity of address translation?"