UVMArena

Locality of Reference in Cache Memory

Locality of Reference is an important concept used in cache memory design. It describes the common behavior of programs when accessing memory. Instead of accessing random memory locations, programs tend to access the same data or nearby data repeatedly.

Because of this behavior, when the CPU requests data from memory, the system moves an entire page (or block) from RAM to cache even if the CPU only requested a single byte.

This design is based on two observations known as locality principles.


1. Spatial Locality

Spatial locality means that if the CPU accesses a particular memory location, there is a high probability that it will soon access memory locations that are close to it.

If a byte is accessed, nearby bytes are likely to be accessed soon.

Because of spatial locality, when a cache miss occurs the system loads the entire page or block from RAM into cache instead of loading only the requested byte.

This reduces future memory accesses to RAM because nearby bytes are already available in cache.


2. Temporal Locality

Temporal locality means that if a particular memory location is accessed now, there is a high chance that the same location will be accessed again in the near future.

If the CPU accesses a byte once, it is likely to access the same byte again soon.

Keeping recently accessed data in cache helps reduce memory access time because the CPU can quickly retrieve the same data again without going to RAM.


Summary

  • Locality of Reference describes common patterns in memory access.
  • Spatial Locality: nearby memory locations are likely to be accessed soon.
  • Temporal Locality: recently accessed data is likely to be accessed again.
  • Because of these principles, cache memory transfers entire blocks/pages instead of single bytes.