---
title: Problem set 11
heading: "Problem set 11: virtual memory, DRAM and buses"
eyebrow: C8 · Problem set 11
type: problems
---

::: hook
These problems use lessons 47 to 51: virtual memory and TLBs, DRAM timing and bandwidth, buses and wait states, and the cache and memory lab. Addresses are 32 bits unless a problem says otherwise.
:::

::: pool
pick: 12

::: check
kind: parts
given: R = 2400 | 3200 | 4800; w = 64 | 128; L = 64 | 128

## A memory interface makes {R} million transfers a second over {w} bits.

::: part
answer: R*w/8/1000
unit: GB/s
tolerance: 0.5%

### What is its peak bandwidth?

::: misses
- [R*w/1000] That's gigabits per second.
- [any] Transfers per second × bytes per transfer.
:::
:::

::: part
answer: L/(w/8)/R*1000
unit: ns
tolerance: 0.5%

### How long does a {L}-byte line take to stream out?

::: misses
- [any] Transfers needed ÷ transfer rate.
:::
:::
:::

::: check
kind: parts
given: t = 12.5 | 13.75 | 15; h = 30 | 50 | 70; e = 10 | 20

## DRAM timings are CL = tRCD = tRP = {t} ns. {h}% of accesses hit an open row, {e}% go to an idle bank, and the rest are row conflicts.

::: part
answer: h/100*t + e/100*2*t + (1 - h/100 - e/100)*3*t
unit: ns
tolerance: 0.5%

### What is the average time to first data?

::: misses
- [any] Hit: CL. Idle: tRCD + CL. Conflict: all three.
:::
:::

::: part
answer: 3*t
unit: ns
tolerance: 0.5%

### What does a conflict cost?

::: misses
- [any] Precharge, activate, read.
:::
:::
:::

::: check
kind: parts
given: a = 24 | 35 | 50; f = 64 | 100 | 168

## Flash takes {a} ns per read on a {f} MHz core.

::: part
answer: ceil(a*f/1000) - 1
tolerance: 0

### How many wait states does it need?

::: misses
- [ceil(a*f/1000)] Wait states are the cycles beyond the first.
- [any] Cycles per read, less one.
:::
:::

::: part
answer: ceil(a*f/1000)
tolerance: 0

### Without a prefetch buffer, how many cycles does each instruction fetch take?

::: misses
- [any] The whole read.
:::
:::
:::

::: check
kind: parts
given: B = 10 | 25.6 | 50; T = 60 | 90 | 120; L = 64 | 128

## A channel gives {B} GB/s with {T} ns of latency, moving {L}-byte lines.

::: part
answer: B*T/L
tolerance: 0.5%

### How many misses must be in flight to use it fully?

::: misses
- [any] $BT/L$.
:::
:::

::: part
answer: L/T
unit: GB/s
tolerance: 0.5%

### What bandwidth does one miss at a time get?

::: misses
- [any] One line per latency.
:::
:::
:::

::: check
kind: parts
given: N = 64 | 256; M = 4 | 10 | 16; T = 80 | 100

## A loop has {N} independent cache misses of {T} ns each; the core can have {M} outstanding at once.

::: part
answer: ceil(N/M)*T
unit: ns
tolerance: 0.5%

### About how long do they take?

::: misses
- [N*T] They overlap, {M} at a time.
- [any] Rounds of {M}, each {T} ns.
:::
:::

::: part
answer: N*T
unit: ns
tolerance: 0.5%

### And one at a time, as in pointer chasing?

::: misses
- [any] Each waits for the last.
:::
:::
:::

::: check
kind: parts
given: E = 32 | 64 | 1536; p = 4 | 16

## A TLB has {E} entries and pages are {p} KiB.

::: part
answer: E*p
unit: KiB
tolerance: 0

### What is its reach, the memory it can map at once?

::: misses
- [any] Entries × page size.
:::
:::

::: part
answer: E*2048
unit: KiB
tolerance: 0

### And with 2 MiB huge pages?

::: misses
- [any] Entries × 2048 KiB.
:::
:::
:::

::: check
kind: parts
given: f = 1 | 10 | 100; T = 5 | 8

## Memory takes 100 ns; a page fault takes {T} ms to service. {f} accesses in a million fault.

::: part
answer: (1 - f*1e-6)*100 + f*1e-6*T*1e6
unit: ns
tolerance: 0.5%

### What is the effective access time?

::: misses
- [any] Weight the normal and faulting accesses.
:::
:::

::: part
answer: 10/(T*1e6 - 100)*1e6
tolerance: 0.5%

### At most how many faults per million accesses keep the slowdown under 10%?

::: misses
- [any] The faults may add only 10 ns on average.
:::
:::
:::

