From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org, Jaime Casanova <jaime.casanova@2ndQuadrant.com>
Subject: Re: LogwrtResult contended spinlock
Date: Thu, 3 Sep 2020 14:34:52 -0400
Message-ID: <20200903183452.GA10634@alvherre.pgsql> (raw)
In-Reply-To: <E494450B-9C6B-4716-9902-976DC7D69490@anarazel.de>
Looking at patterns like this
if (XLogCtl->LogwrtRqst.Write < EndPos)
XLogCtl->LogwrtRqst.Write = EndPos;
It seems possible to implement with
do {
XLogRecPtr currwrite;
currwrite = pg_atomic_read_u64(LogwrtRqst.Write);
if (currwrite > EndPos)
break; // already done by somebody else
if (pg_atomic_compare_exchange_u64(LogwrtRqst.Write,
currwrite, EndPos))
break; // successfully updated
} while (true);
This assumes that LogwrtRqst.Write never goes backwards, so it doesn't
seem good material for a general routine.
This *seems* correct to me, though this is muddy territory to me. Also,
are there better ways to go about this?
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvherre@2ndquadrant.com, andres@anarazel.de, jaime.casanova@2ndQuadrant.com
Subject: Re: LogwrtResult contended spinlock
In-Reply-To: <20200903183452.GA10634@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox