---
title: Directories and interconnection networks
heading: Directory-based coherence, its storage cost, message hops, and network topologies
eyebrow: S4 · Lesson 33 · Directories and interconnection networks
xp: 50
---

::: hook
Snooping needs every cache to see every miss, which a single bus can provide for a few dozen cores at most. Larger machines replace the broadcast with a directory: for every memory line, a home node records which caches hold it, so a miss sends messages only to the caches that matter. The messages travel over a network of point-to-point links, a mesh on a chip or a fat tree across a data center, and its shape decides how far a message must go and how much traffic can cross the machine at once. Directories trade broadcast bandwidth for storage and extra hops.
:::

::: play
- Network diameter, the most hops between any two nodes, against the number of nodes N, for a ring ($N/2$), a 2D mesh ($2(\sqrt N - 1)$), a 2D torus (about $\sqrt N$) and a hypercube ($\log_2N$).
- The ring is cheap but its diameter grows linearly; the mesh and torus fit flat chips; the hypercube grows slowly but needs $\log_2N$ links per node.
- The readouts give bisection width, the links cut when the machine is split in half, for M nodes: the bandwidth for traffic that crosses the middle.
:::
:::

```sim plot
view: graph
x: N = 4..4096 log
y: d = 1..2048 log
slider: M = 16..4096 = 64 log
plot: N/2 | samples: 300 | label: ring
plot: 2*(sqrt(N) - 1) | samples: 300 | color: ch2 | label: 2D mesh
plot: sqrt(N) | samples: 300 | dashed | color: ch3 | label: 2D torus
plot: log(N)/log(2) | samples: 300 | dashed | label: hypercube
readout: bisection links, mesh of M = sqrt(M)
readout: bisection links, torus of M = 2*sqrt(M)
readout: bisection links, hypercube of M = M/2
```

::: predict
## A full bit-vector directory keeps one presence bit per core for every 64-byte line. With 64 cores, how big is the directory compared to the data?

- [ ] 1.6%
- [x] 12.5%
- [ ] 64%
- [ ] 100%

::: reveal
12.5%: 64 bits for every 512 bits of data. With 1024 cores it would be 1024 bits per line, twice the data itself. Large machines therefore use **limited-pointer** directories (a few core numbers per line, overflowing to broadcast or software), coarse vectors (a bit per group of cores) or sparse directories that track only lines actually cached.
:::
:::

::: nameit
## Directory protocols

Each line has a **home node** holding its directory entry: a state (uncached, shared, exclusive) and a record of which caches hold it.

- **Read miss, line clean at home:** requester → home → requester: 2 messages.
- **Read miss, line modified in another cache:** requester → home → owner → requester (with a copy to home): 3 hops on the critical path.
- **Write miss to a shared line:** the home sends invalidations to each sharer and collects their acknowledgments.

Miss latency ≈ (critical-path messages) × (average hops × per-hop latency + per-message overhead).

## Directory storage

- **Full bit vector:** N bits per line, an overhead of $\frac{N}{8B}$ for B-byte lines.
- **Limited pointers:** p pointers of $\lceil\log_2N\rceil$ bits each.

## Interconnection networks

| Topology (N nodes) | Diameter | Bisection links | Links per node |
|---|---|---|---|
| ring | N/2 | 2 | 2 |
| 2D mesh, k × k | $2(k - 1)$ | k | up to 4 |
| 2D torus, k × k (k even) | k | 2k | 4 |
| hypercube | $\log_2N$ | N/2 | $\log_2N$ |

On a k × k mesh the average distance between two distinct nodes is $\frac{2k}{3}$ hops under uniform traffic. Bisection bandwidth = bisection links × link bandwidth caps all-to-all traffic.
:::

::: example
## Compare an 8 × 8 mesh and an 8 × 8 torus: diameter, bisection and (for the mesh) average distance. With 3 ns per hop, what's the critical-path latency of a 3-hop miss on the mesh at average distance, ignoring overheads?

