diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-09-29 04:02:27 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-09-29 04:02:27 +0000 |
commit | 499abb0c0f21cb861c5af1d49a06469f3cfcc1eb (patch) | |
tree | 0af6262d9b6d1159315e93e90e69047b959ea5f5 /src/backend/storage/buffer/buf_init.c | |
parent | 818fb55ac49b4b20e65d9899fc1784e54e86db58 (diff) | |
download | postgresql-499abb0c0f21cb861c5af1d49a06469f3cfcc1eb.tar.gz postgresql-499abb0c0f21cb861c5af1d49a06469f3cfcc1eb.zip |
Implement new 'lightweight lock manager' that's intermediate between
existing lock manager and spinlocks: it understands exclusive vs shared
lock but has few other fancy features. Replace most uses of spinlocks
with lightweight locks. All remaining uses of spinlocks have very short
lock hold times (a few dozen instructions), so tweak spinlock backoff
code to work efficiently given this assumption. All per my proposal on
pghackers 26-Sep-01.
Diffstat (limited to 'src/backend/storage/buffer/buf_init.c')
-rw-r--r-- | src/backend/storage/buffer/buf_init.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c index 819fe7e206c..45a2e4aa160 100644 --- a/src/backend/storage/buffer/buf_init.c +++ b/src/backend/storage/buffer/buf_init.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.43 2001/07/06 21:04:25 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.44 2001/09/29 04:02:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -28,10 +28,9 @@ #include "storage/fd.h" #include "storage/ipc.h" #include "storage/lmgr.h" -#include "storage/s_lock.h" #include "storage/shmem.h" #include "storage/smgr.h" -#include "storage/spin.h" +#include "storage/lwlock.h" #include "utils/builtins.h" #include "utils/hsearch.h" #include "utils/memutils.h" @@ -117,8 +116,6 @@ bool *BufferDirtiedByMe; /* T if buf has been dirtied in cur xact */ * */ -SPINLOCK BufMgrLock; - long int ReadBufferCount; long int ReadLocalBufferCount; long int BufferHitCount; @@ -151,7 +148,7 @@ InitBufferPool(void) * anyone else attached to the shmem at this point, we've got * problems. */ - SpinAcquire(BufMgrLock); + LWLockAcquire(BufMgrLock, LW_EXCLUSIVE); #ifdef BMTRACE CurTraceBuf = (long *) ShmemInitStruct("Buffer trace", @@ -186,8 +183,8 @@ InitBufferPool(void) /* * link the buffers into a circular, doubly-linked list to - * initialize free list. Still don't know anything about - * replacement strategy in this file. + * initialize free list, and initialize the buffer headers. + * Still don't know anything about replacement strategy in this file. */ for (i = 0; i < Data_Descriptors; block += BLCKSZ, buf++, i++) { @@ -197,12 +194,15 @@ InitBufferPool(void) buf->freePrev = i - 1; CLEAR_BUFFERTAG(&(buf->tag)); + buf->buf_id = i; + buf->data = MAKE_OFFSET(block); buf->flags = (BM_DELETED | BM_FREE | BM_VALID); buf->refcount = 0; - buf->buf_id = i; - S_INIT_LOCK(&(buf->io_in_progress_lock)); - S_INIT_LOCK(&(buf->cntx_lock)); + buf->io_in_progress_lock = LWLockAssign(); + buf->cntx_lock = LWLockAssign(); + buf->cntxDirty = false; + buf->wait_backend_id = 0; } /* close the circular queue */ @@ -214,7 +214,7 @@ InitBufferPool(void) InitBufTable(); InitFreeList(!foundDescs); - SpinRelease(BufMgrLock); + LWLockRelease(BufMgrLock); } /* |