diff options
author | Andres Freund <andres@anarazel.de> | 2025-03-30 18:02:23 -0400 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2025-03-30 18:02:23 -0400 |
commit | 12ce89fd0708207f21a8888e546b9670a847ad4f (patch) | |
tree | 2f96a1a77b53efab20c79ee782a1a1df9b567912 /src/include/storage/bufmgr.h | |
parent | 047cba7fa0f8c6930b0dd1d93d98c736ef1e4a5a (diff) | |
download | postgresql-12ce89fd0708207f21a8888e546b9670a847ad4f.tar.gz postgresql-12ce89fd0708207f21a8888e546b9670a847ad4f.zip |
bufmgr: Use AIO in StartReadBuffers()
This finally introduces the first actual use of AIO. StartReadBuffers() now
uses the AIO routines to issue IO.
As the implementation of StartReadBuffers() is also used by the functions for
reading individual blocks (StartReadBuffer() and through that
ReadBufferExtended()) this means all buffered read IO passes through the AIO
paths. However, as those are synchronous reads, actually performing the IO
asynchronously would be rarely beneficial. Instead such IOs are flagged to
always be executed synchronously. This way we don't have to duplicate a fair
bit of code.
When io_method=sync is used, the IO patterns generated after this change are
the same as before, i.e. actual reads are only issued in WaitReadBuffers() and
StartReadBuffers() may issue prefetch requests. This allows to bypass most of
the actual asynchronicity, which is important to make a change as big as this
less risky.
One thing worth calling out is that, if IO is actually executed
asynchronously, the precise meaning of what track_io_timing is measuring has
changed. Previously it tracked the time for each IO, but that does not make
sense when multiple IOs are executed concurrently. Now it only measures the
time actually spent waiting for IO. A subsequent commit will adjust the docs
for this.
While AIO is now actually used, the logic in read_stream.c will often prevent
using sufficiently many concurrent IOs. That will be addressed in the next
commit.
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Co-authored-by: Andres Freund <andres@anarazel.de>
Co-authored-by: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt
Discussion: https://postgr.es/m/20210223100344.llw5an2aklengrmn@alap3.anarazel.de
Discussion: https://postgr.es/m/stj36ea6yyhoxtqkhpieia2z4krnam7qyetc57rfezgk4zgapf@gcnactj4z56m
Diffstat (limited to 'src/include/storage/bufmgr.h')
-rw-r--r-- | src/include/storage/bufmgr.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index 11f8508a90b..867ae9facb5 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -114,6 +114,9 @@ typedef struct BufferManagerRelation #define READ_BUFFERS_ISSUE_ADVICE (1 << 1) /* Don't treat page as invalid due to checksum failures. */ #define READ_BUFFERS_IGNORE_CHECKSUM_FAILURES (1 << 2) +/* IO will immediately be waited for */ +#define READ_BUFFERS_SYNCHRONOUSLY (1 << 3) + struct ReadBuffersOperation { @@ -133,6 +136,9 @@ struct ReadBuffersOperation BlockNumber blocknum; int flags; int16 nblocks; + int16 nblocks_done; + PgAioWaitRef io_wref; + PgAioReturn io_return; }; typedef struct ReadBuffersOperation ReadBuffersOperation; |