::: solution
1. **Mesh.** Diameter 14, bisection 8 links, and average distance
   $$2 \times 8/3 = 5.33\ \text{hops}$$
2. **Torus.** Diameter 8, bisection 16 links.
3. **A 3-message miss on the mesh.** It crosses about
   $$3 \times 5.33 = 16\ \text{hops}$$
   which at 3 ns per hop is 48 ns before memory or cache access times.
4. **Why placement matters.** That's why placing data near the cores that use it matters on large chips.

**Answer:** the mesh has diameter 14, bisection 8 links and an average distance of 5.33 hops; the torus has diameter 8 and bisection 16; the miss's critical path is about 48 ns.
:::
:::

::: example
## A 1024-core machine with 64-byte lines: what does a full bit vector cost, and what do 4 limited pointers cost?

::: solution
1. **Full bit vector.** 1024 bits per 512-bit line:
   $$1024/512 = 200\%$$
   overhead.
2. **Four pointers.** Each is $\log_2 1024 = 10$ bits:
   $$4 \times 10 = 40\ \text{bits}$$
   which is 7.8% overhead.
3. **Overflow.** Lines shared by more than four caches overflow, which is rare for most data but common for widely read code and constants, so systems handle overflow with a broadcast or a coarser vector.

**Answer:** a full bit vector costs 200% of the line, and four limited pointers cost 40 bits, 7.8%.
:::
:::

::: example
## Compare a 64-node hypercube with an 8 × 8 mesh: diameter, bisection links and links per node.

::: solution
1. **Hypercube.** Diameter $\log_2 64 = 6$, bisection 32 links, and 6 links per node.
2. **Mesh.** Diameter 14, bisection 8 links, up to 4 links per node, and an average distance of
   $$2 \times 8/3 = 5.3\ \text{hops}$$
3. **Trade-off.** The hypercube has four times the bisection and much shorter paths, but its node degree grows with size, so large machines use meshes, tori or fat trees.

**Answer:** the hypercube has diameter 6, 32 bisection links and 6 links per node; the mesh has diameter 14, 8 bisection links and up to 4 links per node.
:::
:::

::: check
given: N = 16 | 64 | 256; B = 32 | 64 | 128
answer: 100*N/(8*B)
unit: %
tolerance: 0.5%

## A full bit-vector directory tracks {N} cores for {B}-byte lines. What's its storage overhead relative to the data?

::: right
Right. $N/8B$ = {answer}%.
:::

::: misses
- [100*N/B] Compare bits with bits: a B-byte line has 8B bits.
- [any] Not yet. Presence bits over data bits.
:::
:::

::: check
given: N = 256 | 1024 | 4096; p = 2 | 4 | 8
answer: p*ceil(log(N - 0.5)/log(2))
tolerance: 0

## A limited-pointer directory keeps {p} pointers per line for {N} cores. How many bits of pointers is that?

::: right
Right. $p\lceil\log_2N\rceil$ = {answer}.
:::

::: misses
- [N] Pointers name cores; they don't need a bit per core.
- [any] Not yet. Bits to name one core, times p.
:::
:::

::: check
given: k = 4 | 8 | 16
answer: 2*(k - 1)
tolerance: 0

## What's the diameter of a {k} × {k} mesh?

::: right
Right. $2(k - 1)$ = {answer} hops.
:::

::: misses
- [k] That's a torus; a mesh has no wraparound links.
- [any] Not yet. Corner to opposite corner.
:::
:::

::: check
given: k = 4 | 8 | 16
answer: 2*k/3
tolerance: 0.5%

## What's the average distance between two distinct nodes of a {k} × {k} mesh under uniform traffic?

::: right
Right. $2k/3$ = {answer} hops.
:::

::: misses
- [2*(k - 1)] That's the worst case.
- [any] Not yet. About a third of the way across in each dimension.
:::
:::

::: check
given: k = 4 | 8 | 16; b = 16 | 64
answer: 2*k*b
unit: GB/s
tolerance: 0.5%

