Optimal Cache Line Size: Trade-offs of Larger vs. Smaller
The 64-byte cache line represents a critical trade-off: smaller lines reduce wasted data but increase tag overhead and require more main memory accesses for sequential data, while larger lines reduce tag overhead and improve sequential access but increase memory traffic for random access and exacerbate false sharing.
The top 3
- Why 64 Bytes Dominates CPU Cache Lines: The 64-byte cache line size became prevalent in x86 processors due to its optimal balance: it leverages spatial locality by fetching enough nearby data for most workloads while minimizing tag overhead and the risk of fetching excessive unused data, forming a 'chicken-and-egg' standardization between hardware and software design.
- False Sharing: Larger Cache Lines' Performance Trap: Larger cache lines can lead to 'false sharing,' a significant performance pitfall where multiple threads working on logically independent data located within the same cache line cause constant, unnecessary cache invalidations and reloads across CPU cores. This happens even if threads aren't directly sharing data but modify different parts of the same cache line.
- Smaller Cache Lines: Increased Overhead, Reduced Spatial Locality: Opting for smaller cache lines introduces trade-offs, primarily by reducing the exploitation of spatial locality—meaning fewer nearby addresses are fetched, leading to more cache misses for sequential data access. Additionally, smaller lines increase overhead due to a higher number of tags required to manage the same amount of cached data, as each line needs its own tag.
Sources
Open the full topic