pgsql: Fix various shortcomings of the new PrivateRefCount infrastructu

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix various shortcomings of the new PrivateRefCount infrastructu
Date: 2015-01-19 23:42:45
Message-ID: E1YDLy1-0004QY-NE@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix various shortcomings of the new PrivateRefCount infrastructure.

As noted by Tom Lane the improvements in 4b4b680c3d6 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(dot)1418772313(at)sss(dot)pgh(dot)pa(dot)us

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/2d115e47c861878669ba0814b3d97a4e4c347e8b

Modified Files
--------------
src/backend/storage/buffer/bufmgr.c | 359 +++++++++++++++++++----------------
1 file changed, 195 insertions(+), 164 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2015-01-20 04:02:15 pgsql: Adjust "pgstat wait timeout" message to be a translatable LOG me
Previous Message Robert Haas 2015-01-19 20:28:37 pgsql: Use abbreviated keys for faster sorting of text datums.