| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
| Cc: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, 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-24 11:28:11 |
| Message-ID: | aZ2LS5m1K2G3r3U4@ip-10-97-1-34.eu-west-3.compute.internal |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers pgsql-hackers |
Hi,
On Mon, Feb 23, 2026 at 05:13:29PM +0100, Peter Eisentraut wrote:
> On 13.02.26 09:03, Bertrand Drouvot wrote:
> > +/*
> > + * 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;
>
> You can/should use C11 standard alignas(), so you don't need to worry about
> whether it's supported or not.
Oh right, I did not notice 300c8f53247 and following like e7075a3405c, d4c0f91f7d5
and 97e04c74bed.
PFA, 0001 doing so for PGPROC and PgAioUringContext. As those are typedef,
the patch puts alignas within the struct.
For PGPROC at the start of the struct, I think that placing it on the first member
is the right location because it ensures the whole struct is aligned to PG_CACHE_LINE_SIZE
without adding padding before this member. For example if I set it on backendType,
then it adds 100 bytes of padding and the struct is obviously still a multiple of
PG_CACHE_LINE_SIZE but is now 1024 bytes (instead of 896).
For PgAioUringContext at completion_lock (like suggested by Andres in [1]), which
is also the start of the struct.
I checked and the padding for those are exactly the same after the changes.
0002, is also making use of alignas in ItemPointerData, but this one is more
tricky so I'm not sure that's worth it (given the fact that we still need to
keep pg_attribute_aligned() as explained by Peter in [2]).
[1]: https://postgr.es/m/lsgnps74ictxtm5karcobenxtt5rvoylvbvx7ja6r5rjcund7v%40owxqgv7gisns
[2]: https://postgr.es/m/46f05236-d4d4-4b4e-84d4-faa500f14691%40eisentraut.org
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Use-C11-alignas-in-typedef-definitions.patch | text/x-diff | 2.8 KB |
| v1-0002-Use-C11-alignas-in-more-tricky-typedef-definition.patch | text/x-diff | 1.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrew Dunstan | 2026-02-24 15:55:20 | Re: pgsql: libpq: Grease the protocol by default |
| Previous Message | Peter Eisentraut | 2026-02-24 10:31:54 | pgsql: doc: Add link targets to CREATE/ALTER FOREIGN TABLE reference pa |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Kapila | 2026-02-24 11:28:43 | Re: [PATCH] Support automatic sequence replication |
| Previous Message | Amit Kapila | 2026-02-24 11:25:20 | Re: [PATCH] Support automatic sequence replication |