CPU Cache Explained - What is Cache Memory

Computer has two type of memory. One type is used in RAM modules which is DRAM OR Dynamic RAM.

DRAM is memory that uses capacitor 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 is another type of memory that computer uses that doesn't constantly have to be refreshed and this memory is called SRAM or static RAM. 

SRAM is what is used in CPU Cache and because SRAM doesn't have to be constantly refreshed it is a lot faster then DRAM and it's also very expensive.
 
cache1

The CPU Cache is CPU's internal memory. It's job is to store copy of data and instructions from RAM that's waiting to be used by the CPU. CPU Cache holds common data that it thinks CPU is going to access over and over again because when CPU needs to access certain data it always checks the faster memory first to see if the data it needs is there. And if 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. Therefore, storing the commonly required data in the cache is beneficial to increase the computation speed.
 
cache2

There are three types of cache. The level 1 cache is the smallest. It is located inside the CPU or the processor. So, it runs at the same speed as the CPU.
 
cache3

Level 2 and level 3 caches are external. In modern computers level 2 cache is also being located inside the CPU. Level 2 cache is larger than level 1 cache. If the required data is not available in level 1 cache, the CPU checks the level 2 cache.
 
cache4

If the required data is not available in both level 1 and level 2 caches, the CPU checks the level 3 cache. If the required data is not available in any of these caches, the CPU will access the RAM. Level 1 cache is the fastest cache of all. A CPU can have multiple cores. A core is the execution unit of the CPU. Each core can have separate level 1 and level 2 caches. The level 3 cache is shared among all cores.
 
cache5

cache6

Speed
RAM is faster than secondary storage mediums, but it is not as fast as the cache. 

Cost
Although RAM is expensive, it is not expensive as a cache. Capacity The capacity of cache is smaller than RAM, which has a higher capacity.

Usage
The cache holds frequently used data by the CPU. RAM holds programs and data that are currently executed by the CPU.

Conclusion
Both cache and RAM are volatile memory. The difference between cache and RAM is that the cache is a fast memory component that stores the frequently used data by the CPU while RAM is a computing device that stores data and programs currently used by the CPU. In brief, the cache is faster and expensive than RAM.

0 comments:

Post a Comment