Back
Next
Selecting slots
In associative and set-associative, if no lines available a choice must
be made.
Choice algorithms.
Least Recently Used (LRU) - oldest access time.
Time stamped when accessed.
Similar to FIFO but timestamp refreshed if accessed.
First In First Out (FIFO) - oldest line replaced, Cached line time
stamped when first loaded into cache.
If line is needed
Time stamp for line in each cache is checked.
Oldest chosen.
FIFO and LRU can be implemented with minimal bit flags.
2-way uses 1 bit, 4 and 6-way uses 2 bits, 8-way uses 3 bits
Most recent read in(FIFO) or accessed(LRU) set to 0 and additional
ways incremented.
Selection done by IDing oldest slot.
Least Frequently Used (LFU or LU) - least used.
Needs larger flag/counter.
Tied condition possible, need second way to break tie.
May use flags similar to FIFO or LRU, but only way being accessed
is updated.
Bad case.
If program initialization code heavily used before main loaded,
it may read as most used and never get swapped out unless some
sort of 'stale' flaging also implemented.
Each technique requires additional storage on cache line for meta-data
and logic circuitry for evaluating it.
Non-cpu caches. See wikipedia : cache alogrithms.
Hard drive access - often highly associative. Tracks cached.
Software - Databases - blocks of data smaller than files but larger
than a line of memory processed by cpu. Because the rules of
locality are different, best algorithm may be different.
Virtual memory management - use of hard drive space to simulate
additional blocks of physical memory.