]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Conditional locking in pgaio_worker_submit_internal
authorTomas Vondra <tomas.vondra@postgresql.org>
Wed, 11 Mar 2026 11:11:04 +0000 (12:11 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Wed, 11 Mar 2026 12:40:23 +0000 (13:40 +0100)
commit29a0fb215779d10fae0cbeb8ce57805f244bad9b
treedccf6a3c49373ca6459b4107aff7743498db2244
parent9c05f152b5dd7aeaa6e64bd4ed2fc86bab437073
Conditional locking in pgaio_worker_submit_internal

With io_method=worker, there's a single I/O submission queue. With
enough workers, the backends and workers may end up spending a lot of
time competing for the AioWorkerSubmissionQueueLock lock. This can
happen with workloads that keep the queue full, in which case it's
impossible to add requests to the queue. Increasing the number of I/O
workers increases the pressure on the lock, worsening the issue.

This change improves the situation in two ways:

* If AioWorkerSubmissionQueueLock can't be acquired without waiting,
  the I/O is performed synchronously (as if the queue was full).

* When an entry can't be added to a full queue, stop trying to add more
  entries. All remaining entries are handled as synchronous I/O.

The regression was reported by Alexandre Felipe. Investigation and
patch by me, based on an idea by Andres Freund.

Reported-by: Alexandre Felipe <o.alexandre.felipe@gmail.com>
Author: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAE8JnxOn4+xUAnce+M7LfZWOqfrMMxasMaEmSKwiKbQtZr65uA@mail.gmail.com
src/backend/storage/aio/method_worker.c