diff options
author | Andres Freund <andres@anarazel.de> | 2025-03-18 14:40:05 -0400 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2025-03-26 19:49:13 -0400 |
commit | c325a7633fcb33dbd73f46ddbbe91e95ddf3b227 (patch) | |
tree | 0aa7ab5b32bd5dd26eef0aff6b4d4b200a771d75 /src/backend/storage/aio/aio.c | |
parent | 8eadd5c73c44708ecd45b9fd3ac54a550511d16f (diff) | |
download | postgresql-c325a7633fcb33dbd73f46ddbbe91e95ddf3b227.tar.gz postgresql-c325a7633fcb33dbd73f46ddbbe91e95ddf3b227.zip |
aio: Add io_method=io_uring
Performing AIO using io_uring can be considerably faster than
io_method=worker, particularly when lots of small IOs are issued, as
a) the context-switch overhead for worker based AIO becomes more significant
b) the number of IO workers can become limiting
io_uring, however, is linux specific and requires an additional compile-time
dependency (liburing).
This implementation is fairly simple and there are substantial optimization
opportunities.
The description of the existing AIO_IO_COMPLETION wait event is updated to
make the difference between it and the new AIO_IO_URING_EXECUTION clearer.
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Jakub Wartak <jakub.wartak@enterprisedb.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/backend/storage/aio/aio.c')
-rw-r--r-- | src/backend/storage/aio/aio.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/backend/storage/aio/aio.c b/src/backend/storage/aio/aio.c index 116bf97d3ef..91e76113412 100644 --- a/src/backend/storage/aio/aio.c +++ b/src/backend/storage/aio/aio.c @@ -65,6 +65,9 @@ static void pgaio_io_wait(PgAioHandle *ioh, uint64 ref_generation); const struct config_enum_entry io_method_options[] = { {"sync", IOMETHOD_SYNC, false}, {"worker", IOMETHOD_WORKER, false}, +#ifdef IOMETHOD_IO_URING_ENABLED + {"io_uring", IOMETHOD_IO_URING, false}, +#endif {NULL, 0, false} }; @@ -82,6 +85,9 @@ PgAioBackend *pgaio_my_backend; static const IoMethodOps *const pgaio_method_ops_table[] = { [IOMETHOD_SYNC] = &pgaio_sync_ops, [IOMETHOD_WORKER] = &pgaio_worker_ops, +#ifdef IOMETHOD_IO_URING_ENABLED + [IOMETHOD_IO_URING] = &pgaio_uring_ops, +#endif }; /* callbacks for the configured io_method, set by assign_io_method */ @@ -1118,6 +1124,41 @@ pgaio_closing_fd(int fd) * it's probably not worth it. */ pgaio_submit_staged(); + + /* + * If requested by the IO method, wait for all IOs that use the + * to-be-closed FD. + */ + if (pgaio_method_ops->wait_on_fd_before_close) + { + /* + * As waiting for one IO to complete may complete multiple IOs, we + * can't just use a mutable list iterator. The maximum number of + * in-flight IOs is fairly small, so just restart the loop after + * waiting for an IO. + */ + while (!dclist_is_empty(&pgaio_my_backend->in_flight_ios)) + { + dlist_iter iter; + PgAioHandle *ioh = NULL; + + dclist_foreach(iter, &pgaio_my_backend->in_flight_ios) + { + ioh = dclist_container(PgAioHandle, node, iter.cur); + + if (pgaio_io_uses_fd(ioh, fd)) + break; + else + ioh = NULL; + } + + if (!ioh) + break; + + /* see comment in pgaio_io_wait_for_free() about raciness */ + pgaio_io_wait(ioh, ioh->generation); + } + } } /* |