https://github.com/postgres/postgres
Revision 5af055ed74467f3a2c77d16179e1000b593e04e9 authored by Tom Lane on 01 September 2018, 19:27:14 UTC, committed by Tom Lane on 01 September 2018, 19:27:14 UTC
There's a project policy against using plain "char buf[BLCKSZ]" local
or static variables as page buffers; preferred style is to palloc or
malloc each buffer to ensure it is MAXALIGN'd.  However, that policy's
been ignored in an increasing number of places.  We've apparently got
away with it so far, probably because (a) relatively few people use
platforms on which misalignment causes core dumps and/or (b) the
variables chance to be sufficiently aligned anyway.  But this is not
something to rely on.  Moreover, even if we don't get a core dump,
we might be paying a lot of cycles for misaligned accesses.

To fix, invent new union types PGAlignedBlock and PGAlignedXLogBlock
that the compiler must allocate with sufficient alignment, and use
those in place of plain char arrays.

I used these types even for variables where there's no risk of a
misaligned access, since ensuring proper alignment should make
kernel data transfers faster.  I also changed some places where
we had been palloc'ing short-lived buffers, for coding style
uniformity and to save palloc/pfree overhead.

Since this seems to be a live portability hazard (despite the lack
of field reports), back-patch to all supported versions.

Patch by me; thanks to Michael Paquier for review.

Discussion: https://postgr.es/m/1535618100.1286.3.camel@credativ.de
1 parent 65f3940
History
Tip revision: 5af055ed74467f3a2c77d16179e1000b593e04e9 authored by Tom Lane on 01 September 2018, 19:27:14 UTC
Avoid using potentially-under-aligned page buffers.
Tip revision: 5af055e
File Mode Size
config
contrib
doc
src
.gitignore -rw-r--r-- 392 bytes
COPYRIGHT -rw-r--r-- 1.2 KB
GNUmakefile.in -rw-r--r-- 3.5 KB
HISTORY -rw-r--r-- 284 bytes
Makefile -rw-r--r-- 1.6 KB
README -rw-r--r-- 1.2 KB
README.git -rw-r--r-- 728 bytes
aclocal.m4 -rw-r--r-- 385 bytes
configure -rwxr-xr-x 889.9 KB
configure.in -rw-r--r-- 66.8 KB

README

back to top