Cache Memory : Cache Memory Principles

The memory between CPU and main memory is known as cache memory. Cache memory is used to increase the performance of the PC. It holds data and instructions retrieved from RAM to provide faster access to the CPU. As CPU has to fetch instruction from main memory speed of CPU depending on fetching speed from main memory. CPU contains register which has fastest access but they are limited in number as well as costly. Cache is cheaper so we can access cache. Cache memory is a very high speed memory that is placed between the CPU and main memory, to operate at the speed of the CPU. It is used to reduce the average time to access data from the main memory. The cache is a smaller and faster memory which stores copies of the data from frequently used main memory locations. Most CPUs have different independent caches, including instruction and data.

Types/Levels of Cache Memory :

Cache memory is also commonly referred to by its level or proximity to the CPU. Traditionally the "levels" of cache memory describe its closeness and accessibility to the microprocessor. All levels of cache memory are faster than RAM. The cache closest to CPU is always faster but generally costs more and stores less data then other level of cache. Cache memory is designated in three levels:

1. Level 1 (L1) Cache : L1 cache is placed internally on the processor chip and it is closest the cache memory closest to the CPU. It is also called primary or internal cache. It is built directly into the processor chip. It has small capacity from 8 Km to 128 Kb.

2. Level 2 (L2) Cache : L2 Cache is the fastest memory which has faster access time where data is temporarily stored for faster access. It is slower than L1 cache, but its storage capacity is more, i-e. From 64 Kb to 16 MB.

3. Level 3 (L3) Cache : L3 cache is typically specialized memory that works to improve the performance of L1 and L2. It can be significantly slower than L1 or L2, but is usually double the speed of RAM. This cache is separate from processor chip on the motherboard. It exists on the computer that uses L2 advanced transfer cache. In the case of multicore processors, each core may have its own dedicated L1 and L2 cache, but share a common L3 cache.

Cache Memory Principles : 

When the CPU required a word to perform operation, it first sees in the cache. If the word is not in the cache then only go to main memory. If a substantial fraction of the words are in the cache, the average access time can be reduced to large amount. On the basis of previous experience conclusion can be drawn that the memory references made in any short time interval, normally use only a small fraction of the total memory is called the locality principle and forms the general concept for all caching systems. The locality of reference property states that over a short interval of time, address generated by a typical program refers to a few localized area of memory repeatedly. So if programs and data which are accessed frequently are placed in a fast memory, the average access time can be reduced. The general idea behind this is that when a word is referenced, then it is with some of its neighbours are brings from the large slow memory into the cache, so that the next time, if it is used, then it can be accessed quickly. A common arrangement of the CPU, Cache and Main memory is shown at below figure :

When the processor needs to read or write a location in main memory, it first checks for a corresponding entry in the cache. If the processor finds that the memory location is in the cache, a cache hit has occurred and data is read from cache and if the processor does not find the memory location in the cache, a cache miss has occurred. A cache miss occurred when reference of word is made in cache and that word is not present in cache. For a cache miss, the cache allocates a new entry and copies in data from main memory, then the request is fulfilled from the contents of the cache. 

According to the locality principle as a guide, main memories and caches are divided into fixed-size blocks. When we are worrying over these blocks inside the cache, they are generally referred to as cache lines. When a cache miss occurs, the entire cache line is loaded from the main memory into the cache, not only the word which we require.

The performance of cache memory is frequently measured in terms of a quantity called Hit ratio. The hit ratio is nothing but the proportion of memory references, which are found already stored in cache. 

We can improve Cache performance using higher cache block size, higher associativity, reduce miss rate, reduce miss penalty, and reduce Reduce the time to hit in the cache.

Next Topic :

No comments:

Post a Comment