How Does the CPU Cache Work?
By Stephen Orgill
The cache on your CPU has become a very important part of today's computing. The
cache is a very high speed and very expensive piece of memory, which is used to
speed up the memory retrieval process. Due to its expensive CPU's come with a
relatively small amount of cache compared with the main system memory. Budget
CPU's have even less cache, this is the main way that the top processor
manufacturers take the cost out of their budget CPU's.
How does the CPU Cache work?
Without the cache memory every time the CPU requested data it would send a
request to the main memory which would then be sent back across the memory bus
to the CPU. This is a slow process in computing terms. The idea of the cache is
that this extremely fast memory would store and data that is frequently accessed
and also if possible the data that is around it.
CPU's use a 2 level cache system. The level 1 cache is the fastest and smallest memory,
level 2 cache is larger and slightly slower but still smaller and faster than the main memory.
This is to achieve the quickest possible response time to the CPU. Its based on
playing the percentages. If a certain piece of data has been requested five times
before, its likely that this specific piece of data will be required again and
so is stored in the cache memory.
Lets take a library as an example o how caching works. Imagine a large library
but with only one librarian (the standard one CPU setup). The first person comes
into the library and asks for Lord of the Rings. The librarian goes off follows
the path to the bookshelves (Memory Bus) retrieves the book and gives it to the
person. The book is returned to the library once its finished with. Now without
cache the book would be returned to the shelf. When the next person arrives and
asks for Lord of the Rings, the same process happens and takes the same amount of time.
If this library had a cache system then once the book was returned it would have
been put on a shelf at the librarians desk. This way once the second person comes
in and asks for Lord of the Rings, the librarian only has to reach down to the
shelf and retrieve the book. This significantly reduces the time it takes to
retrieve the book. Back to computing this is the same idea, the data in the
cache is retrieved much quicker. The computer uses its logic to determine which
data is the most frequently accessed and keeps them books on the shelf so to speak.
That is a one level cache system which is used in most hard drives and other
components. CPU's however use a 2 level cache system. The principles are the
same. The level 1 cache is the fastest and smallest memory, level 2 cache is
larger and slightly slower but still smaller and faster than the main memory.
|