4.1.9 · D3Computer Architecture (Deep)

Worked examples — Cache organization — direct-mapped, n-way set associative, fully associative

2,669 words12 min readBack to topic

This is a Deep Dive child of the parent Cache Organization note. There we derived the address split . Here we exercise it against every case a problem can throw at you — every organization, degenerate sizes, limiting values, a word problem, and an exam trick.

Before line one, let us re-anchor the five symbols we will use, in plain words and with the picture below.

Figure — Cache organization — direct-mapped, n-way set associative, fully associative

The scenario matrix

Every cache-organization problem is one cell of this grid. The worked examples below are tagged with the cell they cover, and together they fill every cell.

# Case class What makes it tricky Covered by
C1 Direct-mapped () most index bits, no replacement policy Ex 1
C2 -way set associative () index shrinks, tag grows Ex 2
C3 Fully associative () , no index bits at all Ex 3
C4 Degenerate: byte , no offset bits Ex 4
C5 Degenerate: whole cache = 1 block , both extremes collapse Ex 5
C6 Conflict vs capacity trace which miss type fires, and why Ex 6
C7 Limiting behaviour: tag/comparator cost as flexibility rises Ex 7
C8 Word problem (real-world) translate English → Ex 8
C9 Exam twist: given tag size, find run the derivation backwards Ex 9

Worked examples

Figure — Cache organization — direct-mapped, n-way set associative, fully associative

Recall

Recall (Ex 2 vs Ex 3) Two caches have the same size and block size; one is 4-way, one is fully associative. Which has the bigger tag and why?

Fully associative — it has fewer sets (just one, ), so more bits are pushed from index into tag. Fixed size means index and tag trade bits one-for-one.

Recall (Ex 6) In the

direct-mapped trace, name the miss type and the one-line reason. Conflict misses — the cache had empty slots, but the mapping rule forbade using them.

Recall (Ex 9) Given tag and address widths, what do you compute first to find

? The index bits: . Then , size, and .

Related: Cache replacement policies (LRU, FIFO, random) · Spatial and temporal locality · The 3 C's miss model · Memory hierarchy and AMAT · Virtual memory and TLBs · Write policies (write-through, write-back)