Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1Learning Outcomes

2Placement Policy

A set is a group of blocks in the cache. A block is first mapped onto a set, and then the block can be placed anywhere within that set.

A cache is N-Way Set Associative if sets of N cache blocks are assigned a unique index. The associativity of a cache is therefore the number of slots (i.e., ways) assigned to each indexed set. Figure 1 is a 16-byte, 2-way set-associative cache with 4B blocks.

A 16-byte, 2-way set-associative cache with 4B blocks.

Figure 1:A 16-byte, 2-way set-associative cache with 4B blocks.

3Identification

Determining a cache hit in a set-associative cache works similarly to the process in direct-mapped caches, because the data can only be stored at one index. However, now the index has multiple slots (i.e., ways).

As an example, we can connect the 12-bit memory address in Figure 3 to the set-associative cache in Figure 4 (below).

"TODO"

Figure 3:For a set-associative cache, the memory address is split into three fields: the tag, the index, and the offset. For the cache in Figure 4, a 12-bit memory address is split into an 8-bit tag, a 2-bit index, and a 2-bit offset.

Notes:

4Replacement Policy

5Write Policy

6Walkthrough

The following animation traces through four memory accesses to a 12-bit address space on our 32B, 2-way set-associative cache with 4B blocks. Assume a write-back policy. Assume the cache starts out cold, like in Figure 4.

"TODO"

Figure 4:A cold snapshot of a 32B, 2-way set-associative cache with 4B blocks and a dirty bit for write-back.

(a)

"TODO"

(b)A (byte-addressed) memory address can be decomposed into a block address and a block offset. For direct-mapped caches and set-associative caches, the block address can be further divided into a tag and an index. Fully associative caches have no index field.

"TODO"

(c)The spectrum of cache placement policies, with set-associative as the in-between approach.

Contrast this set-associative cache walkthrough with the one for direct-mapped caches:

  • Identification of a cache hit occurs by checking M tags in an M-way set associative cache: each of the tags for the M blocks in the set.

  • Memory accesses 2 and 3 create cache entries in cache entries 3 and 2, respectively; these cache entries share the same tag. However, the blocks in these entries have different block addresses.

  • Memory access 4 did not incur a block replacement/memory write. Because there are two ways in a set, the existing block in the set with index 3 was not replaced. At the end of memory access 4, the set with index 3 is full.

7Associativity: A Discussion

We illustrate in Figure 5b the relationship between block address, tag, index, and offset.

Notes:

  • Fully associative caches have no index field; the block address is the tag.

  • In direct-mapped caches and set-associative caches, the index is the lower bits of the block address used to select the set.

  • The tag is compared against every block’s tag in the set.

  • The offset is the address of the desired data within the block.