Refine RAID stride noise documentation

This commit is contained in:
Andrea Mazzoleni 2026-08-12 16:07:57 +02:00
parent bce4965998
commit 6cd3f94c39

View file

@ -48,46 +48,47 @@ unsigned raid_optimal_displacement(int n)
#define RAID_WRAP_SIZE 4096 #define RAID_WRAP_SIZE 4096
/* /*
* PREFETCHER MITIGATION VIA PAGE-OFFSET RANDOMIZATION (WAY-SHIFTING) * PREFETCHER MITIGATION WITH 4K STRIDE PERTURBATION
* *
* STRIDE_NOISE is a sequence of small, non-linear multipliers used to inject * STRIDE_NOISE is a sequence of small, non-linear multipliers used to add
* variable byte offsets into the physical distance between consecutive disk * variable 4096-byte increments to the virtual distance between consecutive
* buffers during allocation. These multipliers are applied in 4096-byte chunks. * disk buffers during allocation.
* *
* The parity generation loops contain a massive cross-disk jump in the inner * The parity generation loops repeatedly access corresponding offsets in each
* loop. If the distance between every disk is a constant delta (e.g., exactly * disk buffer. If the distance between buffers is constant, the inner loop
* 256KB + fixed displacement bytes), modern IP-based stride prefetchers * produces a regular cross-buffer stride in addition to the unit-stride access
* (particularly on architectures like AMD Zen 5) will easily recognize the pattern. * within each buffer. A two-dimensional prefetcher can recognize this access
* pattern as a regular grid of disk buffers and offsets.
* *
* Because the prefetcher is biased to aggressively accelerate constant positive * This additional prefetching is not necessarily useful. The cross-buffer
* strides, it incorrectly assumes the program is executing a massive linear * accesses already form independent forward streams, and excessive look-ahead
* sweep of memory. It begins flooding the memory controller with speculative, * can cause cache pollution or pressure on cache-fill and memory-request
* useless requests for data far beyond the active disks. This "garbage traffic" * resources.
* saturates the memory bus, starving the AVX/SIMD execution engine of
* the actual data it needs and crippling throughput.
* *
* We must blind the prefetcher by making the stride unpredictable, but we CANNOT * raid_optimal_displacement() provides the fixed displacement that separates
* alter the carefully calculated L1 cache set mapping (raid_optimal_displacement), * buffer starts among L1 cache sets. This cache-set separation is the most
* otherwise we will cause catastrophic L1 cache thrashing. * likely cause of the broad performance improvement over contiguous buffers.
* STRIDE_NOISE is an additional perturbation and must retain that mapping.
* *
* - The standard x86 L1 data cache has 64 sets, and a cache line is 64 bytes. * On common x86 L1 data caches there are 64 sets and cache lines are 64 bytes.
* A full wrap-around of the L1 cache is exactly 64 * 64 = 4096 bytes (which * A full set-index cycle is therefore 64 * 64 = 4096 bytes, which also matches
* also perfectly aligns with a standard 4KB memory page). * the usual memory-page size.
* *
* - By adding a random multiple of 4096 bytes to our jump: * By adding a varying multiple of 4096 bytes to the buffer spacing:
* 1. The physical memory address changes wildly, breaking the constant stride.
* 2. The modulo-64 cache math is completely unaffected ((X + 4096) % 64 == X % 64).
* *
* The IP-based stride prefetcher monitors the cross-disk jumps and sees a * 1. The virtual cross-buffer stride varies instead of remaining constant.
* chaotic sequence of massive, fluctuating deltas (e.g., +275KB, +267KB, +288KB). * 2. The L1 set index is unchanged because adding 4096 bytes preserves address
* Because the stride is never constant, the prefetcher's internal confidence * bits 6 through 11.
* counter never builds up. The prefetcher safely disables itself for the inner
* loop.
* *
* With the noisy prefetcher silenced, the memory bus is cleared. The CPU's L2 * STRIDE_NOISE is deterministic, not random. Its non-uniform sequence can make
* stream prefetcher is left alone to perfectly track the independent +64 byte * the cross-buffer pattern less suitable for stride-based prediction while
* forward reads for each individual disk. The AVX/SIMD execution engine receives * leaving the sequential access pattern of each buffer unchanged.
* 100% of the bandwidth, yielding maximum physical throughput. *
* With the fixed displacement already applied, STRIDE_NOISE had no material
* effect on the tested Intel processor. On Zen 5, which has a two-dimensional
* prefetcher, disabling it caused a large throughput reduction. This points to
* two-dimensional prefetching as the likely trigger, rather than to an Intel
* or AMD vendor difference.
* *
* These are the results in MB/s with no stride noise on a Zen 5 CPU: * These are the results in MB/s with no stride noise on a Zen 5 CPU:
* *