5. Memory Technologies, Optimization and Dependability
Description
Different storage technologies trade speed, density, cost, volatility and endurance:
| Technology | Cell | Volatile? | Typical latency (order of magnitude) | Use |
|---|---|---|---|---|
| SRAM | 6 transistors (flip-flop) | Yes | ~1 ns (a few cycles) | Registers, L1-L3 caches, TLBs |
| DRAM | 1 transistor + 1 capacitor | Yes (refresh needed) | ~50-100 ns | Main memory (DDR4/DDR5) |
| HBM | Stacked DRAM on interposer | Yes | DRAM-class, huge bandwidth | GPUs, accelerators |
| Flash (NAND) | Floating-gate cell | No | tens of µs | SSDs, phones |
| HDD | Spinning magnetic disk | No | milliseconds | Cheap bulk storage |
SRAM vs DRAM:
| Feature | SRAM | DRAM |
|---|---|---|
| Cell | 6 transistors, no refresh | 1 transistor + 1 capacitor, refresh required |
| Speed | Very fast, predictable timing | Slower, more complex timing |
| Density / cost | Low density, high cost per bit | High density, low cost per bit |
| Power | No refresh, higher static power per cell | Refresh overhead, dynamic power |
| Typical use | CPU caches | System memory |
DRAM basics: the array is organized in banks of rows and columns. A read activates a row into the row buffer (RAS), then selects columns (CAS). Capacitors leak, so every row must be refreshed (typically every ~64 ms). DDR transfers data on both clock edges. HBM stacks DRAM dies and connects them with a very wide interface for bandwidth.
Flash is non-volatile and fast but cells wear out after limited write/erase cycles, so controllers use wear leveling (spread writes evenly) and error correction.
Memory optimizations (main memory level): multiple banks and interleaving, open-row (page) policy to exploit the row buffer, prefetching, write buffering, and wider/faster interfaces (DDR generations, HBM).
Dependability:
- Soft errors: transient bit flips (cosmic rays, noise); corrected, no permanent damage.
- Hard errors: permanent defects.
- ECC (error-correcting code) memory detects and corrects errors; SECDED = single-error correct, double-error detect.
- ChipKill survives the failure of an entire DRAM chip (multi-bit protection).
- RAID adds redundancy across disks for fault tolerance and performance.
- Scrubbing periodically reads and corrects memory to stop errors accumulating.
Key Formulas
Peak DRAM bandwidth = transfer rate (MT/s) × bus width (bytes)
Hamming bound (single-error correct): 2^r ≥ m + r + 1 (m data bits, r check bits)
SECDED check bits = r + 1
Availability = MTTF / (MTTF + MTTR)
Annual failure rate (AFR) ≈ 8760 h / MTTF
Interleaved access time (n banks) ≈ T_access + (n − 1) · T_bus
Steps
DRAM bandwidth: (1) read the transfer rate (MT/s), (2) multiply by bus width in bytes, (3) multiply by number of channels.
Check bits for ECC: (1) pick m data bits, (2) find the smallest r with 2^r ≥ m + r + 1, (3) add 1 parity bit for double-error detection.
Hamming (7,4) single-bit correction: (1) place check bits at positions 1, 2, 4, (2) compute even-parity bits over the position groups, (3) on receipt recompute the syndrome; its value is the position of the flipped bit.
Worked Example
A. DDR4-3200. 3200 MT/s × 8 B = 25.6 GB/s per 64-bit channel; dual channel = 51.2 GB/s.
B. HBM2. 1024-bit interface × 2 Gb/s per pin ÷ 8 = 256 GB/s per stack; four stacks ≈ 1 TB/s.
C. ECC overhead. 64 data bits: need r with 2^r ≥ 64 + r + 1 → r = 7 (128 ≥ 72). Add 1 for double detection → 8 check bits, a (72, 64) code, overhead 8/64 = 12.5%.
D. Hamming (7,4). Data d1..d4 = 1 0 1 1. p1 = d1⊕d2⊕d4 = 0; p2 = d1⊕d3⊕d4 = 1; p4 = d2⊕d3⊕d4 = 0. Codeword (positions 1-7) = 0 1 1 0 0 1 1. Suppose bit 6 flips → 0 1 1 0 0 0 1. Syndrome: s1 (positions 1,3,5,7) = 0; s2 (2,3,6,7) = 1; s4 (4,5,6,7) = 1 → s4 s2 s1 = 110 = 6. Flip position 6 back.
E. Disk reliability. MTTF = 1,000,000 h → AFR ≈ 8760/10⁶ ≈ 0.88%. A farm of 1000 disks expects about 8.8 failures per year. With MTTR = 24 h, availability = 10⁶/(10⁶ + 24) ≈ 99.9976% per disk.
F. Interleaving. Four words, each bank access 40 ns, bus transfer 10 ns. Single bank, sequential: 4 × 40 = 160 ns. Four-way interleaved: 40 + 3 × 10 = 70 ns.
Python / Assembly
def encode74(d1, d2, d3, d4):
p1 = d1 ^ d2 ^ d4
p2 = d1 ^ d3 ^ d4
p4 = d2 ^ d3 ^ d4
return [p1, p2, d1, p4, d2, d3, d4] # positions 1..7
def correct74(c):
s1 = c[0] ^ c[2] ^ c[4] ^ c[6]
s2 = c[1] ^ c[2] ^ c[5] ^ c[6]
s4 = c[3] ^ c[4] ^ c[5] ^ c[6]
pos = s4 * 4 + s2 * 2 + s1 # 0 means no error
if pos:
c[pos - 1] ^= 1
return c, pos
word = encode74(1, 0, 1, 1) # [0,1,1,0,0,1,1]
word[5] ^= 1 # flip position 6
print(correct74(word)) # ([0,1,1,0,0,1,1], 6)
def ddr_bandwidth_gbs(mt_s, bus_bits=64, channels=1):
return mt_s * (bus_bits / 8) * channels / 1000
print(ddr_bandwidth_gbs(3200)) # 25.6
Non-temporal stores bypass the cache for streaming writes (x86-64 AVX):
vmovntdq [rdi], ymm0 # streaming store: avoids polluting the cache
Notes
- DRAM must be refreshed; SRAM does not. That is why DRAM latency and power have extra terms.
- Flash is limited by write cycles, not read cycles. HDDs are slow because of mechanical seek and rotation but remain the cheapest per terabyte.
- Hard-error handling often means retiring bad pages or spare rows, not just ECC.
- Hybrid systems combine all layers (DRAM cache + SSD + HDD) for cost-performance.
- Quick facts: prefetching loads data into cache before it is requested; interleaving accesses multiple banks simultaneously; write-back reduces memory writes; wear leveling prolongs flash life; RAID provides fault tolerance.
References: [HP6] Ch. 2 (2.1-2.2, 2.6), Appendix D (storage, in editions that include it) and Ch. 1 (1.7 dependability); [PH-RV] Ch. 5 (5.2, 5.5); Hamming, "Error Detecting and Error Correcting Codes," Bell System Technical Journal, 1950;
All rights remain with the original author (Algo-holics). Publishing here does not grant a license to copy or reuse this text. Copyright & license. If you noticed a mistake or copyright issues, please contact: lebroskiofficial@proton.me