Prashanth L.A.
2023-09-12
How can we speed up address translation, and generally avoid the
extra memory reference that paging seems to require?
What hardware support is required? What OS involvement is needed?
Solution: Translation-lookaside buffer aka TLB
TLB is part of MMU
Better name for TLB: Address traslation cache
// extract VPN from the virtual address
VPN = (VirtualAddress & VPN_MASK) >> SHIFT
// check if the TLB holds the translation for this VPN
(Success, TlbEntry) = TLB_Lookup(VPN)
if (Success == True)
if (CanAccess(TlbEntry.ProtectBits) == True)
Offset = VirtualAddress & OFFSET_MASK
PhysAddr = (TlbEntry.PFN << SHIFT) | Offset
Register = AccessMemory(PhysAddr)
else
RaiseException(PROTECTION_FAULT)
else
// HW accesses PT to find the translation
PTEAddr = PTBR + (VPN * sizeof(PTE))
PTE = AccessMemory(PTEAddr)
if (PTE.Valid == False)
RaiseException(SEGMENTATION_FAULT)
else if (CanAccess(PTE.ProtectBits) == False)
RaiseException(PROTECTION_FAULT)
else
// If mem ref is valid and accessible, add it to TLB
TLB_Insert(VPN, PTE.PFN, PTE.ProtectBits)
RetryInstruction()
Misses: ? Hits: ?
TLB hit rate: ?
VPN | PFN | valid | prot |
---|---|---|---|
10 | 100 | 1 | rwx |
- | - | - | - |
10 | 170 | 1 | rwx |
- | - | - | - |
VPN | PFN | valid | prot | ASID |
---|---|---|---|---|
10 | 100 | 1 | rwx | 1 |
- | - | - | - | - |
10 | 170 | 1 | rwx | 2 |
- | - | - | - | - |