Caches

What is a Cache?

A cache is a small amount of fast memory that is used to hold the data most frequently used by the processor. Since most programs exhibit locality of reference, caches can be effective in hiding the latency of memory accesses. Entries in a cache have two components. A tag which indicates which address is currently being cached in that particular cache entry and the data which is the value that the address contains. A memory reference checks the tags in the cache against the address of the reference. If a match is found then the data is returned, otherwise data gets fetched into the cache from main memory.

Important Issues in Cache Design

How is a cache-lookup done?

As is shown in the above figure, the low order bits are used to select a word within a multi-word cache line. For single-word cache lines no bits need be used for this operations. The next set of bits selects the cache entry (a set in the cache). The final set of bits is used to perform the tag-check against the tags in the set.

Although these operations are shown to operate using bits from the same address implementations can actually differ. For instance many caches use the virtual address for selecting the set and the word within a set (indexing), but the physical address for the tag checking (tagging). Possible combinations include a) virtually-indexed virtually-tagged caches, b) virtually-indexed physically-tagged caches, and c) physically0indexed physically-tagged caches. Virtually-tagged caches introduce the aliasing problem where two virtual address may point to the same physical address and thus should contain the same data. If both virtual addresses are cached writes to one need to be propagated to the other in order to maintain the cache consistent.