Cache Bypassing: Preventing Low-Reuse Data from Cache
This technique utilizes specialized instructions (like non-temporal hints) or hardware mechanisms to prevent data unlikely to be reused from entering the cache, or to mark it for immediate eviction, thereby preserving valuable cache space for frequently accessed information.
The top 3
- Top 3 x86 Non-Temporal Store Instructions: Intel x86 processors use specific non-temporal store instructions like `MOVNTI`, `MOVNTDQ`, and `_mm_stream_si128` (an intrinsic for `MOVNTDQ` or similar) to bypass the cache. These instructions hint to the CPU that data will not be reused soon, preventing it from polluting the cache and directly writing to memory via write-combining buffers. `MOVNTI` handles general-purpose registers, while `MOVNTDQ` and its variations work with SIMD registers (XMM, YMM, ZMM) for larger data blocks, often requiring 16-byte or greater alignment.
- Write-Combining Buffers: The Hidden Performance Booster: Cache bypassing often leverages Write-Combining (WC) buffers, which are temporary CPU-internal buffers that collect multiple writes to the same cache line before flushing them as a single, larger transaction to main memory, bypassing the cache hierarchy. This reduces memory bandwidth usage by half since the processor doesn't need to fetch the cache line first. Modern Intel CPUs can have 8 to 10 or even 20 such buffers per L1 data cache, facilitating efficient streaming writes to uncached or write-combined memory regions.
- When Cache Bypassing Delivers Peak Performance: Cache bypassing is most effective for workloads characterized by streaming data, large sequential writes, or data with low temporal locality, such as filling large matrices, video processing, or transferring buffers between CPU and GPU. These scenarios benefit because avoiding cache allocation prevents useful data from being evicted and reduces memory bandwidth pressure. However, misuse can lead to severe performance degradation if data is unexpectedly reused or if non-temporal stores are mixed with regular stores to the same cache line.
Sources
Open the full topic