0 day streak
5. Operating systemsMemory hierarchy

Memory hierarchy

The memory hierarchy is the ladder of places a computer keeps data, from tiny and fast to huge and slow: registers, several levels of CPU cache, main memory, then SSD or disk, then the network. Each step down is bigger and cheaper but much slower; roughly, L1 cache answers in about a nanosecond, RAM in around a hundred, and an SSD in tens of thousands. Hardware bridges the gap by moving data in 64-byte chunks called cache lines, betting you’ll soon want the neighbors of what you just touched. That’s why walking an array in order beats chasing scattered pointers, and why two cores writing unrelated variables on the same line can slow each other down.

In this lesson: A zoom-out world with latency scaled to human time: L1 is a second, disk is months. A cache-line sim and false sharing between two cores.