Re: Automatically sizing the IO worker pool
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-08T02:47:37Z
Lists: pgsql-hackers
Attachments
- v8-0001-aio-Adjust-I-O-worker-pool-size-automatically.patch (text/x-patch) patch v8-0001
On Wed, Apr 8, 2026 at 2:20 PM Andres Freund <andres@anarazel.de> wrote:
> I don't follow. What I was proposing is after the conditional lock
> acquisition succeeded. So is your nsync == 0 check.
Oops. Sorry, brainfade. Condition removed.
> > +/*
> > + * Tell postmaster that we think a new worker is needed.
> > + */
> > +static void
> > +pgaio_worker_request_grow(void)
> > +{
> > + /*
> > + * Suppress useless signaling if we already know that we're at the
> > + * maximum. This uses an unlocked read of nworkers, but that's OK for
> > + * this heuristic purpose.
> > + */
> > + if (io_worker_control->nworkers < io_max_workers)
> > {
> > - io_worker_control->workers[i].latch = NULL;
> > - io_worker_control->workers[i].in_use = false;
> > + if (!io_worker_control->grow)
> > + {
> > + io_worker_control->grow = true;
> > + pg_memory_barrier();
> > +
> > + /*
> > + * If the postmaster has already been signaled, don't do it again
> > + * until the postmaster clears this flag. There is no point in
> > + * repeated signals if grow is being set and cleared repeatedly
> > + * while the postmaster is waiting for io_worker_launch_interval
> > + * (which it applies even to canceled requests).
> > + */
> > + if (!io_worker_control->grow_signal_sent)
> > + {
> > + io_worker_control->grow_signal_sent = true;
> > + pg_memory_barrier();
> > + SendPostmasterSignal(PMSIGNAL_IO_WORKER_GROW);
> > + }
> > + }
> > }
> > }
>
>
> I'd probbly use early returns to make it a bit more readable.
Done for this and similar functions.
> > +static bool
> > +pgaio_worker_can_timeout(void)
> > +{
> > + PgAioWorkerSet workerset;
> > +
> > + /* Serialize against pool size changes. */
> > + LWLockAcquire(AioWorkerControlLock, LW_SHARED);
> > + workerset = io_worker_control->workerset;
> > + LWLockRelease(AioWorkerControlLock);
> > +
> > + if (MyIoWorkerId != pgaio_workerset_get_highest(&workerset))
> > + return false;
> > +
> > + if (MyIoWorkerId < io_min_workers)
> > + return false;
> > +
> > + return true;
> > +}
>
> I guess I'd move the < io_min_workers to earlier so that you don't acquire the
> lock if that'll return false anyway.
Done.
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
aio: Adjust I/O worker pool automatically.
- d1c01b79d4ae 19 (unreleased) landed
-
Convert lwlock.c to use the new shmem allocation functions
- a006bc7b1699 19 (unreleased) cited
-
aio: Simplify pgaio_worker_submit().
- fc44f106657a 19 (unreleased) landed
-
Conditional locking in pgaio_worker_submit_internal
- 29a0fb215779 19 (unreleased) cited
-
aio: Remove obsolete IO worker ID references.
- b4c19da93a08 18.0 landed
- 177c1f059338 19 (unreleased) landed
-
aio: Regularize IO worker internal naming.
- b2afb0676337 18.0 landed
- 01d618bcd782 19 (unreleased) landed