Re: AIO / read stream heuristics adjustments for index prefetching
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: Nazir Bilal Yavuz <byavuz81@gmail.com>, pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>, Peter Geoghegan <pg@bowt.ie>,
Tomas Vondra <tv@fuzzy.cz>
Date: 2026-04-03T19:01:13Z
Lists: pgsql-hackers
Hi, On 2026-04-03 12:45:50 -0400, Melanie Plageman wrote: > On Thu, Apr 2, 2026 at 9:33 AM Andres Freund <andres@anarazel.de> wrote: > > > > > + /* > > > + * XXX: Should we actually reduce this at any time other than > > > + * a reset? For now we have to, as this is also a condition > > > + * for re-enabling fast_path. > > > + */ > > > + if (stream->combine_distance > 1) > > > + stream->combine_distance--; > > > > > > I don't think we need to reduce this other than reset. > > > > Hm. I go back and forth on that one :) > > Separate from the fast-path enablement, we also probably want to > decrease combine distance when we decrease readahead_distance because > there is a point where we still want to parallelize the IOs even when > the distance is lower and to do that, we need to make smaller IOs. I'm not sure that's something we really need to worry about at this point. If readahead_distance is so small that it does not allow enough IO concurrency, we will have to wait for IO completion, which in turn will lead to the readahead distance being increased again. I can see some corner cases where this would not suffice, e.g. if you have a rather low pin limit, but I doubt those are relevant in practice? > I'm not sure where this point is, but I wonder if a few 256kB IOs is faster > than 1 1MB IO (could test that with fio actually). Yes, that point definitely exists. But I think the mechanism for that is to configure io_combine_limit at or below the threshold at which even bigger IOs hurt. > I imagine that there is some size where that is true because of > peculiarities in how drives (and cloud storage) issue/break up IOs after > they are a certain size, etc. It's even true for synchronous copies from the kernel page cache, due to some hardware issue I have yet to fully understand. On both Intel and AMD CPUs, unless SMAP is disabled, larger copies from kernel to userspace start to to be substantially slower, somewhere around 1-4MBs per IO. Greetings, Andres Freund
Commits
-
aio: io_uring: Trigger async processing for large IOs
- a9ee66881744 19 (unreleased) landed
-
read stream: Split decision about look ahead for AIO and combining
- 8ca147d582a5 19 (unreleased) landed
-
read_stream: Move logic about IO combining & issuing to helpers
- 434dab76ba76 19 (unreleased) landed
-
read_stream: Only increase read-ahead distance when waiting for IO
- f63ca3379025 19 (unreleased) landed
-
read_stream: Prevent distance from decaying too quickly
- 6e36930f9aaf 19 (unreleased) landed
-
read_stream: Issue IO synchronously while in fast path
- cceb1bf45e3a 19 (unreleased) landed
-
aio: io_uring: Allow IO methods to check if IO completed in the background
- 6e648e353fa0 19 (unreleased) landed
-
bufmgr: Return whether WaitReadBuffers() needed to wait
- 513374a47a71 19 (unreleased) landed