Fast memory and big memory
For the CPU to calculate, values must be close by. But fast memory is small, and big memory is slow. So a computer splits memory into layers. Like a nearby desk and a far-off bookshelf.
The desktop and the bookshelf
Think of studying.
On the desk within reach
you can keep only a few books,
but you grab them at once.
A shelf holds many,
but you have to get up and go.
Memory is the same.
Close means fast and small,
far means big and slow.
The trade between near and far.
You can't have both.
Memory that's fast and big too
is too expensive
or hard to make.
So you have to choose.
A little, but fast,
or a lot, but slow.
Stack them by closeness
So a computer
doesn't keep one kind of memory.
From the tiny, fast memory
closest to the CPU,
to far, big, slow memory,
it stacks them in layers.
Higher up, faster and smaller,
lower down, bigger and slower.
Top fast and small, bottom big and slow.
The memory we saw in lesson 9
is one of these layers.
Above it are the faster
cache and registers,
below is the bigger, slower
storage.
Put what you use often up high,
what you use rarely down low.
Grab from the desk, or go to the shelf
When the CPU
needs one value,
if it's in the nearby cache
it grabs it in a blink.
If it has to go far to memory,
it takes that much longer.
Even the same value,
by where it is,
splits the time.
Near vs far, the time to fetch.
So a computer
moves a value it just used,
or will likely use soon,
into the nearby cache.
So next time it's needed
it doesn't go far.
A small preparation
saves a lot of time.
Is it on the desk, or not
If the value the CPU looks for
is already in the nearby cache,
it's a "hit."
It grabs it right away.
If not, a "miss."
It has to go all the way to memory.
So keeping what's used often
in the cache matters.
By whether the value is in the cache.
The more hits,
the faster the computer.
So the rule "keep what you'll use often
close by"
is the heart of handling memory.
Using a small cache
cleverly.
Can't it all be fast?
"Can't we just fill it
all with fast memory?"
Then it's too expensive,
and can't hold much.
"All with big memory?"
Then it's too slow.
The layers are
a compromise between the two.
Choose and see why.
All fast · all big · layers.
What you use often, in the small fast top layer,
what you use rarely, in the big slow bottom.
Thanks to this clever split
a computer is fast
yet remembers a lot.
Next time we'll see
how all these parts
connect into one machine.