Re: AIO / read stream heuristics adjustments for index prefetching

Melanie Plageman <melanieplageman@gmail.com>

From: Melanie Plageman <melanieplageman@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@gmail.com>, Peter Geoghegan <pg@bowt.ie>, Tomas Vondra <tv@fuzzy.cz>, Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: 2026-04-02T21:13:34Z
Lists: pgsql-hackers
On Thu, Apr 2, 2026 at 11:47 AM Andres Freund <andres@anarazel.de> wrote:
>
> > On some level, relying on worker mode overhead feels fragile. If
> > worker overhead decreases—say, by moving to IO worker threads—we won't
> > be able to rely on this to keep the distance to an advantageous level.
>
> I don't see why lower overhead would prevent this from working?

needed_wait has to be true to increase the readahead distance and for
io_uring, when data was in the kernel buffer cache, needed_wait is
false, meaning the distance doesn't increase. Worker mode didn't have
this problem because of overhead. So needed_wait is true for workers.
But, now that we will have combine_distance, I guess we don't need to
rely on workers having overhead. So we are saying that
readahead_distance is completely irrelevant for copying from the
kernel buffer cache and only combine_distance matters for that now,
right?

> > Yea, I think running ahead far enough to get bigger IOs needs to
> > happen and can't be based on the consumer having to wait.
>
> What do you think about the updated patch to achieve that that I posted?

Will post separately.

- Melanie



Commits

  1. aio: io_uring: Trigger async processing for large IOs

  2. read stream: Split decision about look ahead for AIO and combining

  3. read_stream: Move logic about IO combining & issuing to helpers

  4. read_stream: Only increase read-ahead distance when waiting for IO

  5. read_stream: Prevent distance from decaying too quickly

  6. read_stream: Issue IO synchronously while in fast path

  7. aio: io_uring: Allow IO methods to check if IO completed in the background

  8. bufmgr: Return whether WaitReadBuffers() needed to wait