All problems
TLB Hit Ratio Simulation
Problem
Simulate a fully associative TLB with LRU replacement and count hits and misses.
pages is the sequence of page references and tlb_size is the number of TLB entries. A reference that is present is a hit and refreshes the entry's recency; otherwise it is a miss and the least recently used entry is evicted.
Return [hits, misses]. A non-positive TLB size misses on every reference.
Hint
Store TLB entries from least to most recently used and trim the front on a miss.
Test cases
case 1
in: [[1,2,3,1,2],3]
expected: [2,3]
case 2
in: [[1,1,1],1]
expected: [2,1]
case 3
in: [[1,2,3,4],2]
expected: [0,4]
case 4
in: [[],3]
expected: [0,0]
case 5
in: [[5],1]
expected: [0,1]
Starter codePython
def tlb_hit_misses(pages, tlb_size):
# Your code here
pass5 test cases · run your code against them in the editor