agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Andres Freund <andres@anarazel.de>
Subject: [PATCH v2.12 10/28] aio: Basic read_stream adjustments for real AIO
Date: Tue, 18 Mar 2025 14:40:06 -0400
Adapt the read stream logic for real AIO:
- If AIO is enabled, we shouldn't issue advice, but if it isn't, we should
continue issuing advice
- AIO benefits from reading ahead with direct IO
There is one comment talking about max_ios logic with "real asynchronous I/O"
that I am not sure about, so I left it alone for now.
There are further improvements we should consider:
- While in read_stream_look_ahead(), we can use AIO batch submission mode for
increased efficiency
- We could wait to issue IOs until we can issue multiple IOs at once
---
src/backend/storage/aio/read_stream.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/backend/storage/aio/read_stream.c b/src/backend/storage/aio/read_stream.c
index c60e37e7f7f..df16530d673 100644
--- a/src/backend/storage/aio/read_stream.c
+++ b/src/backend/storage/aio/read_stream.c
@@ -72,6 +72,7 @@
#include "postgres.h"
#include "miscadmin.h"
+#include "storage/aio.h"
#include "storage/fd.h"
#include "storage/smgr.h"
#include "storage/read_stream.h"
@@ -99,6 +100,7 @@ struct ReadStream
int16 pinned_buffers;
int16 distance;
int16 initialized_buffers;
+ bool sync_mode; /* using io_method=sync */
bool advice_enabled;
bool temporary;
@@ -613,15 +615,19 @@ read_stream_begin_impl(int flags,
stream->per_buffer_data = (void *)
MAXALIGN(&stream->ios[Max(1, max_ios)]);
+ stream->sync_mode = io_method == IOMETHOD_SYNC;
+
#ifdef USE_PREFETCH
/*
- * This system supports prefetching advice. We can use it as long as
- * direct I/O isn't enabled, the caller hasn't promised sequential access
- * (overriding our detection heuristics), and max_ios hasn't been set to
- * zero.
+ * This system supports prefetching advice.
+ *
+ * Issue advice only if AIO is not used, direct I/O isn't enabled, the
+ * caller hasn't promised sequential access (overriding our detection
+ * heuristics), and max_ios hasn't been set to zero.
*/
- if ((io_direct_flags & IO_DIRECT_DATA) == 0 &&
+ if (stream->sync_mode &&
+ (io_direct_flags & IO_DIRECT_DATA) == 0 &&
(flags & READ_STREAM_SEQUENTIAL) == 0 &&
max_ios > 0)
stream->advice_enabled = true;
@@ -631,6 +637,9 @@ read_stream_begin_impl(int flags,
* For now, max_ios = 0 is interpreted as max_ios = 1 with advice disabled
* above. If we had real asynchronous I/O we might need a slightly
* different definition.
+ *
+ * FIXME: Not sure what different definition we would need? I guess we
+ * could add the READ_BUFFERS_SYNCHRONOUSLY flag automatically?
*/
if (max_ios == 0)
max_ios = 1;
--
2.48.1.76.g4e746b1a31.dirty
--5i73spx2p4vwf7fe
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="v2.12-0011-read_stream-Introduce-and-use-optional-batchmo.patch"
view thread (8+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: andres@anarazel.de
Subject: Re: [PATCH v2.12 10/28] aio: Basic read_stream adjustments for real AIO
In-Reply-To: <no-message-id-50304@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox