diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-10-28 17:08:09 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-10-28 17:08:09 -0400 |
commit | 53f1ca59b5875f1d3e95ee709ecaddcbdfdbd175 (patch) | |
tree | 8b99d7bf6dd756a5994846ca6295dd4d15974503 /src/backend/storage/buffer/bufmgr.c | |
parent | b6335a3f1b33e5dc52e755956d8648f0813252c4 (diff) | |
download | postgresql-53f1ca59b5875f1d3e95ee709ecaddcbdfdbd175.tar.gz postgresql-53f1ca59b5875f1d3e95ee709ecaddcbdfdbd175.zip |
Allow hint bits to be set sooner for temporary and unlogged tables.
We need not wait until the commit record is durably on disk, because
in the event of a crash the page we're updating with hint bits will
be gone anyway. Per off-list report from Heikki Linnakangas, this
can significantly degrade the performance of unlogged tables; I was
able to show a 2x speedup from this patch on a pgbench run with scale
factor 15. In practice, this will mostly help small, heavily updated
tables, because on larger tables you're unlikely to run into the same
row again before the commit record makes it out to disk.
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 8647eddcb42..f47f1b66b1f 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -1929,6 +1929,35 @@ RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum) return smgrnblocks(relation->rd_smgr, forkNum); } +/* + * BufferIsPermanent + * Determines whether a buffer will potentially still be around after + * a crash. Caller must hold a buffer pin. + */ +bool +BufferIsPermanent(Buffer buffer) +{ + volatile BufferDesc *bufHdr; + + /* Local buffers are used only for temp relations. */ + if (BufferIsLocal(buffer)) + return false; + + /* Make sure we've got a real buffer, and that we hold a pin on it. */ + Assert(BufferIsValid(buffer)); + Assert(BufferIsPinned(buffer)); + + /* + * BM_PERMANENT can't be changed while we hold a pin on the buffer, so + * we need not bother with the buffer header spinlock. Even if someone + * else changes the buffer header flags while we're doing this, we assume + * that changing an aligned 2-byte BufFlags value is atomic, so we'll read + * the old value or the new value, but not random garbage. + */ + bufHdr = &BufferDescriptors[buffer - 1]; + return (bufHdr->flags & BM_PERMANENT) != 0; +} + /* --------------------------------------------------------------------- * DropRelFileNodeBuffers * |