What is a TLB and what happens on a TLB miss?
Short answer: The TLB caches address translations. On a miss, hardware normally walks translation tables; a valid translation can refill the TLB. Invalid mappings or permission violations can cause a fault.
LDR X0, [X1] // translation performed if needed
1. TLB hit: The CPU finds a cached translation and permissions, avoiding a page-table walk.
2. TLB miss: The hardware walks translation tables in memory. If a valid entry is found, it can cache the translation and proceed. A TLB miss alone is not a page fault.
3. Page fault: A missing or forbidden mapping can trigger a synchronous exception. Linux handles legitimate demand paging or rejects illegal access.
| TLB | CPU data cache |
|---|---|
| Stores address translations | Stores memory contents |
| Avoids table walks | Avoids slower data accesses |
4. Context switches: Address Space Identifiers (ASIDs) help distinguish translations belonging to different processes. Kernel mapping changes may require TLB invalidation.
Interview takeaway: TLB miss means translation is not cached; page fault means the access cannot proceed with the current translation state.
A TLB miss with a valid mapping versus a page fault
Consider two successive accesses to VA 0x40001234 with a 4 KiB page. On the first access the TLB may lack a matching translation. Hardware walks the tables, finds the physical page base 0x80000000, checks attributes and proceeds to PA 0x80000234. The second access can reuse the translation. A page-table walk can itself hit CPU caches or dedicated walk caches rather than reading DRAM for every descriptor.
If the terminal descriptor is invalid, the CPU reports a translation fault; Linux checks whether the address belongs to a valid VMA and can install a mapping. If the address is outside a permitted region, a userspace access may instead result in SIGSEGV. Permission faults can also implement legitimate copy-on-write.
For a TLB with 64 entries, 4 KiB pages cover 256 KiB of distinct base-page mappings; larger mappings can increase reach. This simplified calculation ignores multiple TLB levels and replacement behavior.