From: Vadim B. Mikheev Date: Fri, 22 Dec 2000 20:04:43 +0000 (+0000) Subject: Avoid XLogFlush for clean buffers in BufferSync. X-Git-Tag: REL7_1_BETA2~96 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=369aace5f3dc46409f6777c0fed9ef113db43d4a;p=postgresql Avoid XLogFlush for clean buffers in BufferSync. --- diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 7978924553..7586491ec4 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.98 2000/11/30 19:03:25 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.99 2000/12/22 20:04:43 vadim Exp $ * *------------------------------------------------------------------------- */ @@ -723,6 +723,7 @@ BufferSync() RelFileNode rnode; XLogRecPtr recptr; Relation reln = NULL; + bool dirty = false; for (i = 0, bufHdr = BufferDescriptors; i < NBuffers; i++, bufHdr++) { @@ -745,6 +746,7 @@ BufferSync() buffer = BufferDescriptorGetBuffer(bufHdr); rnode = bufHdr->tag.rnode; + dirty = bufHdr->flags & BM_DIRTY; SpinRelease(BufMgrLock); @@ -758,6 +760,17 @@ BufferSync() */ LockBuffer(buffer, BUFFER_LOCK_SHARE); + if (!dirty && !(bufHdr->cntxDirty)) + { + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + SpinAcquire(BufMgrLock); + UnpinBuffer(bufHdr); + SpinRelease(BufMgrLock); + if (reln != (Relation) NULL) + RelationDecrementReferenceCount(reln); + continue; + } + /* * Force XLOG flush for buffer' LSN */ @@ -766,9 +779,8 @@ BufferSync() /* * Now it's safe to write buffer to disk - * (if needed at all -:)) + * (if no one else already) */ - SpinAcquire(BufMgrLock); if (bufHdr->flags & BM_IO_IN_PROGRESS) WaitIO(bufHdr, BufMgrLock); @@ -824,20 +836,19 @@ BufferSync() */ if (!(bufHdr->flags & BM_JUST_DIRTIED)) bufHdr->flags &= ~BM_DIRTY; + UnpinBuffer(bufHdr); + SpinRelease(BufMgrLock); } else + { + UnpinBuffer(bufHdr); + SpinRelease(BufMgrLock); LockBuffer(buffer, BUFFER_LOCK_UNLOCK); - - UnpinBuffer(bufHdr); - - SpinRelease(BufMgrLock); + } /* drop refcnt obtained by RelationNodeCacheGetRelation */ if (reln != (Relation) NULL) - { RelationDecrementReferenceCount(reln); - reln = NULL; - } } }