Locality of reference and its type — Cache Memory !

Aditya Kumar
2 min readApr 30, 2020

Cache memory is faster and a chip-based computer component that makes retrieving data from the computer’s memory more efficient. It acts as a temporary storage area that the computer’s processor can retrieve data from easily. It stores copies of the data from frequently used main memory locations. Cache memory acts as a buffer between RAM and the CPU.

CPU  ⇄  Cache(L1,L2,L3) ⇄ Main Memory

We know the size of cache memory is less as compared to main memory. So to check which part of main memory should be given priority and loaded in cache is decided based on locality of reference also known as the principle of locality.

Types of Locality of reference

Spatial Locality of reference : It states that if a data object is referenced once, then there is a high probability that its neighbour data objects will also be referenced in near future. This says that there is a chance that element will be present in the proximity to the reference point and next time if again searched then more close proximity to the point of reference.

Temporal Locality of reference : Temporal locality states that, the same data objects are likely to be reused multiple times by the CPU during the execution of a program. Once a data object has been written into the cache on the first miss, several subsequent hits on that object can be expected. In this Least recently used algorithm will be used. Whenever there is page fault occurs within a word will not only load word in main memory but complete page fault will be loaded because spatial locality of reference rule says that if you are referring any word next word will be referred in its register that’s why we load complete page table so the complete block will be loaded.

There are two more type of locality of reference but that is less occurring case. That is Branch Locality and Equidistant Locality.

Cache Performance

The performance of the cache is measured in terms of Hit Ratio. When CPU refers to memory and find the data or instruction within the Cache Memory, it is known as cache hit. The very first time when CPU tries to find data in cache then there is sure miss. This miss is called Compulsory miss. If the desired data or instruction is not found in the cache memory and CPU refers to the main memory to find that data or instruction, it is known as a cache miss.

Hit Ratio = Hit / (Hit+Miss)

Thanks 😊

--

--

Aditya Kumar
0 Followers

Main Hu 5 Saal Ka Shinchan Nohara. Kya Apko Capsicum Pasand Hai ? 💁🏻