r/programming 1d ago

io_uring without readahead

https://frn.sh/io-uring/
44 Upvotes

1 comment sorted by

1

u/farnoy 7h ago

In a buffered read, the kernel copies the data from the page cache to the process buffer, and this copy uses the CPU. The copy has a side effect: the data ends up warm in the CPU caches. O_DIRECT skips the copy, but the data still has to reach the CPU at some point. In the buffered read, that happens during the copy. With O_DIRECT, it happens during the query, as cache misses.

I think you can just do that yourself, and better than the kernel for two reasons I can see:

  1. The kernel's copy has twice the cache footprint, since it touches two regions - source and destination.
  2. You know the query plan, so you'd warm up the cache when you predict it's worth doing. Like for a seq scan that will go through most of that page anyway. If the logical order of rows doesn't correlate with physical offsets within the page, an explicit prefetch could help if it converts a low-MLP random access pattern into a simpler streaming read.