postgresql/src/backend
Andres Freund 999dec9ec6 aio: Don't wait for already in-progress IO
When a backend attempts to start a read IO and finds the first buffer already
has I/O in progress, previously it waited for that I/O to complete before
initiating reads for any of the subsequent buffers.

Although it must wait for the I/O to finish when acquiring the buffer, there's
no reason for it to wait when setting up the read operation. Waiting at this
point prevents starting I/O on subsequent buffers and can significantly reduce
concurrency.

This matters in two workloads:
1) When multiple backends scan the same relation concurrently.
2) When a single backend requests the same block multiple times within the
   readahead distance.

Waiting each time an in-progress read is encountered effectively degenerates
the access pattern into synchronous I/O.

To fix this, when encountering an already in-progress IO for the head buffer,
the wait reference is now recorded and waiting is deferred until
WaitReadBuffers(), when the buffer actually needs to be acquired.

In rare cases, a backend may still need to wait synchronously at IO
start time: If another backend has set BM_IO_IN_PROGRESS on the buffer
but has not yet set the wait reference. Such windows should be brief and
uncommon.

Author: Melanie Plageman <melanieplageman@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/flat/zljergweqti7x67lg5ije2rzjusie37nslsnkjkkby4laqqbfw%403p3zu522yykv
2026-03-27 19:53:32 -04:00
..
access Use UnlockReleaseBuffer() in more places 2026-03-27 15:56:29 -04:00
archive Don't include wait_event.h in pgstat.h 2026-03-06 16:24:58 +01:00
backup Add missing deflateEnd() for server-side gzip base backups 2026-03-23 09:04:44 +09:00
bootstrap Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
catalog Refactor to remove ForeignServerName(). 2026-03-24 15:20:28 -07:00
commands Refactor to remove ForeignServerName(). 2026-03-24 15:20:28 -07:00
executor Make many cast functions error safe 2026-03-24 12:08:22 +01:00
foreign Refactor to remove ForeignServerName(). 2026-03-24 15:20:28 -07:00
jit Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
lib dshash: Make it possible to suppress out of memory errors 2026-03-19 11:51:17 -04:00
libpq ssl: Serverside SNI support for libpq 2026-03-18 12:37:11 +01:00
main Update copyright for 2026 2026-01-01 13:24:10 -05:00
nodes Allow IS JSON predicate to work with domain types 2026-03-17 15:20:22 -04:00
optimizer Add an alternative_plan_name field to PlannerInfo. 2026-03-26 16:45:17 -04:00
parser Add a graph pattern variable only once 2026-03-27 10:55:17 +01:00
partitioning Fix -Wcast-qual warning 2026-03-26 15:00:24 +01:00
po Update copyright for 2026 2026-01-01 13:24:10 -05:00
port Disable warnings in system headers in MSVC 2026-03-25 15:03:52 +01:00
postmaster Add rudimentary table prioritization to autovacuum. 2026-03-27 10:17:05 -05:00
regex Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
replication Avoid sending duplicate WAL locations in standby status replies 2026-03-26 20:54:32 +09:00
rewrite Reject consecutive element patterns of same kind 2026-03-27 10:31:53 +01:00
snowball Fix meson build of snowball code. 2026-01-05 16:51:36 -05:00
statistics Fix inconsistency with HeapTuple freeing in extended_stats_funcs.c 2026-03-06 14:49:00 +09:00
storage aio: Don't wait for already in-progress IO 2026-03-27 19:53:32 -04:00
tcop Reduce header inclusions via execnodes.h 2026-03-16 14:34:57 +01:00
tsearch Require superuser to install a non-built-in selectivity estimator. 2026-02-09 10:07:31 -05:00
utils Add rudimentary table prioritization to autovacuum. 2026-03-27 10:17:05 -05:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile ssl: Serverside SNI support for libpq 2026-03-18 12:37:11 +01:00
meson.build Add backtrace support for Windows using DbgHelp API 2026-02-24 17:34:56 +01:00
nls.mk Create a separate file listing backend types 2025-09-26 15:21:49 +02:00