But, why does it need this? What does it actually do?
A Little Background
For those of you who’ve seen the evolution of personal computing right from the early days, will remember the specs of computers of yore. Memory chips used to be in the KBs and so did the processor speeds. As time passed, we moved into the MHz territory, with memory chips running at 4 MHz and CPU at 2 MHz.
So, if the CPU would make a request on such a system, the memory would talk-back rapidly without any delay. Their matched clock-speeds helped make the processor run quickly. But, fast-forward a decade or two and now you can get CPUs that can run in GHz speed, but, unfortunately, memory chips could not keep up.
Big Problem: One Solution
The rapidly increasing CPU speeds meant that the CPU would actually need to wait for the memory chip to understand the fast succession of requests it was sending out. This was a problem. You can technically build memory which has the same speed of the CPU, but it takes more space on the Silicon to store each bit of information. These would cost a whole lot more than the DIMMs that we use today.
The workaround? Split the memory up in two. The main memory which we build out of Dynamic RAM as well as a second type of memory which we build into the CPU. It is much smaller, but also is a much faster type of memory compared to DRAM. And this is what we refer to as Cache.
What Does it Do?
Cache may be an old-fashioned English word, but that’s exactly what the CPU cache does – it stores things. Think of it like a Pirate’s treasure chest. Ok, maybe not. Since we’re all geeks and I already spoke about cache from a web browser, the functionality of this cache is also the same.
So rather than a computer making a request to a web server thousands of miles away and then downloading the images and content every time, cache will retain most of it in memory, for any browser. This saves time and web pages open up a lot faster thanks to cache in browsers.
A CPU has got the same problem, it can talk to its own memory a whole lot faster than what it can to the main memory. So, every time the CPU requests a bit of data, it ‘caches’ a copy to its local memory. This allows it to fetch it much faster in the near future when need be.
But that’s not all. Local memory on a CPU allows it to not only store and read data by the byte but also the next line. If the CPU executes one instruction at a time, there is a good chance that it will then be followed by a known number of instructions following the main action.
So rather than just getting one word from memory at a time, the CPU can access the next 128 bytes of memory and it will read, what is called, the cache line – one single line out of 128 from the CPU, in one go. The idea is always to reduce time and make the whole process much faster.