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

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Andres Freund <andres(at)anarazel(dot)de>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: "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-10 20:53:58
Message-ID: 3dd6f70c-b94d-4428-8e75-74a7136396be@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On 10/02/2026 21:46, Andres Freund wrote:
> On 2026-02-10 19:15:27 +0000, Bertrand Drouvot wrote:
>> On Tue, Feb 10, 2026 at 01:15:01PM -0500, Andres Freund wrote:
>>> On 2026-02-10 19:14:44 +0200, Heikki Linnakangas wrote:
>>> Yea, I don't think we need to be perfect here. Just a bit less bad. And, as
>>> you say, the current order doesn't make a lot of sense.
>>> Just grouping things like
>>> - pid, pgxactoff, backendType (i.e. barely if ever changing)
>>> - wait_event_info, waitStart (i.e. very frequently changing, but typically
>>> accessed within one proc)
>>> - sem, lwWaiting, waitLockMode (i.e. stuff that is updated frequently and
>>> accessed across processes)
>>
>> With an ordering like in the attached (to apply on top of Heikki's patch), we're
>> back to 832 bytes.
>
> You'd really need to insert padding between the sections to make it work...

Here's my attempt at grouping things more logically. I didn't insert
padding and also didn't try to avoid alignment padding. I tried to
optimize for readability rather than size or performance. That said, I
would assume that grouping things logically like this would also help to
avoid false sharing. If not, inserting explicit padding seems like a a
good fix.

I also think we should split 'links' into two fields. For clarity.

With this, sizeof(PGPROC) == 864 without the explicit alignment to
PG_CACHE_LINE_SIZE, and 896 with it.

- Heikki

Attachment Content-Type Size
v2-0001-Align-PGPROC-to-cache-line-boundary.patch text/x-patch 1.5 KB
v2-0002-Remove-useless-store.patch text/x-patch 900 bytes
v2-0003-Split-PGPROC-links-field-into-two-for-clarity.patch text/x-patch 13.0 KB
v2-0004-Rearrange-fields-in-PGPROC-for-clarity.patch text/x-patch 8.0 KB

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2026-02-10 21:32:29 pgsql: Store information about range-table flattening in the final plan
Previous Message Andres Freund 2026-02-10 19:46:31 Re: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals)

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2026-02-10 21:24:56 Re: Decoupling our alignment assumptions about int64 and double
Previous Message Tom Lane 2026-02-10 20:52:18 Re: Decoupling our alignment assumptions about int64 and double