pgsql: Conditional locking in pgaio_worker_submit_internal - Mailing list pgsql-committers

From Tomas Vondra
Subject pgsql: Conditional locking in pgaio_worker_submit_internal
Date
Msg-id E1w0ItN-003THv-24@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/29a0fb215779d10fae0cbeb8ce57805f244bad9b

Modified Files
--------------
src/backend/storage/aio/method_worker.c | 57 ++++++++++++++++++++-------------
1 file changed, 34 insertions(+), 23 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Fixes for C++ typeof implementation
Next
From: Tomas Vondra
Date:
Subject: pgsql: Fix indentation from commit 29a0fb21577