Cache Lines: Spatial Locality's Core
Modern CPUs fetch entire "cache lines" (typically 64 bytes) from memory, not just individual bytes. This design directly exploits spatial locality by anticipating subsequent requests for adjacent data, dramatically reducing access latency for nearby memory locations.
The top 3
- Most Common Cache Line Sizes: Modern CPUs predominantly use a 64-byte cache line size, a choice that balances fetching enough data to exploit spatial locality without bringing in excessive unused data. While 64 bytes is standard for x86_64 and ARM64, some architectures like Apple's M-series chips and IBM Power systems may use 128-byte lines, and s390x can use 256-byte lines.
- Cache Line Alignment's Top Performance Gains: Aligning data structures to cache line boundaries (typically 64 bytes) can significantly boost performance by ensuring that a single memory access fetches only relevant data, reducing cache misses. Misaligned data can force the CPU to fetch multiple cache lines or split accesses, leading to performance degradation of over 100% in some vectorized operations.
- False Sharing: The #1 Cache Line Performance Trap: False sharing, a notorious performance bottleneck in multi-threaded applications, occurs when unrelated data items, accessed by different cores, happen to reside within the same cache line, causing constant, unnecessary cache invalidations and costly synchronization overhead.
Sources
Open the full topic