postgresql/src/backend/storage
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
..
buffer Fix various shortcomings of the new PrivateRefCount infrastructure. 2015-01-19 23:59:41 +01:00
file Update copyright for 2015 2015-01-06 11:43:47 -05:00
freespace Update copyright for 2015 2015-01-06 11:43:47 -05:00
ipc Add a default local latch for use in signal handlers. 2015-01-14 18:45:22 +01:00
large_object Update copyright for 2015 2015-01-06 11:43:47 -05:00
lmgr Add a default local latch for use in signal handlers. 2015-01-14 18:45:22 +01:00
page Update copyright for 2015 2015-01-06 11:43:47 -05:00
smgr Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00