Barriers, Volatile, and Atomics: How PostgreSQL Orders Memory Accesses
Comments
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Ranked by a public rubric, not by votes: what a comment adds counts, not who wrote it. How comments are ranked · Comment rules
Summary
Jan Nidzwetzki's post explains why PostgreSQL's shared-memory code needs compiler and CPU barriers. GCC 14.2 at -O2 swaps two stores in a writer function, letting a reader on another core see done=true with stale data; pg_compiler_barrier() restores the order. It then covers store buffers and invalidate queues, noting that x86 permits only Store→Load reordering while ARM permits all four. Code that runs on x86 may therefore fail on ARM servers such as Graviton. Several hardware and PostgreSQL version details could not be verified.