The main reason for containing cache memory in a computer is to increase system performance by decreasing the time required to access memory. The component of cache performance are cache hits and cache misses.
Each time the CPU accesses memory, it determines the cache. If the requested data is in the cache, the CPU accesses the data in the cache, instead of physical memory, this is a cache hit. If the data is not in the cache, the CPU accesses the data from the main memory. This is a cache miss.
The average memory access time, TM is the weighted average of the cache access time, TC plus the access time for physical memory TP. The weighting factor is the hit ratio h. TM can be expressed as
Since TC is much less than TP, increasing the hit ratio reduces the average memory access time. The table shows for TC=10 ns,TP=60 ns, and various values of h.
Hit ratios and average memory access times
Consider that a computer system has an associative cache, a direct-mapped cache, or a two-way set-associative cache of 8 bytes. The CPU accesses the following locations in the order shown. The subscript for each value is the low-order 3 bits of its address in physical memory.
A0 B0 C2 A0 D1 B0 E4 F5 A0 C2 D1 B0 G3 C2 H7 I6 A0 B0
It can determine the hit ratio and average memory access times for this access pattern for each of the three cache configurations, assuming again that
TC=10 ns and
First, consider the associative cache. It is initially empty uses a FIFO replacement policy. The table shows the contents of the cache as each value is accessed. Seven out of the 18 accesses are hits, yielding a hit ratio of h = 0.389 and an average memory access time of
Cache activity using associative ache