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

2 minute read

背景

起源

Add a basic atomic ops API abstracting away platform/architecture details.  
  
author	Andres Freund <andres@anarazel.de>	  
Fri, 26 Sep 2014 05:49:05 +0800 (23:49 +0200)  
committer	Andres Freund <andres@anarazel.de>	  
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  
ops.  
  
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  
provided.  
  
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  
Discussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com,  
    20131015123303.GH5300@awork2.anarazel.de,  
    20131028205522.GI20248@awork2.anarazel.de  

10.0 新增64bit atomic支持

Improve 64bit atomics support.  
  
author	Andres Freund <andres@anarazel.de>	  
Sat, 8 Apr 2017 05:44:47 +0800 (14:44 -0700)  
committer	Andres Freund <andres@anarazel.de>	  
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  
with PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY.  
  
Author: Andres Freund  
Reviewed-By: Amit Kapila  
Discussion: https://postgr.es/m/20160330230914.GH13305@awork2.anarazel.de  

这个patch的讨论,详见邮件组,本文末尾URL。

PostgreSQL社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以PostgreSQL的稳定性也是远近闻名的。

参考

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=e8fdbd58fe564a29977f4331cd26f9697d76fc40

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b64d92f1a

Flag Counter

digoal’s 大量PostgreSQL文章入口