Re: Direct I/O
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Andrew Dunstan <andrew@dunslane.net>, Andrea Gelmini <andrea.gelmini@gmail.com>,
Heikki Linnakangas <hlinnaka@iki.fi>, Noah Misch <noah@leadboat.com>, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Justin Pryzby <pryzby@telsasoft.com>, pgsql-hackers@postgresql.org
Date: 2023-04-11T02:31:40Z
Lists: pgsql-hackers
On Tue, Apr 11, 2023 at 2:15 PM Andres Freund <andres@anarazel.de> wrote: > And the fix has been merged into > https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git/log/?h=for-next > > I think that means it'll have to wait for 6.4 development to open (in a few > weeks), and then will be merged into the stable branches from there. Great! Let's hope/assume for now that that'll fix phenomenon #2. That still leaves the checksum-vs-concurrent-modification thing that I called phenomenon #1, which we've not actually hit with PostgreSQL yet but is clearly possible and can be seen with the stand-alone repro-program I posted upthread. You wrote: On Mon, Apr 10, 2023 at 2:57 PM Andres Freund <andres@anarazel.de> wrote: > I think we really need to think about whether we eventually we want to do > something to avoid modifying pages while IO is in progress. The only > alternative is for filesystems to make copies of everything in the IO path, > which is far from free (and obviously prevents from using DMA for the whole > IO). The copy we do to avoid the same problem when checksums are enabled, > shows up quite prominently in write-heavy profiles, so there's a "purely > postgres" reason to avoid these issues too. +1 I wonder what the other file systems that maintain checksums (see list at [1]) do when the data changes underneath a write. ZFS's policy is conservative[2], while BTRFS took the demons-will-fly-out-of-your-nose route. I can see arguments for both approaches (ZFS can only reach zero-copy optimum by turning off checksums completely, while BTRFS is happy to assume that if you break this programming rule that is not written down anywhere then you must never want to see your data ever again). What about ReFS? CephFS? I tried to find out what POSIX says about this WRT synchronous pwrite() (as Tom suggested, maybe we're doing something POSIX doesn't allow), but couldn't find it in my first attempt. It *does* say it's undefined for aio_write() (which means that my prototype io_method=posix_aio code that uses that stuff is undefined in presense of hintbit modifications). I don't really see why it should vary between synchronous and asynchronous interfaces (considering the existence of threads, shared memory etc, the synchronous interface only removes one thread from list of possible suspects that could flip some bits). But yeah, in any case, it doesn't seem great that we do that. [1] https://en.wikipedia.org/wiki/Comparison_of_file_systems#Block_capabilities [2] https://openzfs.topicbox.com/groups/developer/T950b02acdf392290/odirect-semantics-in-zfs
Commits
-
Rename hook functions for debug_io_direct to match variable name.
- 155c81463c26 16.0 landed
- 4f3514f201cf 17.0 landed
-
Rename io_direct to debug_io_direct.
- 319bae9a8da6 16.0 landed
-
Skip the 004_io_direct.pl test if a pre-flight check fails.
- 6ca8df2d6147 16.0 landed
-
Use higher wal_level for 004_io_direct.pl.
- 980e8879f54a 16.0 landed
-
Skip \password TAP test on old IPC::Run versions
- 2e57ffe12f6b 16.0 cited
-
Add io_direct setting (developer-only).
- d4e71df6d757 16.0 landed
-
Introduce PG_IO_ALIGN_SIZE and align all I/O buffers.
- faeedbcefd40 16.0 landed
-
Add palloc_aligned() to allow aligned memory allocations
- 439f61757f05 16.0 cited
-
initdb: When running CREATE DATABASE, use STRATEGY = WAL_COPY.
- ad43a413c4f7 15.0 cited