Introduction to CPU Cache
What is CPU cache? Now a computer has two different types of memory. One type is what is used in RAM modules, which is DRAM or a dynamic RAM. And DRAM is memory that uses capacitors to store data and these capacitors have to constantly and dynamically be refreshed often with electricity in order for them to store data.
But there’s another type of memory that a computer uses that doesn’t have to be constantly refreshed. And this memory is called SRAM or a static RAM. And SRAM is what is used in the CPU cache. And because SRAM doesn’t have to be constantly refreshed, it is a lot faster than DRAM and it’s also very expensive. The CPU cache is the CPU’s internal memory.
The Role of CPU Cache
And its job is to store copies of data and instructions from RAM that’s waiting to be used by the CPU. So basically what the CPU cache does is that it holds common data that it thinks the CPU is going to access over and over again because when the CPU needs to access certain data, it always checks the faster cache memory first to see if a data it needs is there.
And if it’s not, then the CPU would have to go back to the slower primary memory or RAM to get the data it needs. So that’s why cache memory is so important, because if the CPU can access what it needs on the faster cache, then the faster the computer will perform. So basically the whole idea behind cache is to make the computer run faster at a cheaper price.
The Necessity of CPU Cache
Now a computer can run without the CPU cache, but it would be a lot slower because even though RAM is becoming faster, it still can’t feed the data to the CPU fast enough because CPUs have gotten so fast, that a lot of times the CPU is waiting around doing nothing while it waits for more data, and this creates a bottleneck.
So that’s why the CPU cache was developed. So it can act like a middleman between the CPU and RAM to assist in feeding the CPU that data it needs a lot faster which reduces bottlenecks.
Levels of CPU Cache
CPU cache comes in three different levels. For example, there’s level 1 cache, which is also called primary cache, and level 1 cache is located on the processor itself. So it runs as the same speed as the processor. So it’s very fast and is the fastest cache on the computer.
And there is also level 2 cache, which is also called external cache, and level 2 cache is used to catch recent data accesses from the processor that were not caught by the level 1 cache.
So in a nutshell, if the CPU can’t find that data it needs in the level 1 cache, it then searches the level 2 cache for the data. And if the CPU can’t find the data in the level 2 cache, then it searches the last level of cache which is level 3. And level 3 cache is used to catch recent data accesses that were not caught by the level 2 cache. And finally, if level 3 doesn’t have the data, then the CPU has to go back to the slower RAM to find the data it needs.
Historical and Modern Cache Levels
Now in earlier computers, level 2 cache was located on a separate chip on the motherboard. Or in modern CPUs, it would be located on the processor. Level 2 cache is larger than level 1 cache but it’s not as fast as level 1 cache. And level 3 cache is also located on the processor.
Level 3 is larger than level 2 but it’s not as fast as level 2 cache. Level 3 is often referred to as shared cache because its memory is shared between all the cores on the CPU, whereas level 1 and level 2 cache are dedicated to their own CPU core.