How Does CPU Cache Work?

When checking out any new processor, there’s a high chance of you seeing the terms ‘L2 cache’ and ‘L3 cache’ in the specs section.

What these are and how they affect CPU performance?

To understand this, we’ll have to go back in time first.

In the early days of computers, both CPU and main memory were slow. Things started to change in 1980s with processors coming with more and more clock speed each year which led to performance increment.

But there were slower advancements in RAM area, which increased the performance gap between the two.

To bridge this gap, the cache memory was invented.

It’s a form of Static RAM (SRAM) that can store data without needing to be constantly refreshed, unlike Dynamic RAM (DRAM) that constantly needs to be electrically refreshed and is used in RAM modules these days.

Being part of the CPU itself, it’s the fastest memory to be used in a computer. Its job is to copy common data/instructions from the RAM that it thinks the CPU is going to access soon.

After this, CPU always check the cache first for its required data before moving on to RAM memory.

L1, L2, and L3 Cache

The cache memory is itself divided into three different levels: L1, L2, and L3 cache.

L1 Cache

L1 cache is the fastest CPU cache out there and this is the place where the data/instructions, which CPU is about to use, are stored.

It’s measured in KB and its size varies from processor to processor.

For example, the L1 cache size is 64 KB per CPU core in AMD Ryzen 7 5800X. This 64 KB L1 cache is further divided into two parts: 32 KB instruction cache and 32 KB data cache.

Instruction cache stores the information about the operations/instructions the CPU should perform on data, while the data cache is used to store the data on which those operations will be performed.

L2 Cache

Next comes the L2 cache. It’s bigger but slower than L1 cache, this is where CPU searches for its required data/instructions if it can’t find them in L1 cache.

Unlike L1 cache, L2 cache is not divided into data and instruction caches and acts as a combined repository. Its size also varies from 256 KB to 8 MB depending on your processor. The Ryzen 7 5800X comes with 512 KB L2 cache per core (Total: 4 MB).

While slower than L1 cache, L2 cache is still 25 times faster than RAM memory.

L3 Cache

Lastly, we have the L3 (or Level 3) cache.

This the last cache memory CPU searches before moving on to the main memory (RAM) of the computer.

Back in the days of single-core CPUs, L3 cache was a part of the motherboard. But now it’s available on the CPU itself, like L1 and L2 cache. Being on Level 3, this cache is slower than L2, but is significantly bigger in size.

Unlike L1 and L2 caches who each core gets one for its own, there’s only one L3 cache memory in a CPU and is shared among all of its cores. Mainstream processors such as 5600X and 5800X have 32 MB L3 cache, but some flagship desktop/server processors can have 64 MB L3 cache.

How CPU Cache Works

There are different types of memory inside a computer.

First, we have permanent storage devices like HDD and SSD that store our files, software, games, and OS. Next we have the main memory aka. RAM. This is a faster, short-term memory that retrieves data from the hard drive/SSD.

After this, the data goes from RAM to L3 cache, then from L3 cache to L2 cache, and lastly from L2 cache to L1 cache.

The CPU first searches for the data in L1, then L2, and then L3. If the CPU finds its data in any of those levels, it’s known as cache hit. But if it’s unable to do so, it accesses the RAM for the data, and this event is known as cache miss.

Modern CPUs have L1 cache hit rate of 95%-97%. But since L2 has significantly higher latency than L1, this 2% cache hit difference can result in 10% performance difference.

Does CPU Cache Affect Gaming

Yes, it does.

Gaming generally involves a lot of repetitive tasks that can be processed quicker if your processor has a bigger cache.

With that said, you can’t consider the cache size as a standalone specification as gaming performance depends on a lot of other factors as well, such as clock speed and number of cores.

Other than this, different CPUs have different cache implementation. Therefore, you can’t directly compare two CPUs only through their cache sizes.

Like most PC hardware components, CPUs are coming with better specs with each passing year, including their cache memory.

So, make sure to consider factors like clock speed, microarchitecture, and cores/threads count, in addition to the cache size, before purchasing any new CPU.

Leave a Reply