Thursday, May 3, 2012

Cache memory animation

The cache memory is defined as the first level of memory after an address encounters after it leaves the processor. In the memory hierarchy, it is placed right below the processor registers as shown in the figure below.

The following animation shows the traversal of address along the memory hierarchy.



The higher the data is found in the hierarchy the faster it can be fetched by the processor.

The cache is generally made up of SRAM because of the high speed of operation of SRAMs and the faster a cache operates, faster data can be made available to the processor for processing.

The cache stores in it the data of memory locations that the processor uses repeatably or is expected to use very soon in future. When the processor wants to access data of a certain memory location, the data might be present in cache or not, this is defined by the terms cache hit and cache miss respectively.

Note: In the examples below we assume the cache to be made of 8 blocks and main memory to be made of 32 blocks.
A block is the minimum amount of memory that is accessed in on operation, it could be one byte or one word etc depending on the design of the cache.


Cache miss: When the processor does not find, the memory location which it wants to access, stored in the cache it has to fetch the data from the main memory. As the data is missing in the cache this is termed as a cache miss. The following animation depicts a cache hit



Cache hit: On the other hand if the memory location is present in the cache, processor can fetch the data from cache itself and need not go to the main memory to fetch it. This is termed as a cache hit. The following animation depicts a cache miss.



The design of applications as well as the cache should always aim to achieve as high a cache hit ratio as possible.

To able to store the data in the cache in such way as to maximize the cache hit two principles are made use of, temporal locality and spatial locality.

Temporal locality : A memory location accessed once will be accessed again soon and hence need to be stored close to the processor.
The following animation depicts the working of temporal locality



Spatial locality : The memory locations around the memory that the processor accesses might also be accessed by the processor soon and hence need to stored close the processor in the cache.
The following animation depicts the working of spatial locality.




No comments:

Post a Comment

Follow by Email