Skip site navigation (1) Skip section navigation (2)

pgsql: Do unlocked prechecks in bufmgr.c loops that scan the wholebuff

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Do unlocked prechecks in bufmgr.c loops that scan the wholebuff
Date: 2012-06-07 20:46:36
Message-ID: E1ScjbI-0006gh-FD@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Do unlocked prechecks in bufmgr.c loops that scan the whole buffer pool.

DropRelFileNodeBuffers, DropDatabaseBuffers, FlushRelationBuffers, and
FlushDatabaseBuffers have to scan the whole shared_buffers pool because
we have no index structure that would find the target buffers any more
efficiently than that.  This gets expensive with large NBuffers.  We can
shave some cycles from these loops by prechecking to see if the current
buffer is interesting before we acquire the buffer header lock.
Ordinarily such a test would be unsafe, but in these cases it should be
safe because we are already assuming that the caller holds a lock that
prevents any new target pages from being loaded into the buffer pool
concurrently.  Therefore, no buffer tag should be changing to a value of
interest, only away from a value of interest.  So a false negative match
is impossible, while a false positive is safe because we'll recheck after
acquiring the buffer lock.  Initial testing says that this speeds these
loops by a factor of 2X to 3X on common Intel hardware.

Patch for DropRelFileNodeBuffers by Jeff Janes (based on an idea of
Heikki's); extended to the remaining sequential scans by Tom Lane

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/e8d029a30b5a5fb74b848a8697b1dfa3f66d9697

Modified Files
--------------
src/backend/storage/buffer/bufmgr.c |   47 +++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 2 deletions(-)

pgsql-committers by date

Next:From: Peter EisentrautDate: 2012-06-07 21:11:13
Subject: pgsql: Documentation spell and markup checking
Previous:From: Simon RiggsDate: 2012-06-07 18:26:20
Subject: pgsql: Wake WALSender to reduce data loss at failover for asynccommit.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group