Re: Direct I/O

Thomas Munro <thomas.munro@gmail.com>

From: Thomas Munro <thomas.munro@gmail.com>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: pgsql-hackers@postgresql.org
Date: 2022-11-01T20:44:30Z
Lists: pgsql-hackers
On Wed, Nov 2, 2022 at 2:33 AM Justin Pryzby <pryzby@telsasoft.com> wrote:
> On Tue, Nov 01, 2022 at 08:36:18PM +1300, Thomas Munro wrote:
> >   io_data_direct = whether to use O_DIRECT for main data files
> >   io_wal_direct = ... for WAL
> >   io_wal_init_direct = ... for WAL-file initialisation
>
> You added 3 booleans, but I wonder if it's better to add a string GUC
> which is parsed for comma separated strings.  (By "better", I mean
> reducing the number of new GUCs - which is less important for developer
> GUCs anyway.)

Interesting idea.  So "direct_io = data, wal, wal_init", or maybe that
should be spelled io_direct.  ("Direct I/O" is a common term of art,
but we also have some more io_XXX GUCs in later patches, so it's hard
to choose...)

> DIO is slower, but not so much that it can't run under CI.  I suggest to
> add an 099 commit to enable the feature during development.

Good idea, will do.

> Note that this fails under linux with fsanitize=align:
> ../src/backend/storage/file/buffile.c:117:17: runtime error: member access within misaligned address 0x561a4a8e40f8 for type 'struct BufFile', which requires 4096 byte alignment

Oh, so BufFile is palloc'd and contains one of these.  BufFile is not
even using direct I/O, but by these rules it would need to be
palloc_io_align'd.  I will think about what to do about that...



Commits

  1. Rename hook functions for debug_io_direct to match variable name.

  2. Rename io_direct to debug_io_direct.

  3. Skip the 004_io_direct.pl test if a pre-flight check fails.

  4. Use higher wal_level for 004_io_direct.pl.

  5. Skip \password TAP test on old IPC::Run versions

  6. Add io_direct setting (developer-only).

  7. Introduce PG_IO_ALIGN_SIZE and align all I/O buffers.

  8. Add palloc_aligned() to allow aligned memory allocations

  9. initdb: When running CREATE DATABASE, use STRATEGY = WAL_COPY.