Working of Cache Technology
Working of Cache Technology
com
1111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110
1101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100
1111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110
0111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110
1001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100
1001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110
1011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110
0001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100
0011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000
0011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010
1001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000
1001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000
1011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111001101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
1010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011
0000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001
0000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001
0010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011
1100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011
0100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101
0110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111
0110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100
1100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101
1110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101
1011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111
0000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101
0000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
Working of Cache
Technology
If you have been shopping for a computer, then you have heard the word "cache."
Modern computers have both L1 and L2 caches. You may also have gotten advice on
the topic from well-meaning friends, perhaps something like "Don't buy that Celeron
chip, it doesn't have any cache in it!"
A Simple Example
Caching is a technology based on the memory subsystem of your computer. The
main purpose of a cache is to accelerate your computer while keeping the price of
the computer low. Caching allows you to do your computer tasks more rapidly.
To understand the basic idea behind a cache system, let's start with a super-simple
example that uses a librarian to demonstrate caching concepts. Let's imagine a
librarian behind his desk. He is there to give you the books you ask for. For the sake
of simplicity, let's say you can't get the books yourself -- you have to ask the
librarian for any book you want to read, and he fetches it for you from a set of stacks
in a storeroom (the library of congress in Washington, D.C., is set up this way). First,
let's start with a librarian without cache.
The first customer arrives. He asks for the book Moby Dick. The librarian goes into
the storeroom, gets the book, returns to the counter and gives the book to the
customer. Later, the client comes back to return the book. The librarian takes the
book and returns it to the storeroom. He then returns to his counter waiting for
another customer. Let's say the next customer asks for Moby Dick (you saw it
coming...). The librarian then has to return to the storeroom to get the book he
recently handled and give it to the client. Under this model, the librarian has to make
a complete round trip to fetch every book -- even very popular ones that are
requested frequently. Is there a way to improve the performance of the librarian?
Yes, there's a way -- we can put a cache on the librarian. Let's give the librarian a
backpack into which he will be able to store 10 books (in computer terms, the
librarian now has a 10-book cache). In this backpack, he will put the books the
clients return to him, up to a maximum of 10. Let's use the prior example, but now
with our new-and-improved caching librarian.
The day starts. The backpack of the librarian is empty. Our first client arrives and
asks for Moby Dick. No magic here -- the librarian has to go to the storeroom to get
the book. He gives it to the client. Later, the client returns and gives the book back
1111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110
1101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100
1111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110
0111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110
1001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100
1001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110
1011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110
0001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100
0011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000
0011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010
1001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000
1001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000
1011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111001101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
1010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011
0000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001
0000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001
0010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011
1100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011
0100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101
0110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111
0110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100
1100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101
1110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101
1011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111
0000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101
0000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
to the librarian. Instead of returning to the storeroom to return the book, the
librarian puts the book in his backpack and stands there (he checks first to see if the
bag is full -- more on that later). Another client arrives and asks for Moby Dick.
Before going to the storeroom, the librarian checks to see if this title is in his
backpack. He finds it! All he has to do is take the book from the backpack and give it
to the client. There's no journey into the storeroom, so the client is served more
efficiently.
What if the client asked for a title not in the cache (the backpack)? In this case, the
librarian is less efficient with a cache than without one, because the librarian takes
the time to look for the book in his backpack first. One of the challenges of cache
design is to minimize the impact of cache searches, and modern hardware has
reduced this time delay to practically zero. Even in our simple librarian example, the
latency time (the waiting time) of searching the cache is so small compared to the
time to walk back to the storeroom that it is irrelevant. The cache is small (10
books), and the time it takes to notice a miss is only a tiny fraction of the time that a
journey to the storeroom takes.
From this example you can see several important facts about caching:
Cache technology is the use of a faster but smaller memory type to accelerate a
slower but larger memory type.
When using a cache, you must check the cache to see if an item is in there. If it is
there, it's called a cache hit. If not, it is called a cache miss and the computer must
wait for a round trip from the larger, slower memory area.
A cache has some maximum size that is much smaller than the larger storage area.
It is possible to have multiple layers of cache. With our librarian example, the
smaller but faster memory type is the backpack, and the storeroom represents the
larger and slower memory type. This is a one-level cache. There might be another
layer of cache consisting of a shelf that can hold 100 books behind the counter. The
librarian can check the backpack, then the shelf and then the storeroom. This would
be a two-level cache.
Computer Caches
What if we build a special memory bank, small but very fast (around 30
nanoseconds)? That's already two times faster than the main memory access. That's
called a level 2 cache or an L2 cache. What if we build an even smaller but faster
memory system directly into the microprocessor's chip? That way, this memory will
be accessed at the speed of the microprocessor and not the speed of the memory
1111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110
1101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100
1111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110
0111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110
1001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100
1001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110
1011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110
0001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100
0011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000
0011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010
1001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000
1001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000
1011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111001101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
1010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011
0000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001
0000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001
0010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011
1100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011
0100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101
0110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111
0110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100
1100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101
1110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101
1011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111
0000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101
0000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
There are a lot of subsystems in a computer; you can put cache between many of
them to improve performance. Here's an example. We have the microprocessor (the
fastest thing in the computer). Then there's the L1 cache that caches the L2 cache
that caches the main memory which can be used (and is often used) as a cache for
even slower peripherals like hard disks and CD-ROMs. The hard disks are also used
to cache an even slower medium -- your Internet connection.
Your Internet connection is the slowest link in your computer. So your browser
(Internet Explorer, Netscape, Opera, etc.) uses the hard disk to store HTML pages,
putting them into a special folder on your disk. The first time you ask for an HTML
page, your browser renders it and a copy of it is also stored on your disk. The next
time you request access to this page, your browser checks if the date of the file on
the Internet is newer than the one cached. If the date is the same, your browser
uses the one on your hard disk instead of downloading it from Internet. In this case,
the smaller but faster memory system is your hard disk and the larger and slower
one is the Internet.
Cache can also be built directly on peripherals. Modern hard disks come with fast
memory, around 512 kilobytes, hardwired to the hard disk. The computer doesn't
directly use this memory -- the hard-disk controller does. For the computer, these
memory chips are the disk itself. When the computer asks for data from the hard
disk, the hard-disk controller checks into this memory before moving the mechanical
parts of the hard disk (which is very slow compared to memory). If it finds the data
that the computer asked for in the cache, it will return the data stored in the cache
without actually accessing data on the disk itself, saving a lot of time.
Here's an experiment you can try. Your computer caches your floppy drive with main
memory, and you can actually see it happening. Access a large file from your floppy
-- for example, open a 300-kilobyte text file in a text editor. The first time, you will
see the light on your floppy turning on, and you will wait. The floppy disk is
extremely slow, so it will take 20 seconds to load the file. Now, close the editor and
open the same file again. The second time (don't wait 30 minutes or do a lot of disk
access between the two tries) you won't see the light turning on, and you won't wait.
The operating system checked into its memory cache for the floppy disk and found
what it was looking for. So instead of waiting 20 seconds, the data was found in a
memory subsystem much faster than when you first tried it (one access to the floppy
disk takes 120 milliseconds, while one access to the main memory takes around 60
nanoseconds -- that's a lot faster). You could have run the same test on your hard
disk, but it's more evident on the floppy drive because it's so slow.
To give you the big picture of it all, here's a list of a normal caching system:
1111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110
1101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100
1111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110
0111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110
1001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100
1001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110
1011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110
0001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100
0011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000
0011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010
1001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000
1001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000
1011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111001101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
1010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011
0000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001
0000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001
0010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011
1100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011
0100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101
0110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111
0110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100
1100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101
1110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101
1011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111
0000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101
0000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
Cache Technology
One common question asked at this point is, "Why not make all of the computer's
memory run at the same speed as the L1 cache, so no caching would be required?"
That would work, but it would be incredibly expensive. The idea behind caching is to
use a small amount of expensive memory to speed up a large amount of slower,
less-expensive memory.
In designing a computer, the goal is to allow the microprocessor to run at its full
speed as inexpensively as possible. A 500-MHz chip goes through 500 million cycles
in one second (one cycle every two nanoseconds). Without L1 and L2 caches, an
access to the main memory takes 60 nanoseconds, or about 30 wasted cycles
accessing memory.
When you think about it, it is kind of incredible that such relatively tiny amounts of
memory can maximize the use of much larger amounts of memory. Think about a
256-kilobyte L2 cache that caches 64 megabytes of RAM. In this case, 256,000 bytes
efficiently caches 64,000,000 bytes. Why does that work?
This small program asks the user to enter a number between 1 and 100. It reads the
value entered by the user. Then, the program divides every number between 1 and
1111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110
1101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100
1111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110
0111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110
1001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100
1001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110
1011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110
0001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100
0011011000111110110110101011001010011110011101100111000000011000101111001101010010011100100110000101001001111110000101101011111011111010101100000011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000
0011010001011100111100000011000010011100111101101001111000111010010100101101111010111110100100000111000001011100001101100011111011011010101100101001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010
1001111001110110011100000001100010111100110101001001110010011000010100100111111000010110101111101111101010110000001101000101110011110000001100001001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000
1001110011110110100111100011101001010010110111101011111010010000011100000101110000110110001111101101101010110010100111100111011001110000000110001011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111000000110000100111001111011010011110001110100101001011011110101111101001000001110000010111000011011000111110110110101011001010011110011101100111000000011000
1011110011010100100111001001100001010010011111100001011010111110111110101011000000110100010111001111001101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
1010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011
0000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001
0000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001
0010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011
1100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011
0100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101
0110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111
0110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100
1100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101
1110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101
1011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111
0000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101
0000011110101011010000111010011110001111001011110110000100001001101011011100010111101101000100010000011101101111000001111000001111001011110001110010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111
0010010100001101011000011010010110101101001001001100101100101011000001110100110110111101100000010010010101001101000001111010101101000011101001111000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111
1000111100101111011000010000100110101101110001011110110100010001000001110110111100000111100000111100101111000111001001010000110101100001101001011010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101
1010110100100100110010110010101100000111010011011011110110000001001001010100110100000111101010110100001110100111100011110010111101100001000010011010110111000101111011010001000100000111011011110000011110000011110010111100011100100101000011010110000110100101101011010010010011001011001010110000011101001101101111011000000100100101010011010000011110101011010000111010011110001111001011110110000100001001
100 by the number entered by the user. It checks if the remainder is 0 (modulo
division). If so, the program outputs "Z is a multiple of X" (for example, 12 is a
multiple of 6), for every number between 1 and 100. Then the program ends.
Even if you don't know much about computer programming, it is easy to understand
that in the 11 lines of this program, the loop part (lines 7 to 9) are executed 100
times. All of the other lines are executed only once. Lines 7 to 9 will run significantly
faster because of caching.
This program is very small and can easily fit entirely in the smallest of L1 caches, but
let's say this program is huge. The result remains the same. When you program, a
lot of action takes place inside loops. A word processor spends 95 percent of the time
waiting for your input and displaying it on the screen. This part of the word-
processor program is in the cache.
This 95%-to-5% ratio (approximately) is what we call the locality of reference, and
it's why a cache works so efficiently. This is also why such a small cache can
efficiently cache such a large memory system. You can see why it's not worth it to
construct a computer with the fastest memory everywhere. We can deliver 95
percent of this effectiveness for a fraction of the cost.