v12-0014-WIP-read_stream-Issue-IO-synchronously-while-in-.patch

application/octet-stream

Filename: v12-0014-WIP-read_stream-Issue-IO-synchronously-while-in-.patch
Type: application/octet-stream
Part: 10
Message: Re: index prefetching

Patch

Format: format-patch
Series: patch v12-0014
Subject: WIP: read_stream: Issue IO synchronously while in fast path
File+
src/backend/storage/aio/read_stream.c 15 0
From 6650b29bc65e54d4c5030582921c1e9e891cadef Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Tue, 3 Mar 2026 16:25:41 -0500
Subject: [PATCH v12 14/23] WIP: read_stream: Issue IO synchronously while in
 fast path

While in fast-path, execute any IO that we might encounter
synchronously. Because we are, right now, not reading ahead, dispatching any
occasional IO to workers would have the overhead of dispatching to workers,
without any realistic chance of the IO completing before we need it.

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/backend/storage/aio/read_stream.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/backend/storage/aio/read_stream.c b/src/backend/storage/aio/read_stream.c
index e78c3b15a..80067b6e6 100644
--- a/src/backend/storage/aio/read_stream.c
+++ b/src/backend/storage/aio/read_stream.c
@@ -833,6 +833,19 @@ read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
 			if (stream->advice_enabled)
 				flags |= READ_BUFFERS_ISSUE_ADVICE;
 
+			/*
+			 * While in fast-path, execute any IO that we might encounter
+			 * synchronously. Because we are, right now, not reading ahead,
+			 * dispatching any occasional IO to workers would have the
+			 * overhead of dispatching to workers, without any realistic
+			 * chance of the IO completing before we need it. We will switch
+			 * to non-synchronous IO after this.
+			 *
+			 * XXX: Should we do so only for worker, or also io_uring? There's
+			 * not much dispatch overhead with io_uring, compared to worker...
+			 */
+			flags |= READ_BUFFERS_SYNCHRONOUSLY;
+
 			/*
 			 * Pin a buffer for the next call.  Same buffer entry, and
 			 * arbitrary I/O entry (they're all free).  We don't have to
@@ -860,6 +873,8 @@ read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
 			stream->ios_in_progress = 1;
 			stream->ios[0].buffer_index = oldest_buffer_index;
 			stream->seq_blocknum = next_blocknum + 1;
+
+			/* FIXME: it would probably worth issuing readahead here */
 		}
 		else
 		{
-- 
2.53.0