On Mon, Oct 26, 2026 at 8:34 AM Jeremy Schneider <[email protected]>
wrote:

>
> On the primary, even on v16 and older without io_uring and the read_stream
> API, I suspect postgres is making calls to the OS that allow the linux
> kernel to detect sequential reads and perform OS readahead.
>
> I haven't spent much time with Linux kernel source code but AI is telling
> me that POSIX_FADV_WILLNEED (used in fd.c FilePrefetch) explicitly does not
> work with Linux OS level read-ahead.
>
> ...

>
>     /*
>     * standalone, small random read
>     * Read as is, and do not pollute the readahead state.
>     */
>     do_page_cache_ra(ractl, req_size, 0);
>
> ...

>
> Might be worth some testing to see if OS readahead is happening on
> replicas when prefetch is disabled - I didnt check this yet.
>

>From a bit of poking around today, I think that replicas do get OS
readahead when prefetch is disabled. I also think that visibility map and
FSM reads were the largest cause of replica reads when prefetch was
disabled (these don't get FPIs), and I think FSM in particular was
triggering linux readahead.  Don't have anything clean enough to publish
yet though.

One thing I wonder is if its worth discussing with Linux kernel maintainers
that there is a use case for a prefetch (WILLNEED) that doesnt disable
readahead.

On the other hand, maybe if replica prefetch could read ahead far enough
then it might be able to use io_uring/read_stream itself to batch a bunch
of sequential reads?  I haven't looked at any actual data yet.  Maybe
that's unrealistic.

-Jeremy

-- 
http://about.me/jeremy_schneider

Reply via email to