Web & Dev

Computer Memory Architecture

DRAM, cache, virtual memory, and paging — how CPUs access data.

DRAM generations

TypeData ratePeak bandwidth (single channel)
DDR3-16001600 MT/s12.8 GB/s
DDR4-24002400 MT/s19.2 GB/s
DDR4-32003200 MT/s25.6 GB/s
DDR5-48004800 MT/s38.4 GB/s
DDR5-64006400 MT/s51.2 GB/s
LPDDR56400 MT/smobile / soldered
HBM2e3.6 Gbps/pin~460 GB/s stack
HBM36.4 Gbps/pin~800 GB/s stack

Virtual memory

Page size4 KB default; huge pages 2 MB or 1 GB
Page tableMaps virtual → physical — multi-level (typically 4 on x86-64)
TLBCaches recent translations
TLB missCosts ~100 ns on x86; use huge pages for large working sets
Swap / pagingMove cold pages to disk — modern systems avoid swap when possible

Cache behavior

Cache line64 bytes on x86 / ARM
Associativity8–16-way typical
CoherenceMESI / MOESI between cores
False sharingDifferent cores hitting same cache line — pad to 64 B
Write-backDirty lines flushed to next level on eviction

Tips

  • Design data for locality — contiguous arrays beat linked lists for iteration.
  • Align hot data on cache-line boundaries.
  • Prefetch: modern CPUs detect sequential access automatically; manual prefetch hints help for irregular patterns.
  • Avoid false sharing between threads by padding or separating per-thread data.

Worked examples

Bandwidth from the data rate. A DDR channel moves 8 bytes (64 bits) per transfer, so peak bandwidth is the data rate times 8. DDR4-3200 gives 3,200 million transfers per second × 8 B = 25.6 GB/s, and two channels give 51.2 GB/s. The “3200” is megatransfers per second, not megahertz: DDR memory transfers on both clock edges, so the I/O clock for DDR4-3200 is 1,600 MHz. Real programs rarely reach peak, because refresh, bank conflicts and read/write turnaround take cycles.

Cache lines and stride. A 64-byte line holds sixteen 4-byte integers. Summing an array in order misses once per 16 elements; the hardware prefetcher usually hides even that. Walking the same data with a 4,096-byte stride touches a new line on every access and uses only 4 of its 64 bytes, so effective bandwidth falls to a small fraction.

Pages and the TLB. A 1 GiB working set is 1 GiB / 4 KiB = 262,144 pages of 4 KiB, but only 512 pages of 2 MiB. Fewer pages means far fewer TLB entries are needed, which is why large databases often enable huge pages.

Common mistakes

  • Confusing GB/s with Gb/s: a factor of 8. Memory bandwidth is quoted in bytes, network links in bits.
  • Comparing MT/s with MHz across generations without checking which is meant.
  • Quoting peak bandwidth as if it were sustained throughput.
  • Assuming a linked list is as fast as an array. Pointer chasing defeats the prefetcher and takes a cache miss per node.
Was this article helpful?