## A {k} × {k} torus has links of {b} GB/s in each direction. What's its bisection bandwidth, counting one direction?

::: right
Right. 2k links × {b} GB/s = {answer} GB/s.
:::

::: misses
- [k*b] A torus's wraparound links double the bisection.
- [any] Not yet. Links cut by the bisection × link bandwidth.
:::
:::

::: check
given: m = 2 | 3 | 4; h = 3 | 6; t = 2 | 5; o = 10 | 20
answer: m*(h*t + o)
unit: ns
tolerance: 0.5%

## A directory miss has {m} messages on its critical path, each crossing {h} hops of {t} ns and paying {o} ns of overhead at the end. What's the network part of its latency?

::: right
Right. $m(ht + o)$ = {answer} ns.
:::

::: misses
- [m*h*t] Include the per-message overhead.
- [any] Not yet. Per message: hops × per-hop time + overhead.
:::
:::

::: check
kind: parts
given: k = 4 | 8 | 16

## Compare a {k} × {k} mesh and a {k} × {k} torus.

::: part
answer: 2*(k - 1)
unit: hops
tolerance: 0

### What is the mesh's diameter?

::: misses
- [any] $2(k - 1)$.
:::
:::

::: part
answer: 2*k/3
unit: hops
tolerance: 0.5%

### What is its average distance under uniform traffic?

::: misses
- [any] $2k/3$.
:::
:::

::: part
answer: 2*k
unit: links
tolerance: 0

### What is the torus's bisection?

::: misses
- [k] The wraparound links double it.
- [any] $2k$.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256 | 1024; B = 64 | 128; p = 2 | 4 | 8

## A directory serves {N} cores with {B}-byte lines.

::: part
answer: N/(8*B)*100
unit: %
tolerance: 0.5%

### What storage overhead does a full bit vector add?

::: misses
- [any] $N/(8B)$.
:::
:::

::: part
answer: p*ceil(log(N)/log(2) - 1e-9)
unit: bits
tolerance: 0

### How many bits do {p} limited pointers take?

::: misses
- [any] $p\lceil\log_2N\rceil$.
:::
:::
:::

::: check
kind: derivation
vars: m = 2..4, h = 1..20, t = 1..10, o = 1..30

## A miss's critical path has m messages, each crossing h hops at t per hop plus o of overhead.

::: step
answer: m*(h*t + o)

### What is its latency?
:::

::: right
Right. Three-hop misses on big meshes cost hundreds of nanoseconds, which is why NUMA placement matters.
:::
:::

::: explain
## Why do large multiprocessors use directories instead of snooping?

::: model
Snooping works by broadcasting every miss to every cache, so each cache must examine every other core's misses, and the shared medium must carry all of them. As cores are added, broadcast traffic grows with the number of cores times their miss rate, and the bus or broadcast network saturates. A directory records, for each line, which caches actually hold it, so a miss is sent only to the home node and to the few caches that need to supply data or be invalidated. Traffic then grows with the actual sharing instead of the machine size, and messages can travel over a scalable point-to-point network. The costs are the directory storage and an extra hop through the home node on many misses.
:::
:::

::: practice

::: check
given: N = 32 | 128; B = 64 | 128
answer: 100*N/(8*B)
unit: %
tolerance: 0.5%

## Bit-vector overhead: {N} cores, {B}-byte lines?

::: misses
- [any] $N/8B$.
:::
:::

::: check
given: k = 4 | 6 | 8 | 10 | 12 | 16
answer: 2*(k - 1)
tolerance: 0

## Diameter of a {k} × {k} mesh?

::: misses
- [any] $2(k - 1)$.
:::
:::

::: check
given: m = 2 | 3; h = 4 | 7; t = 2 | 4; o = 15 | 25
answer: m*(h*t + o)
unit: ns
tolerance: 0.5%

## Network latency: {m} messages, {h} hops of {t} ns, {o} ns overhead?

::: misses
- [any] $m(ht + o)$.
:::
:::
:::
