Cache Memory Simplified

Jony
4 min readSep 27, 2021

What did the data say to the CPU? Cache me outside

Everybody knows about RAM, it is one of those specs everyone looks after even when spending money on a new SmartPhone. But, did you know about the wonders of Cache Memory?

I will help you in that quest. In simple terms, Cache is the middle man, a temporary memory that can be described as small, fast, accessible, and always ready for work. It is a chip-based computer component with one important mission: To increase performance, and to achieve this, the processor stores a few of its favorite and frequently used program instructions or data, so that this can be accessed quickly for subsequent calls.

Frequently also called CPU memory, it can be found integrated directly into the CPU chip, or placed on a separate chip that has a separate bus interconnected with the CPU. This makes Cache more efficient than the computer’s main memory source because it’s physically close to the processor.

Besides acting as a close neighbor to the CPU, Cache Memory is of a different kind. RAM is Dynamic, it uses capacitors to store data, and these capacitors are constantly refreshed with electricity for them to store the data. Cache is SRAM or static RAM. SRAM does not need to be refreshed, making it a lot faster.

So the question arrives: If Cache is so fast, why do we use other options like RAM? And the answer is as simple as the question: Size, and Price. Cache storage is limited and extremely expensive for its space, so it only makes sense to keep the most-accessed data there and leave everything else to RAM.

The Fastest Kid in Town

The process behind the madness is simple, Cache Memory stores data and instructions from RAM that it’s waiting to be used by the CPU. The CPU then first checks the fastest Cache memory to see if the data needed is there. If the data is not in Cache Memory, then the CPU goes back to the slower primary memory to get the data.

But wait! The fastest kid in town is not alone, it comes in many flavors. Level 1 Cache, or Primary Cache. Level 2 Cache, or External Cache. Level 3 Cache, or Shared Cache.

Level 1 (L1) is the cache integrated into the CPU itself. The fastest Cache on the computer, running at the same speed as the processor. It assesses the data that was just accessed by the CPU and determines that it’s likely you’ll access it again soon. This is basically the first place the computer will check the next time you need certain information.

Level 2 (L2) also called the “secondary cache.” This level is used by your computer to catch recent data that was not caught by the Level 1 Cache. In earlier computers, Level 2 Cache was located on a separate chip on the motherboard, close to the processor, but in modern CPUs, Level 2 can be located on the processor. Level 2 Cache is larger than Level 1 Cache, but never faster.

Level 3 (L3) Follows a similar method. It is used to catch that recent data that was not caught by the Level 2 Cache. If Level 3 does not have the data, then the CPU goes to the infamous RAM. Level 3 Cache is larger than Level 2 Cache, not as fast, but always there to improve the performance of L1 and L2 Cache. Level 3 Cache memory is often shared between all the cores in a CPU, whether Level 1 and Level 2 Cache are dedicated to their own CPU core.

Mooore!

Yes, there is life beyond the trio. The hole goes deeper, and Alice is happy about it. You will also find cache memory on the hard drive under the name of Disk Cache. Usually overlooked by most, but a feature that has a huge impact on the drive speeds. It’s the slowest of all the cache levels, as it takes data from the hard drive to put on the RAM, but it is essential to improve the time it takes to read from or write to a hard disk. Modern Disk Cache can range from 8MB to 256MB, and some SSDs may go as high as 4GB.

Thanks for reading this article! Leave a comment below if you have any questions, and if you want to get alerts on the latest updates, be sure to follow me on Twitter

--

--