postgresql/src/common
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
..
unicode meson: don't require 'touch' binary, make use of 'cp' optional 2023-03-07 18:44:42 -08:00
.gitignore Replace the data structure used for keyword lookup. 2019-01-06 17:02:57 -05:00
Makefile Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
archive.c Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
base64.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
checksum_helper.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
compression.c Support long distance matching for zstd compression 2023-04-06 17:18:42 +02:00
config_info.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
controldata_utils.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
cryptohash.c Improve/correct comments 2023-03-09 09:59:46 +01:00
cryptohash_openssl.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
d2s.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
d2s_full_table.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
d2s_intrinsics.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
digit_table.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
encnames.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
exec.c Implement find_my_exec()'s path normalization using realpath(3). 2023-03-23 18:17:49 -04:00
f2s.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
fe_memutils.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
file_perm.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
file_utils.c Introduce PG_IO_ALIGN_SIZE and align all I/O buffers. 2023-04-08 16:34:50 +12:00
hashfn.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
hmac.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
hmac_openssl.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
ip.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
jsonapi.c Fix JSON error reporting for many cases of erroneous string values. 2023-03-13 15:19:00 -04:00
keywords.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
kwlookup.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
link-canary.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
logging.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
md5.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
md5_common.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
md5_int.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
meson.build Revert refactoring of restore command code to shell_restore.c 2023-02-06 08:28:42 +09:00
percentrepl.c Common function for percent placeholder replacement 2023-01-11 10:42:35 +01:00
pg_get_line.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_lzcompress.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_prng.c Invent random_normal() to provide normally-distributed random numbers. 2023-01-09 12:44:00 -05:00
pgfnames.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
protocol_openssl.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
psprintf.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
relpath.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
restricted_token.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
rmtree.c Refactor rmtree() to use get_dirent_type(). 2023-01-31 13:46:25 +13:00
ryu_common.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
saslprep.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
scram-common.c Make SCRAM iteration count configurable 2023-03-27 09:46:29 +02:00
sha1.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
sha1_int.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
sha2.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
sha2_int.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
sprompt.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
string.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
stringinfo.c Use appendStringInfoSpaces in more places 2023-01-20 13:07:24 +13:00
unicode_norm.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
username.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
wait_error.c Add SHELL_ERROR and SHELL_EXIT_CODE magic variables to psql. 2023-03-21 13:03:56 -04:00
wchar.c Update copyright for 2023 2023-01-02 15:00:37 -05:00