Introduction
Cache Basics Direct Mapped Cache Direct Mapped Example 1 Direct Mapped Example 2 Direct Mapped Problem 1 Direct Mapped Problem 2 Direct Mapped Problem 3 Direct Mapped Problem 4 Direct Mapped Comparators Direct Mapped Disadvantages Direct Mapped Locality Direct Mapped UVM Example Associative Mapped Cache Associative Mapped Problem 1 Associative Mapped Problem 2 Associative Mapped Problem 3 Associative Mapped Problem 4 Set Associative Mapped Cache Set Associative Mapped Comparators Set Associative Mapped Problem 1 Set Associative Mapped Problem 2 Set Associative Mapped Problem 3 Set Associative Mapped Problem 4 Set Associative Mapped Problem 5 Other Mapping Problem - Example 1 Cache Replacement Algorithms LRU Cache Replacement Algorithm FIFO Cache Replacement Algorithm MRU Cache Replacement Algorithm PLRU Cache Replacement Algorithm Round Robin Cache Replacement AlgorithmUVMArena
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.
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.
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.