Skip to main content

The Memory & Storage Hierarchy

Modern computer systems are governed by a fundamental physical constraint: signals cannot travel faster than the speed of light in silicon (โ‰ˆ15ย cm/ns\approx 15\text{ cm/ns}). As a result, the closer storage media is to the execution ALU, the faster and more expensive it becomes.

Mechanical Sympathy

Software performance at scale depends on understanding how data flows through physical caches, memory controllers, and PCIe lanes. Code that thrashes cache lines or triggers random disk seeks will be orders of magnitude slower than code aligned with hardware topologies.


The Physical Hierarchyโ€‹

graph TD
subgraph On-Die CPU
A["CPU Registers<br/>(~0.5 ns, 1-2 KB)"]
B["L1 Instruction / Data Cache<br/>(~1 ns, 32-64 KB/core)"]
C["L2 Unified Cache<br/>(~3-7 ns, 512KB-1MB/core)"]
D["L3 Shared Cache<br/>(~15-25 ns, 32-128 MB)"]
end
subgraph Memory Subsystem
E["Main Memory DRAM (DDR5)<br/>(~60-100 ns, 32GB - 2TB)"]
F["CXL Attached Memory / PMEM<br/>(~150-250 ns, Multi-TB)"]
end
subgraph Non-Volatile Storage Bus
G["NVMe SSD (PCIe Gen4/Gen5 x4)<br/>(~10-20 ยตs, 1-30 TB)"]
H["SATA SSD / SAS<br/>(~150 ยตs, 1-16 TB)"]
I["Nearline HDD (7200 RPM CMR/SMR)<br/>(~5-15 ms, 10-30 TB)"]
end

A --> B --> C --> D --> E --> F --> G --> H --> I

Memory Layer Specificationsโ€‹

LayerMediumTyp. LatencyTyp. BandwidthVolatile?Managed By
RegistersFlip-flops / Static latches0.5ย ns0.5\text{ ns}>1ย TB/s> 1\text{ TB/s}YesCompiler / Register Allocator
L1d CacheSRAM (6T/8T cells)1โˆ’1.5ย ns1 - 1.5\text{ ns}โ‰ˆ400ย GB/s\approx 400\text{ GB/s}YesHardware CPU Core
L2 CacheSRAM3โˆ’7ย ns3 - 7\text{ ns}โ‰ˆ200ย GB/s\approx 200\text{ GB/s}YesHardware CPU Core
L3 CacheSRAM (eDRAM)15โˆ’25ย ns15 - 25\text{ ns}โ‰ˆ100ย GB/s\approx 100\text{ GB/s}YesShared Ring / Mesh Bus
DRAM (DDR5)Dynamic capacitors60โˆ’100ย ns60 - 100\text{ ns}30โˆ’80ย GB/s30 - 80\text{ GB/s} per ch.YesMemory Controller / MMU
CXL MemoryCXL.mem over PCIe 5.0150โˆ’250ย ns150 - 250\text{ ns}32โˆ’64ย GB/s32 - 64\text{ GB/s}ConfigurableCXL Controller / Linux Tiering
NVMe Gen53D TLC/QLC NAND10โˆ’25ฮผs10 - 25\mu\text{s}7โˆ’14ย GB/s7 - 14\text{ GB/s}NoNVMe Host Driver / FTL
Mechanical HDDMagnetic Platters5โˆ’15ย ms5 - 15\text{ ms}150โˆ’280ย MB/s150 - 280\text{ MB/s}NoBlock Layer / SCSI/SATA HBA

Cache Line Alignment & False Sharingโ€‹

CPUs do not read single bytes from DRAM; they fetch memory in discrete Cache Lines (typically 64 bytes on x86-64 and ARM64).

The False Sharing Pitfallโ€‹

When two threads running on different cores mutate distinct variables that happen to share the same 64-byte cache line, the CPU cache coherency protocol (MESI / MOESI) invalidates the entire cache line across cores on every store.

// Anti-pattern: Two hot counters located in the same 64-byte cache line
struct StatsBad {
uint64_t thread1_ops; // 8 bytes \ Same 64-byte cache line!
uint64_t thread2_ops; // 8 bytes / Triggers ping-pong invalidations
};

// Optimized: Explicit 64-byte alignment padding eliminates false sharing
struct StatsGood {
alignas(64) uint64_t thread1_ops; // Dedicated 64-byte line
alignas(64) uint64_t thread2_ops; // Dedicated 64-byte line
};

The PCIe Bus & NVMe Protocolโ€‹

Before NVMe, solid-state disks connected through SATA/AHCI controllers designed for slow mechanical spinning disks, restricted to a single queue with a depth of 32 commands.

NVMe (Non-Volatile Memory Express) was engineered specifically for low-latency solid-state media over the PCIe bus:

  • Up to 64,000 parallel queues.
  • Up to 64,000 commands per queue.
  • Direct CPU-to-controller communication without legacy locking.
  • MSI-X interrupt steering mapped directly to CPU cores.
Next Section

Explore how solid-state drives physically store charge and organize flash blocks in NAND Flash, FTL & SSD Internals.