Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)
Date: 2026-02-20 21:03:09
Message-ID: 60478a2d-915e-411d-9f7d-42917dd8b8c4@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On 11/02/2026 06:40, Bertrand Drouvot wrote:
> 0004:
>
> The grouping looks Ok to me. Just one nit for the added comments:
>
> + /*---- Backend identity ----*/
> + /*---- Transactions and snapshots ----*/
> + /*---- Inter-process signaling ----*/
> + /*---- LWLock waiting ----*/
> + /*---- Lock manager data ----*/
> + /*---- Synchronous replication waiting ----*/
> + /*---- Support for group XID clearing. ----*/
> + /*---- Support for group transaction status update. ----*/
> + /*---- Status reporting ----*/
>
> Some have period and some don't.

Fixed that, and changed to different style for the delimiter comments.
It's a matter of taste, but I think the new style is closer to what we
use elsewhere.

On 13/02/2026 10:03, Bertrand Drouvot wrote:
> and what the patch adds:
>
> +/*
> + * If compiler understands aligned pragma, use it to align the struct at cache
> + * line boundaries. This is just for performance, to (a) avoid false sharing
> + * and (b) to make the multiplication / division to convert between PGPROC *
> + * and ProcNumber be a little cheaper.
> + */
> +#if defined(pg_attribute_aligned)
> + pg_attribute_aligned(PG_CACHE_LINE_SIZE)
> +#endif
> +PGPROC;
>
> It means that PGPROC is "acceptable" without padding (on compiler that does not
> understand the aligned attribute).
>
> OTOH, looking at:
>
> "
> typedef union WALInsertLockPadded
> {
> WALInsertLock l;
> char pad[PG_CACHE_LINE_SIZE];
> } WALInsertLockPadded;
> "
>
> It seems to mean that WALInsertLockPadded is unacceptable without padding (since
> it's not using pg_attribute_aligned()).
>
> That looks ok to see PGPROC as an "acceptable" one, if not, should we use the
> union trick?

It seems acceptable to just not align it if the compiler doesn't support
it. This is just a performance optimization, after all.

Attached is new versions the remaining patches. I think these are ready
to be committed.

I don't have the hardware and test case that would be sensitive enough
for these changes in memory layout, so I haven't done any performance
testing of this. I'd guess this no worse than the old layout. Grouping
fields together which are used together is usually a good strategy. I
don't feel obliged to do performance testing of this, given that no one
did that for the old layout either, so if it happened to be really good
from a performance point of view, it was purely accidental. But if
anyone has the means and interest to do that, that'd be much appreciated
of course.

- Heikki

Attachment Content-Type Size
v2-0001-Rearrange-fields-in-PGPROC-for-clarity.patch text/x-patch 9.7 KB
v2-0002-Align-PGPROC-to-cache-line-boundary.patch text/x-patch 1.5 KB

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-02-21 09:42:13 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)
Previous Message Heikki Linnakangas 2026-02-20 21:01:33 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-02-20 21:33:34 Re: refactor architecture-specific popcount code
Previous Message Heikki Linnakangas 2026-02-20 21:01:33 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)