PostgreSQL 10.0 preview 性能增强 - 支持64bit atomic

2 minute read



Add a basic atomic ops API abstracting away platform/architecture details.  
author	Andres Freund <>	  
Fri, 26 Sep 2014 05:49:05 +0800 (23:49 +0200)  
committer	Andres Freund <>	  
Fri, 26 Sep 2014 05:49:05 +0800 (23:49 +0200)  
commit	b64d92f1a5602c55ee8b27a7ac474f03b7aee340  
tree	2ac33fb70d31585297ae8baeb674ef757544a1d7	tree | snapshot  
parent	9111d46351e8c3d82452a7454e43ccbf1991b3dc	commit | diff  
Add a basic atomic ops API abstracting away platform/architecture details.  
Several upcoming performance/scalability improvements require atomic  
operations. This new API avoids the need to splatter compiler and  
architecture dependent code over all the locations employing atomic  
For several of the potential usages it'd be problematic to maintain  
both, a atomics using implementation and one using spinlocks or  
similar. In all likelihood one of the implementations would not get  
tested regularly under concurrency. To avoid that scenario the new API  
provides a automatic fallback of atomic operations to spinlocks. All  
properties of atomic operations are maintained. This fallback -  
obviously - isn't as fast as just using atomic ops, but it's not bad  
either. For one of the future users the atomics ontop spinlocks  
implementation was actually slightly faster than the old purely  
spinlock using implementation. That's important because it reduces the  
fear of regressing older platforms when improving the scalability for  
new ones.  
The API, loosely modeled after the C11 atomics support, currently  
provides 'atomic flags' and 32 bit unsigned integers. If the platform  
efficiently supports atomic 64 bit unsigned integers those are also  
To implement atomics support for a platform/architecture/compiler for  
a type of atomics 32bit compare and exchange needs to be  
implemented. If available and more efficient native support for flags,  
32 bit atomic addition, and corresponding 64 bit operations may also  
be provided. Additional useful atomic operations are implemented  
generically ontop of these.  
The implementation for various versions of gcc, msvc and sun studio have  
been tested. Additional existing stub implementations for  
* Intel icc  
* HUPX acc  
* IBM xlc  
are included but have never been tested. These will likely require  
fixes based on buildfarm and user feedback.  
As atomic operations also require barriers for some operations the  
existing barrier support has been moved into the atomics code.  
Author: Andres Freund with contributions from Oskari Saarenmaa  
Reviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro Herrera  

10.0 新增64bit atomic支持

Improve 64bit atomics support.  
author	Andres Freund <>	  
Sat, 8 Apr 2017 05:44:47 +0800 (14:44 -0700)  
committer	Andres Freund <>	  
Sat, 8 Apr 2017 05:48:11 +0800 (14:48 -0700)  
commit	e8fdbd58fe564a29977f4331cd26f9697d76fc40  
tree	7ac78010b4ad51730fe948a79e7c5d7e5f461981	tree | snapshot  
parent	28afad5c85b436f19d9f2c0e3197c7db960fef6f	commit | diff  
Improve 64bit atomics support.  
When adding atomics back in b64d92f1a, I added 64bit support as  
optional; there wasn't yet a direct user in sight.  That turned out to  
be a bit short-sighted, it'd already have been useful a number of times.  
Add a fallback implementation of 64bit atomics, just like the one we  
have for 32bit atomics.  
Additionally optimize reads/writes to 64bit on a number of platforms  
where aligned writes of that size are atomic. This can now be tested  
Author: Andres Freund  
Reviewed-By: Amit Kapila  




Flag Counter

digoal’s 大量PostgreSQL文章入口