pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: bufmgr: Improve StartBufferIO interface
Date: Fri, 27 Mar 2026 23:17:19 +0000
Message-ID: <E1w6GQY-001lCW-2B@gemulon.postgresql.org> (raw)

bufmgr: Improve StartBufferIO interface

Until now StartBufferIO() had a few weaknesses:

- As it did not submit staged IOs, it was not safe to call StartBufferIO()
  where there was a potential for unsubmitted IO, which required
  AsyncReadBuffers() to use a wrapper (ReadBuffersCanStartIO()) around
  StartBufferIO().

- With nowait = true, the boolean return value did not allow to distinguish
  between no IO being necessary and having to wait, which would lead
  ReadBuffersCanStartIO() to unnecessarily submit staged IO.

- Several callers needed to handle both local and shared buffers, requiring
  the caller to differentiate between StartBufferIO() and StartLocalBufferIO()

- In a future commit some callers of StartBufferIO() want the BufferDesc's
  io_wref to be returned, to asynchronously wait for in-progress IO

- Indicating whether to wait with the nowait parameter was somewhat confusing
  compared to a wait parameter

Address these issues as follows:

- StartBufferIO() is renamed to StartSharedBufferIO()

- A new StartBufferIO() is introduced that supports both shared and local
  buffers

- The boolean return value has been replaced with an enum, indicating whether
  the IO is already done, already in progress or that the buffer has been
  readied for IO

- A new PgAioWaitRef * argument allows the caller to get the wait reference is
  desired.  All current callers pass NULL, a user of this will be introduced
  subsequently

- Instead of the nowait argument there now is wait

  This probably would not have been worthwhile on its own, but since all these
  lines needed to be touched anyway...

Author: Andres Freund <andres@anarazel.de>
Author: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/zljergweqti7x67lg5ije2rzjusie37nslsnkjkkby4laqqbfw@3p3zu522yykv

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/74eafeab1a576620879e889ec70bf826e3e7fce8

Modified Files
--------------
src/backend/storage/buffer/bufmgr.c         | 295 +++++++++++++++++-----------
src/backend/storage/buffer/localbuf.c       |  46 +++--
src/include/storage/buf_internals.h         |  24 ++-
src/test/modules/test_aio/t/001_aio.pl      |  24 +--
src/test/modules/test_aio/test_aio--1.0.sql |   2 +-
src/test/modules/test_aio/test_aio.c        |  17 +-
src/tools/pgindent/typedefs.list            |   1 +
7 files changed, 259 insertions(+), 150 deletions(-)



Message-ID: <E1w6GQY-001lCW-2B@gemulon.postgresql.org>
Permalink:  ../E1w6GQY-001lCW-2B@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w6GQY-001lCW-2B@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: bufmgr: Improve StartBufferIO interface
  In-Reply-To: <E1w6GQY-001lCW-2B@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox