What is Cache Miss
A cache miss occurs when the data or information a program requests is not found in the cache memory. Instead, the system must retrieve it from a slower storage location, typically the main memory, random access memory (RAM), or even disk storage.Â
A cache is a smaller, faster type of volatile computer memory that stores copies of frequently accessed data or instructions. It acts as a high-speed buffer between the processor and the slower RAM. Caches are used to reduce the time it takes to access data or instructions that are repeatedly needed by the CPU.
The CPU first checks the cache memory when it requests data or instructions. If the data is found in the cache (a cache hit), the CPU can access it quickly because the cache memory operates at a much faster speed than the main memory. However, if the requested data is not found in the cache (a miss), the CPU must fetch it from the slower memory.
Types of cache misses
There are several types of cache misses:
Cold miss / Compulsory miss: Occurs when the data being requested has never been accessed before, so it’s not present in the cache. This kind of miss cannot be avoided.Â
Conflict miss / Collision miss: This happens when multiple data items accessed sequentially are mapped to the same cache location and designated as a cache set. This form of miss stems from the cache’s arrangement – in set-associative or direct-mapped caches, distinct data items may share a set, resulting in conflicts. When a new item is introduced into a saturated set, another item must be displaced, resulting in a miss if the displaced item is accessed subsequently.
Capacity miss: This occurs when the cache needs more capacity to hold all the required data for the system. This happens when the working set, representing the data frequently accessed by a program, surpasses the cache’s size. As the cache reaches its full capacity and attempts to accommodate a new data item, current data must be displaced, resulting in a miss.
Instruction cache miss refers to a cache miss in the instruction cache, where the CPU cannot find the instructions it needs to execute.
Data cache miss: Refers to a cache miss in the data cache, where the CPU cannot find the data it needs for processing.
Coherence miss: These are exclusive to multiprocessor systems, where multiple processors possess individual caches and access shared data. Such a miss arises when one processor modifies a data item in its private cache, rendering the corresponding data item in another processor’s cache outdated.
The Impact of Cache Misses on Performance
Cache misses have a significant impact on system performance. Whenever a cache miss occurs, the system is compelled to retrieve the desired data from the main memory or another cache at a lower level, which is inherently slower than fetching data from the cache. This delay can lead to a bottleneck in performance, particularly in systems where rapid operations are critical.
For this reason, minimizing cache misses is essential for improving overall system performance in applications where performance is critical, such as real-time systems or high-performance computing.
The frequency of cache misses is due to several factors, including cache size, organization, replacement policy, and data access patterns. Therefore, understanding and effectively avoiding cache miss penalties is an important facet of optimizing system performance.
It is important to note that only some cache misses take the exact toll. For instance, a cache miss stemming from the initial access to a block of data (compulsory miss) is inevitable. On the other hand, cache misses stemming from data displacement for different data (capacity miss) or conflicts in cache placement policies (conflict miss) can be alleviated through meticulous algorithms and system design.