postgresql/src/backend
Andres Freund 2d115e47c8 Fix various shortcomings of the new PrivateRefCount infrastructure.
As noted by Tom Lane the improvements in 4b4b680c3d had the problem
that in some situations we searched, entered and modified entries in
the private refcount hash while holding a spinlock. I had tried to
keep the logic entirely local to PinBuffer_Locked(), but that's not
really possible given it's called with a spinlock held...

Besides being disadvantageous from a performance point of view, this
also has problems with error handling safety. If we failed inserting
an entry into the hashtable due to an out of memory error, we'd error
out with a held spinlock. Not good.

Change the way private refcounts are manipulated: Before a buffer can
be tracked an entry has to be reserved using
ReservePrivateRefCountEntry(); then, if a entry is not found using
GetPrivateRefCountEntry(), it can be entered with
NewPrivateRefCountEntry().

Also take advantage of the fact that PinBuffer_Locked() currently is
never called for buffers that already have been pinned by the current
backend and don't search the private refcount entries for preexisting
local pins. That results in a small, but measurable, performance
improvement.

Additionally make ReleaseBuffer() always call UnpinBuffer() for shared
buffers. That avoids duplicating work in an eventual UnpinBuffer()
call that already has been done in ReleaseBuffer() and also saves some
code.

Per discussion with Tom Lane.

Discussion: 15028.1418772313@sss.pgh.pa.us
2015-01-19 23:59:41 +01:00
..
access Use abbreviated keys for faster sorting of text datums. 2015-01-19 15:28:27 -05:00
bootstrap Remove some dead IsUnderPostmaster code from bootstrap.c. 2015-01-14 00:37:02 +01:00
catalog Spell the X072 feature correctly, was missing "with". 2015-01-13 16:08:55 +02:00
commands Use abbreviated keys for faster sorting of text datums. 2015-01-19 15:28:27 -05:00
executor Use abbreviated keys for faster sorting of text datums. 2015-01-19 15:28:27 -05:00
foreign Update copyright for 2015 2015-01-06 11:43:47 -05:00
lib Use abbreviated keys for faster sorting of text datums. 2015-01-19 15:28:27 -05:00
libpq Update copyright for 2015 2015-01-06 11:43:47 -05:00
main Always set the six locale category environment variables in main(). 2015-01-07 22:34:57 -05:00
nodes Improve new caching logic in tbm_add_tuples(). 2015-01-16 13:28:30 -05:00
optimizer Fix ancient thinko in default table rowcount estimation. 2015-01-18 17:04:11 -05:00
parser Fix get_object_address argument type for extension statement 2015-01-12 15:32:48 -03:00
po Translation updates 2014-12-15 00:25:35 -05:00
port Add barriers to the latch code. 2015-01-13 12:58:43 +01:00
postmaster Add a default local latch for use in signal handlers. 2015-01-14 18:45:22 +01:00
regex Update copyright for 2015 2015-01-06 11:43:47 -05:00
replication Replace walsender's latch with the general shared latch. 2015-01-17 13:00:42 +01:00
rewrite Update copyright for 2015 2015-01-06 11:43:47 -05:00
snowball Update copyright for 2015 2015-01-06 11:43:47 -05:00
storage Fix various shortcomings of the new PrivateRefCount infrastructure. 2015-01-19 23:59:41 +01:00
tcop Add a default local latch for use in signal handlers. 2015-01-14 18:45:22 +01:00
tsearch Update copyright for 2015 2015-01-06 11:43:47 -05:00
utils Use abbreviated keys for faster sorting of text datums. 2015-01-19 15:28:27 -05:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
Makefile Update copyright for 2015 2015-01-06 11:43:47 -05:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
nls.mk xlogreader.c: Fix report_invalid_record translatability flag 2015-01-09 12:34:25 -03:00