220 likes | 407 Views
Cache Memory. By JIA HUANG. "Computer Science has only three ideas: cache, hash, trash.“ - Greg Ganger, CMU. The idea of using caching. Using very short time to access the recently and frequently data. cache: fast but expensive. disks: cheap but slow. Type of cache.
E N D
Cache Memory By JIA HUANG
"Computer Science has only three ideas: cache, hash, trash.“ - Greg Ganger, CMU
The idea of using caching • Using very short time to access the recently and frequently data cache: fast but expensive disks: cheap but slow
Type of cache • CPU cache • Disk cache • Other caches • Proxy web cache
Usage of caching • Caching is used widely in: • Storage systems • Databases • Web servers • Middleware • Processors • Operating systems • RAID controller • Many other applications
Cache Algorithms • Famous algorithms • LRU (Least Recently Used) • LFU (Least Frequently Used) • Not so Famous algorithms • LRU –K • 2Q • FIFO • others
LRU (Least Recently Used) • LRU is implemented by a linked list. • Discards the least recently used items first.
LFU (least frequently used) • Counts, how often an item is needed. Those that are used least often are discarded first.
LRU vs. LFU • The fundamental locality principle claims that if a process visits a location in the memory, it will probably revisit the location and its neighborhood soon • The advanced locality principle claims that the probability of revisiting will increased if the number of the visits is bigger
Disadvantages • LRU – problem with process scans a huge database • LFU – process scans a huge database, but it made the performance even worse.
New algorithm • ARC (Adaptive Replacement Cache) - itcombines the virtues of LRU and LFU, while avoiding vices of both. The basic idea behind ARC is to adaptively, dynamically and relentlessly balance between "recency" and "frequency" to achieve a high hit ratio. -Invented byIBM in 2003 ( Almaden Research Center, San Jose)
L1: pages were seenonce recently("recency") L2: pages were seen atleasttwice recently("frequency") If L1 contains exactly c pages --replace the LRU page in L1 else --replace the LRU page in L2. Lemma: The c most recent pages are in the union of L1 and L2. ARC LRU L2 MRU MRU L1 LRU
ARC LRU • Divide L1 into T1 (top) & B1 (bottom) • Divide L2 into T2 (top) & B2 (bottom) • T1 and T2 contain c pages • in cache and in directory • B1 and B2 contain c pages • in directory, but not in cache • If T1 contains more than p pages, --replace LRU page in T1, else --replace LRU page in T2. L2 MRU MRU L1 LRU
ARC • Adapt target size of T1 to an observed workload • A self-tuning algorithm: • hit in T1 or T2 : do nothing • hit in B1: increase target of T1 • hit in B2: decrease target of T1 L2"frequency" Midpoint L1"recency"
ARC • ARC has low space complexity. A realistic implementation had a total space overhead of less than 0.75%. • ARC has low time complexity; virtually identical to LRU. • ARC is self-tuning and adapts to different workloads and cache sizes. In particular, it gives very little cache space to sequential workloads, thus avoiding a key limitation of LRU. • ARC outperforms LRU for a wide range of workloads.
Example • For a huge, real-life workload generated by a large commercial search engine with a 4GB cache, ARC's hit ratio was dramatically better than that of LRU (40.44 percent vs. 27.62 percent). -IBM (Almaden Research Center)
ARC • Currently, ARC is a research prototype and will be available to customers via many of IBM's existing and future products.
References • http://en.wikipedia.org/wiki/Caching#Other_caches • http://www.cs.biu.ac.il/~wiseman/2os/2os/os2.pdf • http://www.almaden.ibm.com/StorageSystems/autonomic_storage/ARC/index.shtml • http://www.almaden.ibm.com/cs/people/dmodha/arc-fast.pdf