Hi, While working on something else in the AIO code I noticed that FileStartReadV() accepts a wait_event_info argument but never passes it. Instead pgaio_io_perform_synchronously() hardcodes the wait event to WAIT_EVENT_DATA_FILE_READ, so a wait event supplied by the caller is silently ignored.
This is not a live bug today. The only caller of FileStartReadV() is md.c, and it passes exactly the WAIT_EVENT_DATA_FILE_READ that is hardcoded anyway; pgaio_io_start_writev() has no callers at all yet. Fix this by storing the wait event in PgAioOpData and reporting it. -- Regards, Nazir Bilal Yavuz Microsoft
From a34d9458caf40293144f0914b90b4a10819041da Mon Sep 17 00:00:00 2001 From: Nazir Bilal Yavuz <[email protected]> Date: Wed, 19 Aug 2026 11:28:18 +0300 Subject: [PATCH v1] aio: Don't silently drop wait_event_info FileStartReadV() accepts a wait_event_info argument but never passes it. Instead pgaio_io_perform_synchronously() hardcodes WAIT_EVENT_DATA_FILE_READ and WAIT_EVENT_DATA_FILE_WRITE, so a wait event supplied by the caller is silently ignored. This is not a live bug today: the only caller of FileStartReadV() is md.c, which passes exactly the wait event that is hardcoded, and pgaio_io_start_writev() has no callers at all. It would become one as soon as AIO is used for files other than relation data files. Fix this by storing the wait event in PgAioOpData and reporting it. --- src/backend/storage/aio/aio_io.c | 12 ++++++++---- src/backend/storage/file/fd.c | 2 +- src/include/storage/aio.h | 9 +++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/backend/storage/aio/aio_io.c b/src/backend/storage/aio/aio_io.c index 132868130e7..5e0b332b319 100644 --- a/src/backend/storage/aio/aio_io.c +++ b/src/backend/storage/aio/aio_io.c @@ -76,26 +76,30 @@ pgaio_io_get_op_data(PgAioHandle *ioh) void pgaio_io_start_readv(PgAioHandle *ioh, - int fd, int iovcnt, uint64 offset) + int fd, int iovcnt, uint64 offset, + uint32 wait_event_info) { pgaio_io_before_start(ioh); ioh->op_data.read.fd = fd; ioh->op_data.read.offset = offset; ioh->op_data.read.iov_length = iovcnt; + ioh->op_data.read.wait_event_info = wait_event_info; pgaio_io_stage(ioh, PGAIO_OP_READV); } void pgaio_io_start_writev(PgAioHandle *ioh, - int fd, int iovcnt, uint64 offset) + int fd, int iovcnt, uint64 offset, + uint32 wait_event_info) { pgaio_io_before_start(ioh); ioh->op_data.write.fd = fd; ioh->op_data.write.offset = offset; ioh->op_data.write.iov_length = iovcnt; + ioh->op_data.write.wait_event_info = wait_event_info; pgaio_io_stage(ioh, PGAIO_OP_WRITEV); } @@ -124,14 +128,14 @@ pgaio_io_perform_synchronously(PgAioHandle *ioh) switch ((PgAioOp) ioh->op) { case PGAIO_OP_READV: - pgstat_report_wait_start(WAIT_EVENT_DATA_FILE_READ); + pgstat_report_wait_start(ioh->op_data.read.wait_event_info); result = pg_preadv(ioh->op_data.read.fd, iov, ioh->op_data.read.iov_length, ioh->op_data.read.offset); pgstat_report_wait_end(); break; case PGAIO_OP_WRITEV: - pgstat_report_wait_start(WAIT_EVENT_DATA_FILE_WRITE); + pgstat_report_wait_start(ioh->op_data.write.wait_event_info); result = pg_pwritev(ioh->op_data.write.fd, iov, ioh->op_data.write.iov_length, ioh->op_data.write.offset); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 190c9974494..9044d01a674 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -2222,7 +2222,7 @@ FileStartReadV(PgAioHandle *ioh, File file, vfdP = &VfdCache[file]; - pgaio_io_start_readv(ioh, vfdP->fd, iovcnt, offset); + pgaio_io_start_readv(ioh, vfdP->fd, iovcnt, offset, wait_event_info); return 0; } diff --git a/src/include/storage/aio.h b/src/include/storage/aio.h index ec543b78409..53ace239a91 100644 --- a/src/include/storage/aio.h +++ b/src/include/storage/aio.h @@ -138,6 +138,7 @@ typedef union int fd; uint16 iov_length; uint64 offset; + uint32 wait_event_info; } read; struct @@ -145,6 +146,7 @@ typedef union int fd; uint16 iov_length; uint64 offset; + uint32 wait_event_info; } write; } PgAioOpData; @@ -297,9 +299,12 @@ extern PgAioOp pgaio_io_get_op(PgAioHandle *ioh); extern PgAioOpData *pgaio_io_get_op_data(PgAioHandle *ioh); extern void pgaio_io_start_readv(PgAioHandle *ioh, - int fd, int iovcnt, uint64 offset); + int fd, int iovcnt, uint64 offset, + uint32 wait_event_info); extern void pgaio_io_start_writev(PgAioHandle *ioh, - int fd, int iovcnt, uint64 offset); + int fd, int iovcnt, uint64 offset, + uint32 wait_event_info); + /* functions in aio_target.c */ extern void pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid); -- 2.47.3
