Re: AIO v2.5
Noah Misch <noah@leadboat.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
aio: Fix assertion, clarify README
- 7b98c5536818 18.0 landed
- d3f97fd1dda3 19 (unreleased) landed
-
aio: Fix reference to outdated name
- f20a347e1a61 19 (unreleased) landed
- 95163cbe111c 18.0 landed
-
aio: Fix possible state confusions due to interrupt processing
- acad909321a4 18.0 landed
-
aio: Improve debug logging around waiting for IOs
- 039bfc457e43 18.0 landed
-
aio: Fix crash potential for pg_aios views due to late state update
- 0d9114b7040d 18.0 landed
-
Increase BAS_BULKREAD based on effective_io_concurrency
- 15f0cb26b530 18.0 landed
-
localbuf: Add Valgrind buffer access instrumentation
- 8ab4241b9f4f 18.0 landed
-
aio: Make AIO more compatible with valgrind
- 8e293e689bab 18.0 landed
-
aio: Avoid spurious coverity warning
- 57dec20fd469 18.0 landed
-
tests: Fix incompatibility of test_aio with *_FORCE_RELEASE
- a6285b150ad3 18.0 landed
-
tests: Cope with WARNINGs during failed CREATE DB on windows
- 43dca8a11624 18.0 landed
-
aio: Add errcontext for processing I/Os for another backend
- b3219c69fc1e 18.0 landed
-
aio: Add README.md explaining higher level design
- fdd146a8ef2b 18.0 landed
-
aio: Minor comment improvements
- e19dc74491e6 18.0 landed
-
aio: Add test_aio module
- 93bc3d75d8e1 18.0 landed
-
aio: Add pg_aios view
- 60f566b4f243 18.0 landed
-
docs: Add acronym and glossary entries for I/O and AIO
- 46250cdcb037 18.0 landed
-
Enable IO concurrency on all systems
- 2a5e709e721c 18.0 landed
-
read_stream: Introduce and use optional batchmode support
- ae3df4b34155 18.0 landed
-
docs: Reframe track_io_timing related docs as wait time
- b27f8637ea70 18.0 landed
-
bufmgr: Use AIO in StartReadBuffers()
- 12ce89fd0708 18.0 landed
-
bufmgr: Implement AIO read support
- 047cba7fa0f8 18.0 landed
-
aio: Add WARNING result status
- ef64fe26bad9 18.0 landed
-
Let caller of PageIsVerified() control ignore_checksum_failure
- d445990adc41 18.0 landed
-
pgstat: Allow checksum errors to be reported in critical sections
- b96d3c389755 18.0 landed
-
Add errhint_internal()
- 4244cf687697 18.0 landed
-
localbuf: Track pincount in BufferDesc as well
- d6d8054dc72d 18.0 landed
-
aio, bufmgr: Comment fixes/improvements
- 08ccd56ac765 18.0 landed
-
Fix mis-attribution of checksum failure stats to the wrong database
- dee80024688c 18.0 landed
-
aio: Implement support for reads in smgr/md/fd
- 50cb7505b301 18.0 landed
-
aio: Add io_method=io_uring
- c325a7633fcb 18.0 landed
-
aio: Add liburing dependency
- 8eadd5c73c44 18.0 landed
-
aio: Rename pgaio_io_prep_* to pgaio_io_start_*
- 9469d7fdd2bc 18.0 landed
-
aio: Pass result of local callbacks to ->report_return
- f321ec237a54 18.0 landed
-
aio: Be more paranoid about interrupts
- 96da9050a57a 18.0 landed
-
Redefine max_files_per_process to control additionally opened files
- adb5f85fa5a0 18.0 landed
-
aio: Change prefix of PgAioResultStatus values to PGAIO_RS_
- ca3067cc573d 18.0 landed
-
bufmgr: Improve stats when a buffer is read in concurrently
- 202b12774d09 18.0 landed
-
aio: Add io_method=worker
- 247ce06b883d 18.0 landed
-
aio: Infrastructure for io_method=worker
- 55b454d0e140 18.0 landed
-
aio: Add core asynchronous I/O infrastructure
- da7226993fd4 18.0 landed
-
aio: Basic subsystem initialization
- 02844012b304 18.0 landed
-
tests: Expand temp table tests to some pin related matters
- 1a22a8a0f131 18.0 landed
-
localbuf: Introduce FlushLocalBuffer()
- 4b4d33b9ea9f 18.0 landed
-
localbuf: Introduce TerminateLocalBufferIO()
- dd6f2618f681 18.0 landed
-
localbuf: Fix dangerous coding pattern in GetLocalVictimBuffer()
- fa6af9b25e4b 18.0 landed
-
localbuf: Introduce StartLocalBufferIO()
- 771ba90298e2 18.0 landed
-
localbuf: Introduce InvalidateLocalBuffer()
- 0762a151b0e0 18.0 landed
-
Allow lwlocks to be disowned
- f8d7f29b3e81 18.0 landed
-
Make jsonb casts to scalar types translate JSON null to SQL NULL.
- a5579a90af05 18.0 cited
-
bufmgr/smgr: Don't cross segment boundaries in StartReadBuffers()
- 755a4c10d19d 18.0 landed
-
Use aux process resource owner in walsender
- 57f370247127 18.0 landed
-
bufmgr: Return early in ScheduleBufferTagForWriteback() if fsync=off
- 488f826c729b 18.0 landed
I reviewed everything up to and including "[PATCH v2.12 17/28] aio, bufmgr:
Comment fixes", the last patch before write support.
postgr.es/m/20250326001915.bc.nmisch@google.com covered patches 1-9, and this
email covers patches 10-17. All remaining review comments are minor, so I've
marked the commitfest entry Ready for Committer. If there's anything you'd
like re-reviewed before you commit it, feel free to bring it to my attention.
Thanks for getting the feature to this stage!
On Mon, Mar 24, 2025 at 09:18:06PM -0400, Andres Freund wrote:
> Subject: [PATCH v2.12 10/28] aio: Basic read_stream adjustments for real AIO
> @@ -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?
I think we don't need a different definition. max_ios comes from
effective_io_concurrency and similar settings. The above comment's definition
of max_ios=0 matches that GUC's documented behavior:
The allowed range is
<literal>1</literal> to <literal>1000</literal>, or
<literal>0</literal> to disable issuance of asynchronous I/O requests.
I'll guess the comment meant that "advice disabled" is a no-op for AIO, so we
could reasonably argue to have effective_io_concurrency=0 distinguish itself
from effective_io_concurrency=1 in some different way for AIO. Equally,
there's no hurry to use that freedom to distinguish them.
> Subject: [PATCH v2.12 11/28] read_stream: Introduce and use optional batchmode
> support
> This patch adds an explicit flag (READ_STREAM_USE_BATCHING) to read_stream and
> uses it where appropriate.
I'd also use the new flag on the read_stream_begin_smgr_relation() call in
RelationCopyStorageUsingBuffer(). It uses block_range_read_stream_cb, and
other streams of that callback rightly use the flag.
> + * b) directly or indirectly start another batch pgaio_enter_batchmode()
Needs new wording from end of postgr.es/m/20250325155808.f7.nmisch@google.com
> Subject: [PATCH v2.12 12/28] docs: Reframe track_io_timing related docs as
> wait time
> Subject: [PATCH v2.12 13/28] Enable IO concurrency on all systems
Consider also updating this comment to stop focusing on prefetch; I think
changing that aligns with the patch's other changes:
/*
* How many buffers PrefetchBuffer callers should try to stay ahead of their
* ReadBuffer calls by. Zero means "never prefetch". This value is only used
* for buffers not belonging to tablespaces that have their
* effective_io_concurrency parameter set.
*/
int effective_io_concurrency = DEFAULT_EFFECTIVE_IO_CONCURRENCY;
> -#io_combine_limit = 128kB # usually 1-128 blocks (depends on OS)
> +#io_combine_limit = 128kB # usually 1-32 blocks (depends on OS)
I think "usually 1-128" remains right given:
GUC_UNIT_BLOCKS
#define MAX_IO_COMBINE_LIMIT PG_IOV_MAX
#define PG_IOV_MAX Min(IOV_MAX, 128)
> - On systems without prefetch advice support, attempting to configure
> - any value other than <literal>0</literal> will error out.
> + On systems with prefetch advice support,
> + <varname>effective_io_concurrency</varname> also controls the prefetch distance.
Wrap the last line.
> Subject: [PATCH v2.12 14/28] docs: Add acronym and glossary entries for I/O
> and AIO
> These could use a lot more polish.
To me, it's fine as-is.
> I did not actually reference the new entries yet, because I don't really
> understand what our policy for that is.
I haven't seen much of a policy on that.
> Subject: [PATCH v2.12 15/28] aio: Add pg_aios view
> +retry:
> +
> + /*
> + * There is no lock that could prevent the state of the IO to advance
> + * concurrently - and we don't want to introduce one, as that would
> + * introduce atomics into a very common path. Instead we
> + *
> + * 1) Determine the state + generation of the IO.
> + *
> + * 2) Copy the IO to local memory.
> + *
> + * 3) Check if state or generation of the IO changed. If the state
> + * changed, retry, if the generation changed don't display the IO.
> + */
> +
> + /* 1) from above */
> + start_generation = live_ioh->generation;
> + pg_read_barrier();
Based on the "really started after this function was called" and "no risk of a
livelock here" comments below, I think "retry:" should be here. We don't
want to livelock in the form of chasing ever-growing start_generation numbers.
> + /*
> + * The IO completed and a new one was started with the same ID. Don't
> + * display it - it really started after this function was called.
> + * There be a risk of a livelock if we just retried endlessly, if IOs
> + * complete very quickly.
> + */
> + if (live_ioh->generation != start_generation)
> + continue;
> +
> + /*
> + * The IOs state changed while we were "rendering" it. Just start from
s/IOs/IO's/
> + * scratch. There's no risk of a livelock here, as an IO has a limited
> + * sets of states it can be in, and state changes go only in a single
> + * direction.
> + */
> + if (live_ioh->state != start_state)
> + goto retry;
> + <entry role="catalog_table_entry"><para role="column_definition">
> + <structfield>target</structfield> <type>text</type>
> + </para>
> + <para>
> + What kind of object is the I/O targeting:
> + <itemizedlist spacing="compact">
> + <listitem>
> + <para>
> + <literal>smgr</literal>, I/O on postgres relations
s/postgres relations/relations/ since SGML docs don't use the term "postgres"
that way.
> Subject: [PATCH v2.12 16/28] aio: Add test_aio module
> --- a/src/test/modules/meson.build
> +++ b/src/test/modules/meson.build
> @@ -1,5 +1,6 @@
> # Copyright (c) 2022-2025, PostgreSQL Global Development Group
>
> +subdir('test_aio')
> subdir('brin')
List is alphabetized; please preserve that.
> +++ b/src/test/modules/test_aio/Makefile
> @@ -0,0 +1,26 @@
> +# src/test/modules/delay_execution/Makefile
Update filename in comment.
> +++ b/src/test/modules/test_aio/meson.build
> @@ -0,0 +1,37 @@
> +# Copyright (c) 2022-2024, PostgreSQL Global Development Group
s/2024/2025/
> --- /dev/null
> +++ b/src/test/modules/test_aio/t/001_aio.pl
s/ {4}/\t/g on this file. It's mostly \t now, with some exceptions.
> + test_inject_worker('worker', $node_worker);
What do we expect to happen if autovacuum or checkpointer runs one of these
injection points? I'm guessing it would at most make that process fail
without affecting the test outcome. If so, that's fine.
> + $waitfor,);
s/,//
> + # normal handle use
> + psql_like($io_method, $psql, "handle_get_release()",
> + qq(SELECT handle_get_release()),
> + qr/^$/, qr/^$/);
> +
> + # should error out, API violation
> + psql_like($io_method, $psql, "handle_get_twice()",
> + qq(SELECT handle_get_release()),
> + qr/^$/, qr/^$/);
Last two lines are a clone of the previous psql_like() call. I guess this
wants to instead call handle_get_twice() and check for some stderr.
> + "read_rel_block_ll() of $tblname page",
What does "_ll" stand for?
> + # Issue IO without waiting for completion, then exit
> + $psql_a->query_safe(
> + qq(SELECT read_rel_block_ll('tbl_ok', 1, wait_complete=>false);));
> + $psql_a->reconnect_and_clear();
> +
> + # Check that another backend can read the relevant block
> + psql_like(
> + $io_method,
> + $psql_b,
> + "completing read started by exited backend",
I think the exiting backend's pgaio_shutdown() completed it.
> +sub test_inject
This deserves a brief comment on the behaviors being tested, like the previous
functions have. It seems to be about short reads and hard failures like EIO.
> Subject: [PATCH v2.12 17/28] aio, bufmgr: Comment fixes