Project Translation LookAside Buffer ICS 143 B L
Project: Translation Look-Aside Buffer ICS 143 B L. Bic NOTE: This is an individual project—no groups are allowed ICS 143 B -- L. Bic 1
Assignment • implement a software emulation of a TLB • generate reference strings • study how TLB reduces number of main memory references ICS 143 B -- L. Bic 2
Organization of VM and TLB • assume both paging and segmentation (Sect. 8. 2. 3) • VM address is an integer, divided into s, p, w • TLB: ICS 143 B -- L. Bic 3
Organization of VM and TLB • implement TLB as an integer array: – TLB. LRU[], TLB. SP[] – frame number f is not needed – implement each s, p as a single integer • operations on TLB: – do for each s, p from a given RS: • search TLB. SP[] sequentially for a match • if not found, replace one entry with the current s, p using LRU information • if found, count as TLB hit • update LRU information ICS 143 B -- L. Bic 4
Organization of VM and TLB • LRU implementation – LRU field is a counter c – for any given sp: • when sp is found (TLB hit), set corresponding c=0 • increment c of all frames by 1 • when sp is not found (TLB miss), select entry with largest c for replacement ICS 143 B -- L. Bic 5
Performance evaluations • measure effectiveness of TLB: cost of VM access without TLB E= cost of VM access with TLB • disregards page faults (assume VM is resident) • disregard caching • cost w/o TLB: 3 main memory accesses (3 m) • cost w/ TLB: – fixed overhead for each VM access, cm – memory accesses: 1 m for each TLB hit, 3 m for each TLB miss – determine hit ratio h experimentally ICS 143 B -- L. Bic 6
Performance evaluations E= 3 m hm+(1–h)3 m+cm = 3 3– 2 h+c • determine best case and worst case (h=0, h=1, c=0, c=1) • determine best case and worst case for realistic c (e. g. , c=0. 1) • determine h using simulation for different RS types; compute and plot E ICS 143 B -- L. Bic 7
Performance evaluations • determine h for different RSs and TLB sizes hit_cnt=0; for (i=0; i<length_of_RS; i++) { read next element sp of RS; search for i such that TLB. SP[i]==sp; if (no such i exists) //TLB miss find i such that TLB. LRU[i] is max; TLB. SP[i]=sp; else hit_cnt++; TLB. LRU[i]=0; for (j=0; j<length_of_TLB; j++) if (j != i) TLB. LRU[j]++; } h = hit_cnt/length_of_RS; ICS 143 B -- L. Bic 8
Performance evaluations • variables to experiment with: – program locality • choose different parameters when generating RS – size n of TLB • minimum: n=0 (no TLB) • maximum: use observed h as a guide; when h approaches 1, increasing n further will not help – fixed cost overhead c of using TLB • determine and plot: – hit ratio h – effectiveness E ICS 143 B -- L. Bic 9
Generating reference strings (analogous to page replacement project) • no locality: pick random number in [0. . P-1] • typical behavior: – periods of stable WS – punctuated by transitions: WS grows rapidly, then settles into new stable size ICS 143 B -- L. Bic 10
Generating reference strings • model typical behavior: – locus of reference |-----|---------------------| 0 sp sp+e P-1 • stable period: – assume constant rate in one direction (1 step every m references) • transition: – generate new locus with probability t • locus defined by sp, e, m, t ICS 143 B -- L. Bic 11
Generating reference strings • Note: algorithm for generating RS is on page 498/499 (page replacement project) • for TLB project, pages are grouped into segments but we do not need to choose s and p separately; an integer sp in the range 0: P-1 represents a page ICS 143 B -- L. Bic 12
Generating reference strings • algorithm to generate RS: – select P, sp, e, m, t – repeat until RS generated: • pick m random numbers in [sp. . sp+e]; include in RS • generate random number 0 <= r <= 1; • if (r < t) generate new sp else increment sp (mod P) ICS 143 B -- L. Bic 13
Choosing simulation constants • P: size of VM (# pages) • e: size of working set (# pages) – P and e need to be chosen together: e<P, but: • if e is too close to P, working sets overlap after transitions • if e is too small, the program will rarely revisit previous locations (important for LRU to benefit) • suggestion: e varies from 2 to P/10, P=500 or 1000 • sp random number within [0. . P-1] ICS 143 B -- L. Bic 14
Choosing simulation constants • m: # of times a page is referenced – typically, m 100 (see page 267, fig 8 -13 b) • t: length of stable period – random number in [0. . 1]; typically, t<0. 1 (i. e. , thousands of instructions are executed between transitions) • length of RS: • must be large to make behavior statistically significant • suggestion: 100, 000 ICS 143 B -- L. Bic 15
Summary of tasks • develop simulation program • generate representative reference strings • run simulation program: – for each type of RS, • • vary TLB size n and overhead value c record hit ratio h compute corresponding effectiveness E plot h and E over TLB size for different c values ICS 143 B -- L. Bic 16
- Slides: 16