postgresql/src/bin/pg_upgrade
Thomas Munro faeedbcefd Introduce PG_IO_ALIGN_SIZE and align all I/O buffers.
In order to have the option to use O_DIRECT/FILE_FLAG_NO_BUFFERING in a
later commit, we need the addresses of user space buffers to be well
aligned.  The exact requirements vary by OS and file system (typically
sectors and/or memory pages).  The address alignment size is set to
4096, which is enough for currently known systems: it matches modern
sectors and common memory page size.  There is no standard governing
O_DIRECT's requirements so we might eventually have to reconsider this
with more information from the field or future systems.

Aligning I/O buffers on memory pages is also known to improve regular
buffered I/O performance.

Three classes of I/O buffers for regular data pages are adjusted:
(1) Heap buffers are now allocated with the new palloc_aligned() or
MemoryContextAllocAligned() functions introduced by commit 439f6175.
(2) Stack buffers now use a new struct PGIOAlignedBlock to respect
PG_IO_ALIGN_SIZE, if possible with this compiler.  (3) The buffer
pool is also aligned in shared memory.

WAL buffers were already aligned on XLOG_BLCKSZ.  It's possible for
XLOG_BLCKSZ to be configured smaller than PG_IO_ALIGNED_SIZE and thus
for O_DIRECT WAL writes to fail to be well aligned, but that's a
pre-existing condition and will be addressed by a later commit.

BufFiles are not yet addressed (there's no current plan to use O_DIRECT
for those, but they could potentially get some incidental speedup even
in plain buffered I/O operations through better alignment).

If we can't align stack objects suitably using the compiler extensions
we know about, we disable the use of O_DIRECT by setting PG_O_DIRECT to
0.  This avoids the need to consider systems that have O_DIRECT but
can't align stack objects the way we want; such systems could in theory
be supported with more work but we don't currently know of any such
machines, so it's easier to pretend there is no O_DIRECT support
instead.  That's an existing and tested class of system.

Add assertions that all buffers passed into smgrread(), smgrwrite() and
smgrextend() are correctly aligned, unless PG_O_DIRECT is 0 (= stack
alignment tricks may be unavailable) or the block size has been set too
small to allow arrays of buffers to be all aligned.

Author: Thomas Munro <thomas.munro@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/CA+hUKGK1X532hYqJ_MzFWt0n1zt8trz980D79WbjwnT-yYLZpg@mail.gmail.com
2023-04-08 16:34:50 +12:00
..
po meson: add install-{quiet, world} targets 2023-03-23 21:20:18 -07:00
t Add Copyright notice in 001_basic.pl and 002_pg_upgrade.pl. 2023-04-05 09:20:14 +05:30
.gitignore Re-add locally-generated files in pg_upgrade's .gitignore and Makefile 2022-06-15 15:36:16 +09:00
IMPLEMENTATION pg_upgrade: Preserve database OIDs. 2022-01-24 14:23:43 -05:00
Makefile pg_upgrade: copy locale and encoding information to new cluster. 2023-03-09 08:28:05 -08:00
TESTING Create common infrastructure for cross-version upgrade testing. 2023-01-16 20:35:55 -05:00
check.c Avoid using atooid for numerical comparisons which arent Oids 2023-03-21 12:57:21 +01:00
controldata.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
dump.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
exec.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
file.c Introduce PG_IO_ALIGN_SIZE and align all I/O buffers. 2023-04-08 16:34:50 +12:00
function.c Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
info.c Fix 9637badd9f. 2023-03-09 10:26:47 -08:00
meson.build pg_upgrade: copy locale and encoding information to new cluster. 2023-03-09 08:28:05 -08:00
nls.mk Break up long GETTEXT_FILES lists 2023-03-08 15:05:43 +01:00
option.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
parallel.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_upgrade.c Fix incorrect format placeholders 2023-03-17 07:48:24 +01:00
pg_upgrade.h pg_upgrade: copy locale and encoding information to new cluster. 2023-03-09 08:28:05 -08:00
relfilenumber.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
server.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
tablespace.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
util.c Try to fix pg_upgrade test on Windows, again. 2023-02-01 14:40:25 +13:00
version.c Update copyright for 2023 2023-01-02 15:00:37 -05:00