Professional Documents
Culture Documents
07caching Cse130 Fa19 KV
07caching Cse130 Fa19 KV
Miller
Caching
Principles of Computer System Design
‣…
else if N < 0:
return 0
if bv[N] == 0:
❖ Solution: Memoize! bv[N] = b(N-1) + b(N-2)
return bv[N]
Caching is everywhere
w(t)
❖ Working set is the set of items used by the k most recent actions
‣ w(t) is the size, usually much much smaller than the total number of items!
❖ If you can cache the whole working set, you win!
❖ But, how do you know what is in the working set???
Caching Terms
❖ Write-Back: Writes occur only on cached data
❖ Write-Through: Writes occur on both cache and back-end
❖ Associativity: Which data can be stored in each cache slot?
‣ Fully Associative: each item can be stored anywhere
‣ Direct-mapped: each item can be stored in only one location
‣ N-way associative: each item can be stored in n locations
❖ Mechanism: The algorithms and structures used
‣ Namely: how do you map from virtual pages to physical pages?
❖ Policy: The decision of what action to perform
‣ Namely: how do you pick the “right” pages to keep in memory?
CSE 130: Principles of Computer System Design 7
© 2019 Ethan L. Miller
Page Fault
❖ Read new page from disk and place it in old pages’s slot
‣ Update structures that keep track of virtual memory
‣ Careful: there’s tricky atomicity issues here
❖ Removal policy: when are values removed?
‣ In this case: on-demand (only remove when necessary)
‣ But, which values should be removed?
referenced unreferenced
A B C D E F G H A
t=0 t=4 t=8 t=15 t=21 t=22 t=29 t=30 t=32
Clock algorithm
❖ Same functionality as second
A
chance t=32
t=0
H B
❖ Simpler implementation t=30 t=32
t=4
Example Simulation
❖ Reference String: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
❖ Simulate a FIFO cache with 3 pages and with 4 pages.