::: check
kind: parts
given: c = 4 | 12 | 20; s = 1 | 2

## A process on a 32-bit machine with 4 KiB pages and a two-level table (10, 10, 12 bits, 4-byte entries) has {c} MiB of code and data from address 0, and {s} page(s) of stack at the top.

::: part
answer: 1 + ceil(c/4) + 1
tolerance: 0

### How many page-table pages does it need?

::: misses
- [any] The root, one second-level table per 4 MiB of code, and one for the stack.
:::
:::

::: part
answer: 4*(1 + ceil(c/4) + 1)
unit: KiB
tolerance: 0

### How much memory is that?

::: misses
- [any] 4 KiB per table.
:::
:::
:::

::: check
kind: parts
given: v = 32 | 36 | 39; p = 12 | 14 | 16

## A virtual address has {v} bits, and pages are $2^p$ bytes with p = {p}.

::: part
answer: 2^(v - p)
tolerance: 0

### How many virtual pages are there?

::: misses
- [any] $2^{v - p}$.
:::
:::

::: part
answer: 2^(v - p)*8/2^20
unit: MiB
tolerance: 0.5%

### How big would a flat table of 8-byte entries be?

::: misses
- [any] Pages × 8 bytes.
:::
:::
:::

::: check
kind: parts
given: V = 4210220 | 1060864 | 3145935; P = 498 | 4096 | 81

## Virtual address {V:hex8} is in a page mapped to physical page number {P}, with 4 KiB pages.

::: part
answer: V - 4096*floor(V/4096)
tolerance: 0
base: 16
width: 3

### What is the page offset?

::: misses
- [any] The low 12 bits.
:::
:::

::: part
answer: P*4096 + V - 4096*floor(V/4096)
tolerance: 0
base: 16
width: 8

### What is the physical address?

::: misses
- [any] PPN × 4096 + offset.
:::
:::
:::

::: check
kind: parts
given: R = 64 | 128 | 256; C = 4 | 8

## A direct-mapped {C} KiB cache with 64-byte lines holds an R × R int matrix, R = {R}, summed by columns.

::: part
answer: C*1024/(4*R)
tolerance: 0

### How many different sets does one column use?

::: misses
- [any] Rows are {R} · 4 bytes apart, so a column cycles through the cache every C/(4R) rows.
:::
:::

::: part
answer: 4*R*R/(C*1024)
tolerance: 0

### How many rows share each of those sets?

::: misses
- [any] {R} rows over those sets.
:::
:::
:::

::: check
kind: parts
given: r = 2048 | 8192; a = 32 | 64

## A program streams through memory in {a}-byte accesses; DRAM rows are {r} bytes, and nothing else uses the bank.

::: part
answer: (1 - a/r)*100
unit: %
tolerance: 0.5%

### What fraction of accesses hit the open row?

::: misses
- [any] Only the first access in each row misses.
:::
:::

::: part
answer: r/a
tolerance: 0

### How many accesses are made per row?

::: misses
- [any] Row size ÷ access size.
:::
:::
:::

::: check
kind: parts
given: D = 20 | 50 | 120; C = 200 | 400

## A DMA stream moves {D} MB/s over a bus that carries {C} MB/s.

::: part
answer: D/C*100
unit: %
tolerance: 0.5%

### What share of the bus does it use?

::: misses
- [any] $D/C$.
:::
:::

::: part
answer: C - D
unit: MB/s
tolerance: 0.5%

### How much is left for the processor?

::: misses
- [any] The rest.
:::
:::
:::

::: check
kind: parts
given: w = 1 | 2 | 3; k = 5 | 8

## A flash interface fetches 128 bits (four instructions) per read, with {w} wait state(s). Taken branches, one every {k} instructions, flush the prefetch buffer.

::: part
answer: w + 1
tolerance: 0

### How many cycles does one flash read take?

::: misses
- [any] One plus the wait states.
:::
:::

::: part
answer: 1 + w/k
tolerance: 0.5%

### What is the CPI, if each taken branch stalls for the wait states and straight-line code runs at one a cycle?

::: misses
- [any] $1 + w/k$.
:::
:::
:::

::: check
kind: parts
given: n = 8 | 16 | 32 | 50 | 64 | 100 | 128

## Two streams in the same DRAM bank alternate accesses, each {n} accesses long; their rows differ. Timings are CL = tRCD = tRP = 14 ns.

::: part
answer: 0
tolerance: 0

### How many accesses hit an open row?

::: misses
- [any] Each access closes the other stream's row.
:::
:::

::: part
answer: 2*n*3*14
unit: ns
tolerance: 0.5%

### How long do the accesses wait for data in all?

::: misses
- [any] Every one is a row conflict.
:::
:::
:::
:::
