From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Michael Banck <michael.banck@credativ.de>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: pg_verify_checksums and -fno-strict-aliasing
Date: Fri, 31 Aug 2018 15:21:19 -0700
Message-ID: <20180831222119.GD5305@paquier.xyz> (raw)
In-Reply-To: <21037.1535745351@sss.pgh.pa.us>
References: <1535618100.1286.3.camel@credativ.de>
<alpine.DEB.2.21.1808301325070.32764@lancre>
<7321.1535639966@sss.pgh.pa.us>
<20180830175652.GC15446@paquier.xyz>
<12123.1535672257@sss.pgh.pa.us>
<20180831000600.GI15446@paquier.xyz>
<28226.1535727306@sss.pgh.pa.us>
<21037.1535745351@sss.pgh.pa.us>
On Fri, Aug 31, 2018 at 03:55:51PM -0400, Tom Lane wrote:
> I wrote:
>> Some of these places might be performance-critical enough that adding
>> a palloc/pfree cycle would not be nice. What I was considering doing
>> was inventing something like
>>
>> typedef union PGAlignedBuffer
>> {
>> char data[BLCKSZ];
>> double force_align;
>> } PGAlignedBuffer;
>
> Here's a proposed patch using that approach.
This solution is smarter than using malloc/palloc to enforce alignment.
I was digging into the GIN and bloom code with this pattern, but except
if I used TopTransactionContext for a simple approach, which is not
acceptable by the way, I was finishing with ugly memory contexts
used... I am still not sure if that was completely correct either, this
needed more time ;)
> Although some of the places that were using "char buf[BLCKSZ]" variables
> weren't doing anything that really requires better alignment, I made
> almost all of them use PGAlignedBuffer variables anyway, on the grounds
> that you typically get better memcpy speed for aligned than unaligned
> transfers.
Makes sense.
> I also fixed a few places that were using the palloc solution, and
> one that was actually doing hand-alignment of the pointer (ugh).
> I didn't try to be thorough about getting rid of such pallocs,
> just fix places that seemed likely to be performance-critical.
Okay, for the memo replay_image_masked and master_image_masked
in xlog.c could make use of the new structure. SetWALSegSize in
pg_standby.c and WriteEmptyXLOG in pg_resetwal.c, and pg_upgrade's
file.c could also be patched.
walmethods.c could also use some static buffers, not worth the
complication perhaps..
> +typedef union PGAlignedBuffer
> +{
> + char data[BLCKSZ];
> + double force_align_d;
> + int64 force_align_i64;
> +} PGAlignedBuffer;
> +
> +/* Same, but for an XLOG_BLCKSZ-sized buffer */
> +typedef union PGAlignedXLogBuffer
> +{
> + char data[XLOG_BLCKSZ];
> + double force_align_d;
> + int64 force_align_i64;
> +} PGAlignedXLogBuffer;
One complain I have is about the name of those structures. Perhaps
PGAlignedBlock and PGAlignedXlogBlock make more sense?
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: michael@paquier.xyz, tgl@sss.pgh.pa.us, coelho@cri.ensmp.fr, michael.banck@credativ.de
Subject: Re: pg_verify_checksums and -fno-strict-aliasing
In-Reply-To: <20180831222119.GD5305@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox