Locality of Reference
The tendency of a processor to access the same memory block, again and again, is called locality of reference. Mean to say if CPU refers a memory block now or location now then the same memory block or location will be referenced again in the future. In this way hit, chances are increased and the Miss penalty is reduced.
There are two types of Locality of Reference
1. Spatial Locality of Reference
Spatial locality of reference is totally concern with the Space of Cache line.
The Rule of Spatial:
If a word of a block accessed now, then the word adjacent to it of same Block will access the next.
Keeping more words in block affects the spatial locality. Because we load the entire block in cache and if the block contains large no of words in it then a cache hit chances will be increased.
2. Temporal Locality of Reference
It is totally concern with time. Mean to say if the cache is full and we want to add new block in cache then the least recently used block is replaced.
The Rule of Temporal:
If the word is referenced now then the same word of that Block will be referenced again in the future.
LRU is use in the temporal locality.
Tip: CPU generates an address of Byte or word (which exists inside Block) of Main Memory. Then the whole Block (having that Byte or Word from main memory) is copy to Cache Memory. Then CPU gets that byte or word from cache.