Lecture 01 · Storage
The whole deck on two pages. Page numbers refer to lectures/Lecture_01_Storage.pdf.
Hierarchy
- Registers 1 cy · L1 ~4 · L2 ~10 · L3 ~30–60 · DRAM ~100–200 cy (~60 ns) · disk µs–ms p.6
- Units: word 4–8 B → cache line 64 B → page 4 KB → file p.10
- Caches are hardware-managed; memory ↔ storage is software-managed p.8
- Multi-socket: local memory faster than remote (NUMA, L03) p.15
- Purposes of storage: durability (sequential writes), memory extension (swap, LSM), data exchange between steps (S3, Kafka) p.16
- Storage matters when its latency is a big share of response time or its access rate caps throughput; test with a RamFS p.17
HDD vs SSD
| HDD | SSD (NVMe) | |
|---|---|---|
| Latency | 2–10 ms | 10–100s µs (NVMe <10 µs) |
| Bandwidth | 100s MB/s | several GB/s; PCIe4 ×4 ≈ 7, PCIe5 ×4 ≈ 14, PCIe6 ×4 ≈ 32 GB/s |
| Cost of access | seek + rotation + transfer | needs many outstanding requests (channels) |
| Quirks | placement on disk matters | erase-before-write, GC, write amplification ≥ 1, wear leveling, latency spikes |
| Price | $ | $$$ (gap closing) |
pp.19–25, 30
random n blocks = n(a + t) sequential n blocks = a + n·t a = seek + rotation Little's Law: queue depth = IOPS × latency (1 M IOPS × 10 µs = 10)Interfaces & software path
- AHCI/SATA: 1 queue × 32 commands, heavy OS involvement; fine for 100–200 IOPS HDDs p.27
- NVMe over PCIe: 64 K queues × 64 K commands; submission + completion queue pair in host memory; doorbell registers (MMIO); MSI-X interrupt per queue; one queue pair per core → lock-free p.29
- With µs devices, the kernel path (syscall, copies, interrupts, context switches) becomes the bottleneck → (1) async APIs, (2) kernel bypass p.31
- POSIX sync I/O (HDD) · libaio (async, buffers pinned per I/O) · io_uring (async, user-space buffers) · SPDK (user-space driver, no file system) p.32
- Apps can avoid FS overhead: own layout inside few big files (DBMS) or own the device (SPDK) — but then they duplicate OS features p.33
Beyond the local disk
- NVMe-oF: NVMe over RDMA/TCP → disaggregated flash pools (JBOF) p.35
- CXL: cache-coherent interconnect over PCIe PHY; Type-3 = memory expanders p.37
- ZNS: zones written sequentially, reset before rewrite → no in-zone GC, ~1× write amplification, predictable latency; FTL work moves to host p.38
- Computational storage: filter/scan/decompress in the device; KV-SSDs; pairs with Parquet predicate pushdown; caveat: lock-in, programmability p.39
File systems (OS view)
- Stack: syscall → VFS → EXT*/ZFS/NFS → buffer cache → drivers → disk p.43
- Why FS: disk management, naming, security, durability p.45
- Layout: boot block | superblock | free-block bitmap | inode table | file blocks pp.47–52
- Block size trade-off: big → wasted space on small files; small → too much metadata; 4 KB typical, 512 B min p.48
- Reads don’t always hit disk — the buffer cache in DRAM serves them p.53
Data formats
| CSV | Parquet | Arrow | |
|---|---|---|---|
| Kind | text, row lines | binary, columnar, pages | in-memory columnar |
| Metadata | none | rich | schema |
| Parse speed | 10s MB/s, hard to parallelise | >100s MB/s/core | no parsing |
| Focus | simplicity | compression, column access | access speed |
Parquet row group → column chunk → page; decode/decompress to Arrow. High-rate systems still burn much compute on Parquet parsing → Vortex, BtrBlocks pp.56–59
Exam-style questions from the deck p.61
- T/F: with flash, Linux retired the block device interface.
- 100 MB in 4 KB sequential pages: SATA-II HDD vs PCIe 5 ×4 SSD — how long? (worked in lesson 0001)
- T/F: io_uring allows async disk access with buffers in kernel space.
- Do apps need fundamentally different interfaces for local vs remote storage? Why / why not?