In this short note, we will discuss a recent cache design called a ZCache that performs well in reducing conflict misses. This is not a formal paper, but rather an expository note on the topic. Nothing of the discussions in original except perhaps the point of view. The main references we used are [1], [2] and [3] listed at the end of this note.
Cache is a fundamental concept in the memory hierarchy abstraction. In broad terms it is a storage device (e.g. SRAM) that is served as a staging area for slower memories (e.g. DRAM or hard disk). They are used to fill in the increasing gaps between CPU access speed and main memory and hard disk access speed. In this definition, the main memory (DRAM) can be thought of a cache for the hard disk, and register sets can be thought of as caches for main memory. In today’s computers, there are usually two to three additional levels of caches inserted in between the register sets and main memory, and they are denoted as L1, L2, and L3 caches, respectively. It is important to note that the data between the level
Now let’s focus on L1, L2 or possibly L3 caches for the main memory. There are four characteristics that describe a generic cache memory organization: number of bits in main memory address: , the number of sets of the cache:
, the number of cache lines each set contains:
, and the block size (in bytes) used as the atomic transfer unit:
. We thus can identify a cache with the tuple:
. We assume that
and
are both powers of
, and define
and
, thus a
-bit pattern corresponds to a set in the cache, and a
-bit pattern corresponds to the address of a byte in a block. The size of the cache equals to
.
The pair induces a partition on the address space of the main memory: we choose the least significant
bits as the block offset indicator, and the next
bits as the set identifier. Then we have
bits left at the most significant slots. Those are called the tag bits for that address. For each line in a set of a cache, we not only store the block of bytes, but also some header information including
bits from the tags in the base address of each block of data read in from main memory, as well as a one (flag) bit indicating whether the current line is valid or not. It is important to note that the flag bits uniquely identifies the multiple blocks that are mapped to the same cache set. Within a single block, the flag bits are the same for all the byte addresses in that block, thus it does not matter which byte we take the flag bits from, in particular we can say that it is from the base address.
Here is how cache works in storing data temporarily: given an address in main memory, since we transfer in block size, we are going to fetch
bytes containing
(to be more explicit, we fetch all the bytes with addresses having the same tag bits and set bits, and
block offset bits ranging from
to
).
has
bits: we use the middle
bits to determine which set of the cache will
be stored, and the least significant
bits to determine the address of the byte in the cache block will this byte pointed by
be placed. Note that the tag bits together with the set bits uniquely determine each block in main memory. Therefore in order to determine if a byte of data is present in the cache, we need to:
- 1. first check the set bits to locate the cache set that this byte should be in;
- 2. then check if the flag bit is set to valid and if the tag bits in the address of this byte matches with the tag bits stored in any of the caches lines within that set.
If we have passed this test, then we know that this byte must be present in the cache since we transfer data in block sized units. Hence what is left to do is to look at the offset bits to determine the address of this byte within the block. In this case we have a cache hit. If a query byte cannot be found within the cache, then we have a cache miss, in which case we have to go to the next level cache to get the block containing that data, replace (or evict) a block in the current cache with it, and return data (now lies in the cache) back to CPU. We won’t discuss any of the replacement policy in choosing the block to be evicted (called a victim block), and simply assume that we either follow the LRU (least recently used) or random policy.
We can classify the memory caches by the value , the number of cache lines within each cache set. In the case where
, it is called a direct mapped cache in which case a block in main memory can be mapped to a unique line within some cache set. In the case where
, it is called a
-way set-associative cache in which case a block in main memory can be mapped to any of the
cache lines within a cache set. In the case where
, or equivalently
, we have only one cache set and it is called a fully-associative cache. In this case a cache block can be mapped to any cache line in this cache.
Suppose we have an
In the case of a cache miss on the data with address , we see that it could end up in set
and
. Thus we get three candidate victim blocks to evict. We can evict one of the blocks according to certain replacement policy. In ZCache we will see a modification of the skew associative cache in terms of the eviction and replacement scheme.