ContentsThe library

Memory, All the Way Down

If a Cache Hit Took One Second, Main Memory Would Take Four Minutes

Last timeThe Page That Was Not There

The gaps in the memory hierarchy are two orders of magnitude and nobody can feel a nanosecond. Rescale the whole ladder to seconds and the design rules become obvious.

The ladder and its rungs

Here are the numbers. They vary across machines by a factor of two and the

shape never changes.

FIG 1The hierarchy, in nanoseconds and in seconds
nanosecondsseconds, if one cycle istypical size in kilobyte
nearest cache1164
second cache441024
third cache121232768
main memory8024033554432
solid state drive1000003000001000000000
spinning disk8000000240000002000000000
Read the middle column rather than the left one. The two marked figures are the ones worth carrying: main memory is four minutes away and a solid state drive is eleven days away, in the units the processor experiences. The right column shows what you buy by going there.

The left column is correct and useless. Nobody has any intuition for the

difference between one nanosecond and eighty nanoseconds, because nobody has

experienced either.

The same ladder in seconds

So rescale. Take one processor cycle, about a third of a nanosecond, and call

it one second. Everything else scales by the same factor, and the ladder turns

into durations from ordinary life.

Reaching the nearest cache: one second. Reaching the second cache: four

seconds, about as long as it takes to find something on your desk. The third

cache: twelve seconds, walking to a filing cabinet. Main memory: four minutes,

which is walking to another floor of the building. A solid state drive: eleven

days. A spinning disk: nine months.

That rescaling is the single most useful thing in this course, because it

converts an abstract ratio into a decision you already know how to make. Nobody

would walk to another floor of the building eight hundred times to collect

eight hundred items one at a time. They would carry a box. That instinct,

transplanted back down to nanoseconds, is the whole content of the next two

lessons.

The lesson stops here

4 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Two Programs Can Hold the Same Address and Never Collide
  2. 02A Few Hundred Entries Decide Whether Your Program Falls Off a Cliffopening only
  3. 03Most Faults Cost a Microsecond and One Costs Ten Thousandopening only
  4. 04If a Cache Hit Took One Second, Main Memory Would Take Four Minutesyou are here
  5. 05You Asked for Four Bytes and Sixty-Four Arrivedopening only
  6. 06Predict the Speedup on Paper Before You Change a Lineopening only
  7. 07One Allocator Adds a Number, the Other Goes Lookingopening only
  8. 08Two Threads, No Shared Variables, and One of Them Is Ten Times Sloweropening only

Read alongside