Sub topic 5
The TLB and Effective Access Time
Prerequisites and the Translation Path
This chapter assumes that you understand virtual addresses, pages, page frames, and basic memory access. A page table maps a virtual page number to a physical frame number. Address translation is the process of using that mapping.
A translation lookaside buffer (TLB) is a small, fast cache of recent page-table entries. The memory-management unit (MMU) checks the TLB before reading the page table.
The virtual address is divided into:
- A virtual page number, used for translation.
- An offset, copied unchanged into the physical address.
If the required mapping is in the TLB, the result is a TLB hit. Otherwise, the result is a TLB miss, and the MMU must read the page table.
Calculating Effective Access Time
Effective access time (EAT) is the average time required for one memory reference, including the time spent translating the address.
Use these symbols:
| Symbol | Meaning |
|---|---|
| \(h\) | TLB hit ratio |
| \(t_{TLB}\) | TLB lookup time |
| \(t_M\) | One main-memory access time |
Assume a single-level page table stored in main memory. Also assume that the TLB lookup happens before the memory access.
For a TLB hit:
\[ T{hit}=t{TLB}+t_M \]
The TLB supplies the frame number, so only the requested memory word must be read.
For a TLB miss:
\[ T{miss}=t{TLB}+tM+tM \]
One memory access reads the page-table entry, and another reads the requested data. Therefore:
\[ EAT=h(t{TLB}+tM)+(1-h)(t{TLB}+2tM) \]
For a 90% hit ratio, a 10 ns TLB lookup, and 100 ns memory access:
\[ EAT=0.9(10+100)+0.1(10+200) \]
\[ EAT=99+21=120\text{ ns} \]
The hit ratio is a probability, so use the miss ratio \(1-h\) for the miss term.
def eat(hit_ratio, tlb_time, memory_time):
# A TLB miss requires one page-table access and one data access.
return (
hit_ratio * (tlb_time + memory_time)
+ (1 - hit_ratio) * (tlb_time + 2 * memory_time)
)
print(eat(0.90, 10, 100)) # 120.0Common Errors
A frequent mistake is counting only one memory access after a TLB miss. In the single-level model, a miss needs both a page-table access and a data access.
Another mistake is using the hit ratio for both cases. If the hit ratio is \(h\), the miss ratio is \(1-h\).
Some problems state that TLB lookup and memory access overlap, or that the page-table entry is cached. In those cases, use the timing model stated by the problem instead of applying the formula mechanically. A page fault is also different from a TLB miss. A TLB miss can be handled using memory; a page fault requires fetching the page from secondary storage.
Exercise
The TLB lookup takes 20 ns, memory takes 80 ns, and the hit ratio is 95%. Assuming the single-level model, what is the EAT?
Show answer
The hit path is 20 + 80 = 100 ns. The miss path is 20 + 80 + 80 = 180 ns. EAT = 0.95(100) + 0.05(180) = 104 ns.