Computer Architecture Cheatsheet

Memory Hierarchy

Use this Computer Architecture reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

The Memory Hierarchy Principle

No single memory technology offers high speed, large capacity, and low cost simultaneously. The hierarchy exploits locality to give the illusion of both large and fast memory.

Speed ▲  Cost/bit ▲
      │
      │  Registers      ~300 ps    <1 KB   On-chip flip-flops
      │  L1 Cache       ~1 ns      3264 KB  On-chip SRAM
      │  L2 Cache       ~4 ns      256 KB–2 MB  On-chip SRAM
      │  L3 Cache       ~1040 ns  864 MB  On-die SRAM
      │  DRAM (main)    ~6080 ns  8256 GB  Off-chip
      │  NVMe SSD       ~100 µs    132 TB  PCIe attached
      │  HDD            ~10 ms     120 TB  Spinning disk
      │  Tape/Archive   ~sec–min   Unlimited
      ▼
Capacity ▲  Access time ▲

Locality

TypeDefinitionExample
Temporal localityA recently accessed location is likely to be accessed again soonLoop variable accessed each iteration
Spatial localityAccessing one location makes nearby locations likely to be accessed soonIterating an array sequentially

Cache design exploits both: temporal → keep recently used data in cache; spatial → fetch an entire cache line (block) at once (typically 64 bytes).

DRAM Basics

DRAM cell = 1 transistor + 1 capacitor. Charge on capacitor = 1, discharged = 0. Must be refreshed every ~64 ms or data is lost.

DRAM Timing Parameters

ParameterSymbolMeaningTypical (DDR5)
CAS LatencyCLCycles from column address to data40
RAS-to-CAS delaytRCDCycles to open a row40
Row PrechargetRPCycles to close a row40
Row Active TimetRASMin cycles a row stays open77
Data RateTransfers per second6400 MT/s

DDR Generations

GenVoltageTypical bandwidth per channel
DDR41.2 V25.6–51.2 GB/s
DDR51.1 V38.4–102.4 GB/s
LPDDR5 (mobile)1.05 Vup to 68 GB/s
HBM3 (GPU/HPC)up to 1+ TB/s

SRAM vs DRAM

PropertySRAMDRAM
Cell size6 transistors1T + 1C
Speed~1–5 ns~50–80 ns
DensityLowHigh
Refresh neededNoYes
Power (standby)Low (no refresh)Higher (refresh)
Cost/bitHighLow
UseRegisters, cachesMain memory

Storage Technologies

TechnologyWrite enduranceLatencyUse
SLC NAND flash~100 K P/E cyclesµs read, ms writePremium SSDs, enterprise
MLC NAND~10 K P/Eµs/msConsumer SSDs
TLC NAND~3 K P/Eµs/msBulk consumer SSDs
QLC NAND~1 K P/Eµs/msHigh-density, read-heavy
3D XPoint / Optane~millions~10 µs(Discontinued; was DRAM-like)
HDD (spinning)Unlimited writes~5–10 msBulk cold storage

Memory Interleaving

Multiple DRAM banks accessed in round-robin to overlap access latency and maximize bandwidth. With k banks, can sustain k simultaneous requests.

Memory Bandwidth vs Latency

  • Latency = time to first byte of a random access
  • Bandwidth = sustained bytes/second for sequential access

Sequential access saturates bandwidth; random access is latency-bound. Example (DDR5-6400 dual-channel): - Peak bandwidth: ~100 GB/s - Latency: ~70–80 ns for a random access

NUMA (Non-Uniform Memory Access)

In multi-socket systems, each CPU socket has its own local DRAM. Accessing another socket's memory crosses a high-latency interconnect (e.g., AMD Infinity Fabric, Intel UPI).

Access typeLatencyNotes
Local NUMA node~70 nsNormal DRAM latency
Remote NUMA node~120–200 nsCross-socket hop

OS NUMA-awareness: Linux numactl, CPU affinity scheduling, first-touch DRAM allocation policy.

Memory Coherence (Multi-Core)

When multiple cores each have their own L1/L2 caches holding copies of the same address, they must agree on the current value. The cache coherence protocol enforces this.

MESI Protocol States

StateMeaningCan read?Can write?Dirty?
M odifiedOnly copy; differs from memoryYesYesYes
E xclusiveOnly copy; matches memoryYesYes (silent → M)No
S haredMultiple clean copiesYesNo (must invalidate)No
I nvalidNot present or invalidatedNoNo

Transitions:

EventState change
Read miss (no other sharer)I → E
Read miss (other sharers exist)I → S
Write hit in EE → M
Write hit in S (send invalidations)S → M
Another core reads MM → S (writeback)
Another core writes to our SS → I

Memory System Performance Equations

Average Memory Access Time (AMAT):

AMAT = Hit time + Miss rate × Miss penalty

For a two-level hierarchy:

AMAT = L1 hit time + L1 miss rate × (L2 hit time + L2 miss rate × Memory time)

Example: - L1: 1 cycle, 5% miss rate - L2: 10 cycles, 2% miss rate - Memory: 200 cycles

AMAT = 1 + 0.05 × (10 + 0.02 × 200) = 1 + 0.05 × 14 = 1.7 cycles