summaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/buffer')
-rw-r--r--src/backend/storage/buffer/buf_init.c43
-rw-r--r--src/backend/storage/buffer/bufmgr.c104
-rw-r--r--src/backend/storage/buffer/s_lock.c6
-rw-r--r--src/backend/storage/buffer/xlog_bufmgr.c104
4 files changed, 14 insertions, 243 deletions
diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c
index 3c40009422d..0fda21972f6 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.37 2000/10/23 04:10:06 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.38 2000/11/28 23:27:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -56,13 +56,6 @@ int Num_Descriptors;
BufferDesc *BufferDescriptors;
BufferBlock BufferBlocks;
-#ifndef HAS_TEST_AND_SET
-long *NWaitIOBackendP;
-
-#endif
-
-extern IpcSemaphoreId WaitIOSemId;
-
long *PrivateRefCount; /* also used in freelist.c */
bits8 *BufferLocks; /* flag bits showing locks I have set */
BufferTag *BufferTagLastDirtied; /* tag buffer had when last
@@ -139,7 +132,7 @@ long int LocalBufferFlushCount;
* amount of available memory.
*/
void
-InitBufferPool(IPCKey key)
+InitBufferPool(void)
{
bool foundBufs,
foundDescs;
@@ -170,18 +163,6 @@ InitBufferPool(IPCKey key)
ShmemInitStruct("Buffer Blocks",
NBuffers * BLCKSZ, &foundBufs);
-#ifndef HAS_TEST_AND_SET
- {
- bool foundNWaitIO;
-
- NWaitIOBackendP = (long *) ShmemInitStruct("#Backends Waiting IO",
- sizeof(long),
- &foundNWaitIO);
- if (!foundNWaitIO)
- *NWaitIOBackendP = 0;
- }
-#endif
-
if (foundDescs || foundBufs)
{
@@ -214,10 +195,8 @@ InitBufferPool(IPCKey key)
buf->flags = (BM_DELETED | BM_FREE | BM_VALID);
buf->refcount = 0;
buf->buf_id = i;
-#ifdef HAS_TEST_AND_SET
S_INIT_LOCK(&(buf->io_in_progress_lock));
S_INIT_LOCK(&(buf->cntx_lock));
-#endif
}
/* close the circular queue */
@@ -231,22 +210,6 @@ InitBufferPool(IPCKey key)
SpinRelease(BufMgrLock);
-#ifndef HAS_TEST_AND_SET
- {
- extern IpcSemaphoreId WaitIOSemId;
- extern IpcSemaphoreId WaitCLSemId;
-
- WaitIOSemId = IpcSemaphoreCreate(IPCKeyGetWaitIOSemaphoreKey(key),
- 1, IPCProtection, 0, 1);
- if (WaitIOSemId < 0)
- elog(FATAL, "InitBufferPool: IpcSemaphoreCreate(WaitIOSemId) failed");
- WaitCLSemId = IpcSemaphoreCreate(IPCKeyGetWaitCLSemaphoreKey(key),
- 1, IPCProtection,
- IpcSemaphoreDefaultStartValue, 1);
- if (WaitCLSemId < 0)
- elog(FATAL, "InitBufferPool: IpcSemaphoreCreate(WaitCLSemId) failed");
- }
-#endif
PrivateRefCount = (long *) calloc(NBuffers, sizeof(long));
BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8));
BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag));
@@ -262,7 +225,7 @@ InitBufferPool(IPCKey key)
* ----------------------------------------------------
*/
int
-BufferShmemSize()
+BufferShmemSize(void)
{
int size = 0;
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 907e8194743..8ed03138fac 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.94 2000/11/20 16:47:31 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.95 2000/11/28 23:27:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -93,12 +93,6 @@ extern void AbortBufferIO(void);
*/
#define BUFFER_IS_BROKEN(buf) ((buf->flags & BM_IO_ERROR) && !(buf->flags & BM_DIRTY))
-#ifndef HAS_TEST_AND_SET
-static void SignalIO(BufferDesc *buf);
-extern long *NWaitIOBackendP; /* defined in buf_init.c */
-
-#endif /* HAS_TEST_AND_SET */
-
static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum,
bool bufferLockHeld);
static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
@@ -1187,27 +1181,7 @@ BufferSync()
*
* Should be entered with buffer manager spinlock held; releases it before
* waiting and re-acquires it afterwards.
- *
- * OLD NOTES:
- * Because IO_IN_PROGRESS conflicts are
- * expected to be rare, there is only one BufferIO
- * lock in the entire system. All processes block
- * on this semaphore when they try to use a buffer
- * that someone else is faulting in. Whenever a
- * process finishes an IO and someone is waiting for
- * the buffer, BufferIO is signaled (SignalIO). All
- * waiting processes then wake up and check to see
- * if their buffer is now ready. This implementation
- * is simple, but efficient enough if WaitIO is
- * rarely called by multiple processes simultaneously.
- *
- * NEW NOTES:
- * The above is true only on machines without test-and-set
- * semaphores (which we hope are few, these days). On better
- * hardware, each buffer has a spinlock that we can wait on.
*/
-#ifdef HAS_TEST_AND_SET
-
static void
WaitIO(BufferDesc *buf, SPINLOCK spinlock)
{
@@ -1224,43 +1198,6 @@ WaitIO(BufferDesc *buf, SPINLOCK spinlock)
}
}
-#else /* !HAS_TEST_AND_SET */
-
-IpcSemaphoreId WaitIOSemId;
-IpcSemaphoreId WaitCLSemId;
-
-static void
-WaitIO(BufferDesc *buf, SPINLOCK spinlock)
-{
- bool inProgress;
-
- for (;;)
- {
-
- /* wait until someone releases IO lock */
- (*NWaitIOBackendP)++;
- SpinRelease(spinlock);
- IpcSemaphoreLock(WaitIOSemId, 0, 1);
- SpinAcquire(spinlock);
- inProgress = (buf->flags & BM_IO_IN_PROGRESS);
- if (!inProgress)
- break;
- }
-}
-
-/*
- * SignalIO
- */
-static void
-SignalIO(BufferDesc *buf)
-{
- /* somebody better be waiting. */
- Assert(buf->refcount > 1);
- IpcSemaphoreUnlock(WaitIOSemId, 0, *NWaitIOBackendP);
- *NWaitIOBackendP = 0;
-}
-
-#endif /* HAS_TEST_AND_SET */
long NDirectFileRead; /* some I/O's are direct file access.
* bypass bufmgr */
@@ -2297,11 +2234,7 @@ UnlockBuffers()
Assert(BufferIsValid(i + 1));
buf = &(BufferDescriptors[i]);
-#ifdef HAS_TEST_AND_SET
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
if (BufferLocks[i] & BL_R_LOCK)
{
@@ -2324,11 +2257,9 @@ UnlockBuffers()
Assert(buf->w_lock);
buf->w_lock = false;
}
-#ifdef HAS_TEST_AND_SET
+
S_UNLOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
+
BufferLocks[i] = 0;
}
}
@@ -2346,11 +2277,7 @@ LockBuffer(Buffer buffer, int mode)
buf = &(BufferDescriptors[buffer - 1]);
buflock = &(BufferLocks[buffer - 1]);
-#ifdef HAS_TEST_AND_SET
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
if (mode == BUFFER_LOCK_UNLOCK)
{
@@ -2380,15 +2307,9 @@ LockBuffer(Buffer buffer, int mode)
Assert(!(*buflock & (BL_R_LOCK | BL_W_LOCK | BL_RI_LOCK)));
while (buf->ri_lock || buf->w_lock)
{
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->cntx_lock));
s_lock_sleep(i++);
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
- s_lock_sleep(i++);
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
}
(buf->r_locks)++;
*buflock |= BL_R_LOCK;
@@ -2412,15 +2333,9 @@ LockBuffer(Buffer buffer, int mode)
*buflock |= BL_RI_LOCK;
buf->ri_lock = true;
}
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->cntx_lock));
s_lock_sleep(i++);
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
- s_lock_sleep(i++);
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
}
buf->w_lock = true;
*buflock |= BL_W_LOCK;
@@ -2438,12 +2353,7 @@ LockBuffer(Buffer buffer, int mode)
else
elog(ERROR, "LockBuffer: unknown lock mode %d", mode);
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
-
}
/*
@@ -2471,7 +2381,6 @@ StartBufferIO(BufferDesc *buf, bool forInput)
Assert(!InProgressBuf);
Assert(!(buf->flags & BM_IO_IN_PROGRESS));
buf->flags |= BM_IO_IN_PROGRESS;
-#ifdef HAS_TEST_AND_SET
/*
* There used to be
@@ -2485,7 +2394,7 @@ StartBufferIO(BufferDesc *buf, bool forInput)
* happen -- tgl
*/
S_LOCK(&(buf->io_in_progress_lock));
-#endif /* HAS_TEST_AND_SET */
+
InProgressBuf = buf;
IsForInput = forInput;
}
@@ -2502,12 +2411,7 @@ static void
TerminateBufferIO(BufferDesc *buf)
{
Assert(buf == InProgressBuf);
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->io_in_progress_lock));
-#else
- if (buf->refcount > 1)
- SignalIO(buf);
-#endif /* HAS_TEST_AND_SET */
InProgressBuf = (BufferDesc *) 0;
}
diff --git a/src/backend/storage/buffer/s_lock.c b/src/backend/storage/buffer/s_lock.c
index 883c150b923..72b167977d5 100644
--- a/src/backend/storage/buffer/s_lock.c
+++ b/src/backend/storage/buffer/s_lock.c
@@ -1,22 +1,22 @@
/*-------------------------------------------------------------------------
*
* s_lock.c
- * buffer manager interface routines
+ * Spinlock support routines
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/s_lock.c,v 1.25 2000/11/16 05:51:01 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/s_lock.c,v 1.26 2000/11/28 23:27:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
+#include "postgres.h"
#include <sys/time.h>
#include <unistd.h>
-#include "postgres.h"
#include "storage/s_lock.h"
diff --git a/src/backend/storage/buffer/xlog_bufmgr.c b/src/backend/storage/buffer/xlog_bufmgr.c
index ff6bff29a1d..9672510547a 100644
--- a/src/backend/storage/buffer/xlog_bufmgr.c
+++ b/src/backend/storage/buffer/xlog_bufmgr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.4 2000/11/22 02:19:14 inoue Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.5 2000/11/28 23:27:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -88,12 +88,6 @@ extern void AbortBufferIO(void);
*/
#define BUFFER_IS_BROKEN(buf) ((buf->flags & BM_IO_ERROR) && !(buf->flags & BM_DIRTY))
-#ifndef HAS_TEST_AND_SET
-static void SignalIO(BufferDesc *buf);
-extern long *NWaitIOBackendP; /* defined in buf_init.c */
-
-#endif /* HAS_TEST_AND_SET */
-
static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum,
bool bufferLockHeld);
static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
@@ -853,27 +847,7 @@ BufferSync()
*
* Should be entered with buffer manager spinlock held; releases it before
* waiting and re-acquires it afterwards.
- *
- * OLD NOTES:
- * Because IO_IN_PROGRESS conflicts are
- * expected to be rare, there is only one BufferIO
- * lock in the entire system. All processes block
- * on this semaphore when they try to use a buffer
- * that someone else is faulting in. Whenever a
- * process finishes an IO and someone is waiting for
- * the buffer, BufferIO is signaled (SignalIO). All
- * waiting processes then wake up and check to see
- * if their buffer is now ready. This implementation
- * is simple, but efficient enough if WaitIO is
- * rarely called by multiple processes simultaneously.
- *
- * NEW NOTES:
- * The above is true only on machines without test-and-set
- * semaphores (which we hope are few, these days). On better
- * hardware, each buffer has a spinlock that we can wait on.
*/
-#ifdef HAS_TEST_AND_SET
-
static void
WaitIO(BufferDesc *buf, SPINLOCK spinlock)
{
@@ -890,43 +864,6 @@ WaitIO(BufferDesc *buf, SPINLOCK spinlock)
}
}
-#else /* !HAS_TEST_AND_SET */
-
-IpcSemaphoreId WaitIOSemId;
-IpcSemaphoreId WaitCLSemId;
-
-static void
-WaitIO(BufferDesc *buf, SPINLOCK spinlock)
-{
- bool inProgress;
-
- for (;;)
- {
-
- /* wait until someone releases IO lock */
- (*NWaitIOBackendP)++;
- SpinRelease(spinlock);
- IpcSemaphoreLock(WaitIOSemId, 0, 1);
- SpinAcquire(spinlock);
- inProgress = (buf->flags & BM_IO_IN_PROGRESS);
- if (!inProgress)
- break;
- }
-}
-
-/*
- * SignalIO
- */
-static void
-SignalIO(BufferDesc *buf)
-{
- /* somebody better be waiting. */
- Assert(buf->refcount > 1);
- IpcSemaphoreUnlock(WaitIOSemId, 0, *NWaitIOBackendP);
- *NWaitIOBackendP = 0;
-}
-
-#endif /* HAS_TEST_AND_SET */
long NDirectFileRead; /* some I/O's are direct file access.
* bypass bufmgr */
@@ -1965,11 +1902,7 @@ UnlockBuffers()
Assert(BufferIsValid(i + 1));
buf = &(BufferDescriptors[i]);
-#ifdef HAS_TEST_AND_SET
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
if (BufferLocks[i] & BL_R_LOCK)
{
@@ -1992,11 +1925,9 @@ UnlockBuffers()
Assert(buf->w_lock);
buf->w_lock = false;
}
-#ifdef HAS_TEST_AND_SET
+
S_UNLOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
+
BufferLocks[i] = 0;
}
}
@@ -2014,11 +1945,7 @@ LockBuffer(Buffer buffer, int mode)
buf = &(BufferDescriptors[buffer - 1]);
buflock = &(BufferLocks[buffer - 1]);
-#ifdef HAS_TEST_AND_SET
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
if (mode == BUFFER_LOCK_UNLOCK)
{
@@ -2048,15 +1975,9 @@ LockBuffer(Buffer buffer, int mode)
Assert(!(*buflock & (BL_R_LOCK | BL_W_LOCK | BL_RI_LOCK)));
while (buf->ri_lock || buf->w_lock)
{
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->cntx_lock));
s_lock_sleep(i++);
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
- s_lock_sleep(i++);
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
}
(buf->r_locks)++;
*buflock |= BL_R_LOCK;
@@ -2080,15 +2001,9 @@ LockBuffer(Buffer buffer, int mode)
*buflock |= BL_RI_LOCK;
buf->ri_lock = true;
}
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->cntx_lock));
s_lock_sleep(i++);
S_LOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
- s_lock_sleep(i++);
- IpcSemaphoreLock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
}
buf->w_lock = true;
*buflock |= BL_W_LOCK;
@@ -2109,12 +2024,7 @@ LockBuffer(Buffer buffer, int mode)
else
elog(ERROR, "LockBuffer: unknown lock mode %d", mode);
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->cntx_lock));
-#else
- IpcSemaphoreUnlock(WaitCLSemId, 0, IpcExclusiveLock);
-#endif
-
}
/*
@@ -2142,7 +2052,6 @@ StartBufferIO(BufferDesc *buf, bool forInput)
Assert(!InProgressBuf);
Assert(!(buf->flags & BM_IO_IN_PROGRESS));
buf->flags |= BM_IO_IN_PROGRESS;
-#ifdef HAS_TEST_AND_SET
/*
* There used to be
@@ -2156,7 +2065,7 @@ StartBufferIO(BufferDesc *buf, bool forInput)
* happen -- tgl
*/
S_LOCK(&(buf->io_in_progress_lock));
-#endif /* HAS_TEST_AND_SET */
+
InProgressBuf = buf;
IsForInput = forInput;
}
@@ -2173,12 +2082,7 @@ static void
TerminateBufferIO(BufferDesc *buf)
{
Assert(buf == InProgressBuf);
-#ifdef HAS_TEST_AND_SET
S_UNLOCK(&(buf->io_in_progress_lock));
-#else
- if (buf->refcount > 1)
- SignalIO(buf);
-#endif /* HAS_TEST_AND_SET */
InProgressBuf = (BufferDesc *) 0;
}