S420 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S4 · Lesson 20 · Multicore cache hierarchies

Inclusion, replacement policies, distributed last-level caches and partitioning

A multicore chip's last-level cache is shared by every core, split into slices spread across the chip, and managed by policies that decide which lines stay. Whether it duplicates what the private caches hold, how it picks victims, how far away the right slice is, and how its capacity is divided among competing programs together decide much of the chip's memory performance. LRU, the textbook policy, turns out to fail badly on common access patterns, and a slice at the far corner of the chip can take twice as long as one next door.

  • The curve is a working set's miss rate in a shared cache when it gets only a share of the capacity, by the √2 rule: m0S0/S for a program that misses m0 when it has the whole cache S0 to itself.
  • Each co-runner that takes an equal share raises the program's miss rate: four equal sharers double it.
  • Way partitioning gives each program a guaranteed share, so a cache-hungry neighbor can't push it further.

Predict

Eight cores each have a 1 MB private L2 in front of a 16 MB shared L3. How much distinct data can the hierarchy hold if the L3 is inclusive, and if it is exclusive?

Name it

Inclusion

  • Inclusive: every line in a private cache is also in the LLC. Snoops can check the LLC alone, but an LLC eviction must back-invalidate the private copies, and the effective capacity is just the LLC's.
  • Exclusive: a line lives in one level at a time; capacity adds, but lines move between levels on every miss.
  • Non-inclusive: neither guarantee; common in recent server chips, with a separate snoop filter.

Replacement

  • True LRU orders all W lines of a set: ⌈log2⁡W!⌉ bits per set. Tree pseudo-LRU approximates it with W − 1 bits.
  • LRU fails on scans and on cyclic working sets slightly larger than the cache: each line is evicted just before it's reused, and the hit rate drops to zero. LRU-insertion (placing new lines at the LRU end) keeps most of a cyclic set resident; RRIP keeps 2-bit re-reference predictions per line and adapts between the two.

Distributed last-level caches

The LLC is split into slices, often one per core, joined by an on-chip network; an address hashes to one slice. Latency = slice access + the round trip across the network, about 2hthop for h hops: non-uniform cache access (NUCA).

Sharing and partitioning

Co-running programs compete for capacity. Under the √2 rule, a program's miss rate with a share s of the cache is about m0/s. Way partitioning reserves ways per core or per class of service so one program can't evict another's working set.

Worked example

How much replacement state does a 16-way set need under true LRU, tree pseudo-LRU and 2-bit RRIP?

Show the solution
  1. True LRU. It must encode one of 16! orders: ⌈log2⁡16!⌉=⌈44.25⌉=45bits
  2. Tree pseudo-LRU. It uses 15 bits, one per node of a binary tree over the ways.
  3. 2-bit RRIP. It stores 2 bits per line: 16×2=32bits
  4. Across a whole cache. A 32 MB cache of 64-byte lines has 32 768 sets, so LRU would cost 180 KB of state against 60 KB for PLRU.

Answer 45 bits per set for true LRU, 15 for tree pseudo-LRU and 32 for 2-bit RRIP.

Worked example

An LLC is spread over a 4 × 4 mesh of slices, 10 cycles per slice access and 3 cycles per hop. What is the average access latency for a core's random address?

Show the solution
  1. Average distance. On a k × k mesh it's about 2k/3=2.7hops each way.
  2. Average latency. The request and the reply both cross it: t=10+2×83×3=26cycles
  3. Nearest and farthest. The nearest slice costs 10 cycles and the farthest 10+2×6×3=46cycles which is why systems map a thread's private data to nearby slices.

Answer a random address takes about 26 cycles on average.

Worked example

A program misses 2% of the time with a 16 MB cache to itself. What happens when it shares the cache equally with three other programs?

Show the solution
  1. Its share. Shared equally four ways, its share falls to 4 MB, a quarter of the cache.
  2. New miss rate. By the √2 rule, a quarter of the cache doubles the miss rate: 2%×16/4=4%
  3. Protecting it. If the other programs are streaming data they'll never reuse, partitioning them into a few ways protects it without hurting them.

Answer its miss rate doubles to about 4%.

Check

8 cores each have a 0.5 MB private L2; the shared L3 holds 32 MB.

(a)

How much distinct data fits if the L3 is inclusive?

(b)

And if it is exclusive?

Check

An 8 MB cache with 64-byte lines is 8-way set associative.

(a)

How many sets does it have?

(b)

How much tree-PLRU state does it need?

(c)

And 2-bit RRIP?

Check

An LLC is sliced over a 6 × 6 mesh; a slice takes 8 cycles and each hop 3.

(a)

What is the average latency to a random slice?

(b)

And to the farthest slice?

Check

A program misses 0.02 of the time with the whole LLC; it now shares the cache equally with 2 programs in all.

(a)

What miss rate does the √2 rule predict?

Check

An inclusive LLC evicts a line that a core is actively using in its L1. What happens, and why do some designs avoid inclusion?

Check

A W-way cache of S MB with 64-byte lines; a program that misses m with the whole cache gets a share s.

Step 1

How many lines does the cache hold?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write set_hits(pattern, ways, policy): simulate one cache set; policy 'lru' inserts misses at the most-recent end, 'lip' inserts them at the least-recent end (hits always move to the most-recent end, and the least-recent line is evicted). Return the hit rate.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does LRU replacement get zero hits on a loop over a working set slightly larger than the cache?

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.