Skip to main content

Module prefetch

Module prefetch 

Source
Expand description

Telling the cache what the next walk is going to want.

04 section 3 walks a drained batch twice. The first walk works out which index bucket each command will land in and asks for that line; the second walk executes, and by then the line is on its way or already there. The whole batch is the prefetch distance, which is 64 rather than Valkey’s or Redis 8.4’s 16, because Y1 means there is no lock held across the window and no other thread that can invalidate a bucket between the ask and the use.

There is no stable portable intrinsic for this, so there are three implementations here and they are all one instruction. x86_64 gets prefetcht0, aarch64 gets prfm pldl1keep, and anything else gets nothing at all, because a hint that has to be emulated is not a hint. Miri also gets nothing, since it does not run inline assembly and there is no correctness in here for it to check.

Functions§

prefetch
The same hint for a reference, which is the shape the call sites have.
prefetch_read
Ask for the cache line at p, for reading, into every level of cache.