pgsql: Be more careful about barriers when releasing BackgroundWorkerSl

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Be more careful about barriers when releasing BackgroundWorkerSl
Date: 2021-05-15 16:21:29
Message-ID: E1lhx2f-00083Y-9v@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Be more careful about barriers when releasing BackgroundWorkerSlots.

ForgetBackgroundWorker lacked any memory barrier at all, while
BackgroundWorkerStateChange had one but unaccountably did
additional manipulation of the slot after the barrier. AFAICS,
the rule must be that the barrier is immediately before setting
or clearing slot->in_use.

It looks like back in 9.6 when ForgetBackgroundWorker was first
written, there might have been some case for not needing a
barrier there, but I'm not very convinced of that --- the fact
that the load of bgw_notify_pid is in the caller doesn't seem
to guarantee no memory ordering problem. So patch 9.6 too.

It's likely that this doesn't fix any observable bug on Intel
hardware, but machines with weaker memory ordering rules could
have problems here.

Discussion: https://postgr.es/m/4046084.1620244003@sss.pgh.pa.us

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5d195dc40af07cc822a20fd8a9a9f9de2a1df43d

Modified Files
--------------
src/backend/postmaster/bgworker.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2021-05-15 18:14:18 pgsql: Allow compute_query_id to be set to 'auto' and make it default
Previous Message Peter Geoghegan 2021-05-14 22:08:55 pgsql: Harden nbtree deduplication posting split code.