]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Align PGPROC to cache line boundary
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sun, 22 Feb 2026 11:13:43 +0000 (13:13 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sun, 22 Feb 2026 11:13:43 +0000 (13:13 +0200)
On common architectures, the PGPROC struct happened to be a multiple
of 64 bytes on PG 18, but it's changed on 'master' since. There was
worry that changing the alignment might hurt performance, due to false
cacheline sharing across elements in the proc array. However, there
was no explicit alignment, so any alignment to cache lines was
accidental. Add explicit alignment to remove worry about false
sharing.

Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://www.postgresql.org/message-id/3dd6f70c-b94d-4428-8e75-74a7136396be@iki.fi

src/include/storage/proc.h

index b2fd4d029591f62140816210e56be921c91d3888..a8d2e7db1a1e8c3cdbb5365f3909b51f6d8f736f 100644 (file)
@@ -374,8 +374,16 @@ typedef struct PGPROC
         ************************************************************************/
 
        uint32          wait_event_info;        /* proc's wait information */
-} PGPROC;
+}
 
+/*
+ * If compiler understands aligned pragma, use it to align the struct at cache
+ * line boundaries.  This is just for performance, to avoid false sharing.
+ */
+#if defined(pg_attribute_aligned)
+                       pg_attribute_aligned(PG_CACHE_LINE_SIZE)
+#endif
+PGPROC;
 
 extern PGDLLIMPORT PGPROC *MyProc;