The CPU cache is a tiny temporary memory located on the CPU die itself. It storesprefetched data that the CPU will likely need for quick access. This is necessary to ensure the RAM doesn’t bottleneck the CPU.
Modern CPUs typically implement CPU cache in 3 levels –L1,L2, andL3. These play an important part in determining CPU performance (especially for certain tasks like gaming).
So, let’s look at how CPU cache works, why it matters, and how much CPU cache you’ll need for your workloads.
What Does the CPU Cache Do
The programs that you run are first loaded into the RAM. The CPUfetches,decodes, andexecutesinstructions from the main memory.
The ‘problem’ with this is that modern processors are extremely powerful (capable of executing billions of instructions per second).
For instance, theAMD Ryzen 9 3950Xhas a base clock speed of 3.5 GHz (3.5 billion cycles per second). It can execute over a hundred instructions in asingle clock cycle.
However, accessing data from the RAM may takehundreds of cycles. That is a lot of wasted cycles that the CPU is stalled for.
If the CPU had to access data from the RAM every time, that wouldcreate a significant bottleneckand cripple system performance. This is where the CPU cache comes into play.
The CPU analyzes access patterns to predict what data and instructions it’ll likely need next. Then, it moves them from the RAM to the CPU cache before they’re actually needed (this is calledprefetching).
Depending on the level, accessing data from the CPU cache can be over a hundred times faster than doing so from the RAM. So, the CPU delay is significantly reduced.
Current CPUs implement 3 levels of CPU cache to maximize performance. This allows them to hit the sweet spot for cache size, latency, and hit rate.
you may get the exact numbers for your CPU online or using system profiling tools likeCPU-ZandHWiNFO.
On myRyzen 7 5700G, you may see that it’s split intoL1 DataandL1 Instructions. 32 KB of both caches is embedded into all 8 cores. This means the total L1 cache is 512 KB.
As the L1 cache is the smallest/fastest memory level, the CPU first checks whether the required data is in L1. If the data is present, it immediately reads from or writes to L1. This is called acache hit.