Skip to content

Commit 247ce06

Browse files
anarazelmacdice
andcommitted
aio: Add io_method=worker
The previous commit introduced the infrastructure to start io_workers. This commit actually makes the workers execute IOs. IO workers consume IOs from a shared memory submission queue, run traditional synchronous system calls, and perform the shared completion handling immediately. Client code submits most requests by pushing IOs into the submission queue, and waits (if necessary) using condition variables. Some IOs cannot be performed in another process due to lack of infrastructure for reopening the file, and must processed synchronously by the client code when submitted. For now the default io_method is changed to "worker". We should re-evaluate that around beta1, we might want to be careful and set the default to "sync" for 18. Reviewed-by: Noah Misch <noah@leadboat.com> Co-authored-by: Thomas Munro <thomas.munro@gmail.com> Co-authored-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt Discussion: https://postgr.es/m/20210223100344.llw5an2aklengrmn@alap3.anarazel.de Discussion: https://postgr.es/m/stj36ea6yyhoxtqkhpieia2z4krnam7qyetc57rfezgk4zgapf@gcnactj4z56m
1 parent 55b454d commit 247ce06

File tree

10 files changed

+466
-8
lines changed

10 files changed

+466
-8
lines changed

doc/src/sgml/config.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,11 @@ include_dir 'conf.d'
26762676
Selects the method for executing asynchronous I/O.
26772677
Possible values are:
26782678
<itemizedlist>
2679+
<listitem>
2680+
<para>
2681+
<literal>worker</literal> (execute asynchronous I/O using worker processes)
2682+
</para>
2683+
</listitem>
26792684
<listitem>
26802685
<para>
26812686
<literal>sync</literal> (execute asynchronous-eligible I/O synchronously)

src/backend/storage/aio/aio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static void pgaio_io_wait(PgAioHandle *ioh, uint64 ref_generation);
6464
/* Options for io_method. */
6565
const struct config_enum_entry io_method_options[] = {
6666
{"sync", IOMETHOD_SYNC, false},
67+
{"worker", IOMETHOD_WORKER, false},
6768
{NULL, 0, false}
6869
};
6970

@@ -80,6 +81,7 @@ PgAioBackend *pgaio_my_backend;
8081

8182
static const IoMethodOps *const pgaio_method_ops_table[] = {
8283
[IOMETHOD_SYNC] = &pgaio_sync_ops,
84+
[IOMETHOD_WORKER] = &pgaio_worker_ops,
8385
};
8486

8587
/* callbacks for the configured io_method, set by assign_io_method */

src/backend/storage/aio/aio_init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "storage/aio.h"
1919
#include "storage/aio_internal.h"
2020
#include "storage/aio_subsys.h"
21+
#include "storage/io_worker.h"
2122
#include "storage/ipc.h"
2223
#include "storage/proc.h"
2324
#include "storage/shmem.h"
@@ -39,6 +40,11 @@ AioCtlShmemSize(void)
3940
static uint32
4041
AioProcs(void)
4142
{
43+
/*
44+
* While AIO workers don't need their own AIO context, we can't currently
45+
* guarantee nothing gets assigned to the a ProcNumber for an IO worker if
46+
* we just subtracted MAX_IO_WORKERS.
47+
*/
4248
return MaxBackends + NUM_AUXILIARY_PROCS;
4349
}
4450

@@ -223,6 +229,9 @@ pgaio_init_backend(void)
223229
/* shouldn't be initialized twice */
224230
Assert(!pgaio_my_backend);
225231

232+
if (MyBackendType == B_IO_WORKER)
233+
return;
234+
226235
if (MyProc == NULL || MyProcNumber >= AioProcs())
227236
elog(ERROR, "aio requires a normal PGPROC");
228237

0 commit comments

Comments
 (0)