Re: better atomics - v0.5 - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: better atomics - v0.5
Date
Msg-id CAA4eK1+ogD7vefvGbPyZ6c3aPUVVJ1UqWJwMrpyPfykzahAg=g@mail.gmail.com
Whole thread Raw
In response to Re: better atomics - v0.5  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-hackers
On Sat, Jul 12, 2014 at 1:26 AM, Martijn van Oosterhout <kleptog@svana.org> wrote:
> On Thu, Jul 10, 2014 at 08:46:55AM +0530, Amit Kapila wrote:
> > As per my understanding of the general theory around barriers,
> > read and write are defined to avoid reordering due to compiler and
> > full memory barriers are defined to avoid reordering due to processors.
> > There are some processors that support instructions for memory
> > barriers with acquire, release and fence semantics.
>
> Not exactly, both compilers and processors can rearrange loads and
> stores.  Because the architecture most developers work on (x86) has
> such a strong memory model (it's goes to lot of effort to hide
> reordering) people are under the impression that it's only the compiler
> you need to worry about, but that's not true for any other
> architechture.

I am not saying that we need only barriers to avoid reordering due to 
compiler, rather my point was that we need to avoid reordering due to
both compiler and processor, however ways to achieve it require different
API's

> Memory barriers/fences are on the whole discouraged if you can use
> acquire/release semantics because the latter are faster and much easier
> to optimise for.

Do all processors support instructions for memory barriers with acquire,
release semantics?

> I strongly recommend the "Atomic Weapons" talk on the C11 memory model
> to help understand how they work. As a bonus it includes correct
> implementations for the major architectures.

Yes that will be a good if we can can implement as per C11 memory model and
thats what I am referring while reviewing this patch, however even if that is not
possible or difficult to achieve in all cases, it is worth to have a discussion for
memory model used in current API's implemented in patch. 

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: things I learned from working on memory allocation
Next
From: Fabrízio de Royes Mello
Date:
Subject: Re: [GSoC2014] Patch ALTER TABLE ... SET LOGGED