*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.27 2000/03/17 02:36:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/hash/hashpage.c,v 1.28 2000/11/30 01:39:06 tgl Exp $
*
* NOTES
* Postgres hash pages look like ordinary relation pages. The opaque
#include "access/genam.h"
#include "access/hash.h"
#include "miscadmin.h"
+#include "storage/lmgr.h"
static void _hash_setpagelock(Relation rel, BlockNumber blkno, int access);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.40 2000/10/21 15:43:18 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.41 2000/11/30 01:39:06 tgl Exp $
*
* NOTES
* Postgres btree pages look like ordinary relation pages. The opaque
*
*-------------------------------------------------------------------------
*/
-#include <time.h>
-
#include "postgres.h"
+#include <time.h>
+
#include "access/nbtree.h"
#include "miscadmin.h"
+#include "storage/lmgr.h"
+
/*
* We use high-concurrency locking on btrees. There are two cases in
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.38 2000/11/28 23:27:55 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.39 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
+#include "postgres.h"
+
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
#include <signal.h>
-#include "postgres.h"
-
#include "catalog/catalog.h"
#include "executor/execdebug.h"
#include "miscadmin.h"
int Num_Descriptors;
BufferDesc *BufferDescriptors;
-BufferBlock BufferBlocks;
+Block *BufferBlockPointers;
long *PrivateRefCount; /* also used in freelist.c */
bits8 *BufferLocks; /* flag bits showing locks I have set */
/*
- * Initialize module:
+ * Initialize module: called once during shared-memory initialization
*
* should calculate size of pool dynamically based on the
* amount of available memory.
void
InitBufferPool(void)
{
+ char *BufferBlocks;
bool foundBufs,
foundDescs;
int i;
ShmemInitStruct("Buffer Descriptors",
Num_Descriptors * sizeof(BufferDesc), &foundDescs);
- BufferBlocks = (BufferBlock)
+ BufferBlocks = (char *)
ShmemInitStruct("Buffer Blocks",
NBuffers * BLCKSZ, &foundBufs);
if (foundDescs || foundBufs)
{
-
/* both should be present or neither */
Assert(foundDescs && foundBufs);
-
}
else
{
BufferDesc *buf;
- unsigned long block;
+ char *block;
buf = BufferDescriptors;
- block = (unsigned long) BufferBlocks;
+ block = BufferBlocks;
/*
* link the buffers into a circular, doubly-linked list to
SpinRelease(BufMgrLock);
+ BufferBlockPointers = (Block *) calloc(NBuffers, sizeof(Block));
PrivateRefCount = (long *) calloc(NBuffers, sizeof(long));
BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8));
BufferTagLastDirtied = (BufferTag *) calloc(NBuffers, sizeof(BufferTag));
BufferBlindLastDirtied = (BufferBlindId *) calloc(NBuffers, sizeof(BufferBlindId));
BufferDirtiedByMe = (bool *) calloc(NBuffers, sizeof(bool));
+
+ /*
+ * Convert shmem offsets into addresses as seen by this process.
+ * This is just to speed up the BufferGetBlock() macro.
+ */
+ for (i = 0; i < NBuffers; i++)
+ {
+ BufferBlockPointers[i] = (Block) MAKE_PTR(BufferDescriptors[i].data);
+ }
}
/* -----------------------------------------------------
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.18 2000/10/18 05:50:15 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.19 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
+#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
static HTAB *SharedBufHash;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.95 2000/11/28 23:27:55 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.96 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "executor/execdebug.h"
#include "miscadmin.h"
+#include "storage/buf_internals.h"
+#include "storage/bufmgr.h"
#include "storage/s_lock.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/freelist.c,v 1.21 2000/04/09 04:43:19 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/freelist.c,v 1.22 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
#include "postgres.h"
+
+#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.35 2000/11/20 16:47:32 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.36 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <signal.h>
#include "executor/execdebug.h"
+#include "storage/buf_internals.h"
+#include "storage/bufmgr.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
int NLocBuffer = 64;
BufferDesc *LocalBufferDescriptors = NULL;
+Block *LocalBufferBlockPointers = NULL;
long *LocalRefCount = NULL;
static int nextFreeLocalBuf = 0;
bufHdr->flags &= ~BM_DIRTY;
/*
- * lazy memory allocation. (see MAKE_PTR for why we need to do
- * MAKE_OFFSET.)
+ * lazy memory allocation: allocate space on first use of a buffer.
*/
if (bufHdr->data == (SHMEM_OFFSET) 0)
{
char *data = (char *) malloc(BLCKSZ);
+ if (data == NULL)
+ elog(FATAL, "Out of memory in LocalBufferAlloc");
+ /*
+ * This is a bit of a hack: bufHdr->data needs to be a shmem offset
+ * for consistency with the shared-buffer case, so make it one
+ * even though it's not really a valid shmem offset.
+ */
bufHdr->data = MAKE_OFFSET(data);
+ /*
+ * Set pointer for use by BufferGetBlock() macro.
+ */
+ LocalBufferBlockPointers[-(bufHdr->buf_id + 2)] = (Block) data;
}
*foundPtr = FALSE;
/*
* InitLocalBuffer -
* init the local buffer cache. Since most queries (esp. multi-user ones)
- * don't involve local buffers, we delay allocating memory for actual the
+ * don't involve local buffers, we delay allocating actual memory for the
* buffer until we need it.
*/
void
* these aren't going away. I'm not gonna use palloc.
*/
LocalBufferDescriptors =
- (BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
- MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
+ (BufferDesc *) calloc(NLocBuffer, sizeof(BufferDesc));
+ LocalBufferBlockPointers = (Block *) calloc(NLocBuffer, sizeof(Block));
+ LocalRefCount = (long *) calloc(NLocBuffer, sizeof(long));
nextFreeLocalBuf = 0;
for (i = 0; i < NLocBuffer; i++)
*/
buf->buf_id = -i - 2;
}
-
- LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
- MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
}
/*
buf->tag.rnode.relNode = InvalidOid;
buf->flags &= ~BM_DIRTY;
- buf->buf_id = -i - 2;
}
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
/*-------------------------------------------------------------------------
*
- * bufmgr.c
+ * xlog_bufmgr.c
* buffer manager interface routines
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.5 2000/11/28 23:27:55 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_bufmgr.c,v 1.6 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* freelist.c -- chooses victim for buffer replacement
* buf_table.c -- manages the buffer lookup table
*/
+#include "postgres.h"
+
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
#include <signal.h>
-#include "postgres.h"
#include "executor/execdebug.h"
#include "miscadmin.h"
+#include "storage/buf_internals.h"
+#include "storage/bufmgr.h"
#include "storage/s_lock.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
/*-------------------------------------------------------------------------
*
- * localbuf.c
+ * xlog_localbuf.c
* local buffer manager. Fast buffer manager for temporary tables
* or special cases when the operation is not visible to other backends.
*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_localbuf.c,v 1.1 2000/10/28 16:20:56 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_localbuf.c,v 1.2 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
+#include "postgres.h"
+
#include <sys/types.h>
#include <sys/file.h>
#include <math.h>
#include <signal.h>
-#include "postgres.h"
-
#include "executor/execdebug.h"
+#include "storage/buf_internals.h"
+#include "storage/bufmgr.h"
#include "storage/smgr.h"
#include "utils/relcache.h"
int NLocBuffer = 64;
BufferDesc *LocalBufferDescriptors = NULL;
+Block *LocalBufferBlockPointers = NULL;
long *LocalRefCount = NULL;
static int nextFreeLocalBuf = 0;
bufHdr->cntxDirty = false;
/*
- * lazy memory allocation. (see MAKE_PTR for why we need to do
- * MAKE_OFFSET.)
+ * lazy memory allocation: allocate space on first use of a buffer.
*/
if (bufHdr->data == (SHMEM_OFFSET) 0)
{
char *data = (char *) malloc(BLCKSZ);
+ if (data == NULL)
+ elog(FATAL, "Out of memory in LocalBufferAlloc");
+ /*
+ * This is a bit of a hack: bufHdr->data needs to be a shmem offset
+ * for consistency with the shared-buffer case, so make it one
+ * even though it's not really a valid shmem offset.
+ */
bufHdr->data = MAKE_OFFSET(data);
+ /*
+ * Set pointer for use by BufferGetBlock() macro.
+ */
+ LocalBufferBlockPointers[-(bufHdr->buf_id + 2)] = (Block) data;
}
*foundPtr = FALSE;
/*
* InitLocalBuffer -
* init the local buffer cache. Since most queries (esp. multi-user ones)
- * don't involve local buffers, we delay allocating memory for actual the
+ * don't involve local buffers, we delay allocating actual memory for the
* buffer until we need it.
*/
void
* these aren't going away. I'm not gonna use palloc.
*/
LocalBufferDescriptors =
- (BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
- MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
+ (BufferDesc *) calloc(NLocBuffer, sizeof(BufferDesc));
+ LocalBufferBlockPointers = (Block *) calloc(NLocBuffer, sizeof(Block));
+ LocalRefCount = (long *) calloc(NLocBuffer, sizeof(long));
nextFreeLocalBuf = 0;
for (i = 0; i < NLocBuffer; i++)
*/
buf->buf_id = -i - 2;
}
-
- LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
- MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
}
/*
Assert(bufrel != NULL);
smgrwrite(DEFAULT_SMGR, bufrel, buf->tag.blockNum,
- (char *) MAKE_PTR(buf->data));
+ (char *) MAKE_PTR(buf->data));
smgrmarkdirty(DEFAULT_SMGR, bufrel, buf->tag.blockNum);
LocalBufferFlushCount++;
buf->tag.rnode.relNode = InvalidOid;
buf->flags &= ~BM_DIRTY;
buf->cntxDirty = false;
- buf->buf_id = -i - 2;
}
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.35 2000/11/28 23:27:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.36 2000/11/30 01:39:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "miscadmin.h"
#include "access/xlog.h"
#include "storage/bufmgr.h"
+#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/sinval.h"
#include "storage/spin.h"
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.41 2000/06/08 22:37:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.42 2000/11/30 01:39:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "access/transam.h"
#include "catalog/catalog.h"
#include "miscadmin.h"
+#include "storage/lmgr.h"
#include "utils/inval.h"
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: buf_internals.h,v 1.44 2000/11/28 23:27:57 tgl Exp $
+ * $Id: buf_internals.h,v 1.45 2000/11/30 01:39:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "storage/lmgr.h"
#include "storage/s_lock.h"
+
/* Buf Mgr constants */
/* in bufmgr.c */
-extern int NBuffers;
extern int Data_Descriptors;
extern int Free_List_Descriptor;
extern int Lookup_List_Descriptor;
extern int Num_Descriptors;
+extern int ShowPinTrace;
+
+
/*
* Flags for buffer descriptors
*/
typedef bits16 BufFlags;
-/* long * so alignment will be correct */
-typedef long **BufferBlock;
-
typedef struct buftag
{
RelFileNode rnode;
)
/*
- * We don't need in this data any more but it allows more user
+ * We don't need this data any more but it allows more user
* friendly error messages. Feel free to get rid of it
* (and change a lot of places -:))
*/
char relname[NAMEDATALEN]; /* name of reln */
} BufferBlindId;
-#define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers)
-#define INVALID_DESCRIPTOR (-3)
-
/*
* BufferDesc -- shared buffer cache metadata for a single
* shared buffer descriptor.
void (*CleanupFunc)(Buffer);
} BufferDesc;
+#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
+
/*
* Each backend has its own BufferLocks[] array holding flag bits
* showing what locks it has set on each buffer.
/* bufmgr.c */
extern BufferDesc *BufferDescriptors;
-extern BufferBlock BufferBlocks;
-extern long *PrivateRefCount;
extern bits8 *BufferLocks;
extern BufferTag *BufferTagLastDirtied;
extern BufferBlindId *BufferBlindLastDirtied;
extern SPINLOCK BufMgrLock;
/* localbuf.c */
-extern long *LocalRefCount;
extern BufferDesc *LocalBufferDescriptors;
-extern int NLocBuffer;
extern BufferDesc *LocalBufferAlloc(Relation reln, BlockNumber blockNum,
bool *foundPtr);
extern int WriteLocalBuffer(Buffer buffer, bool release);
extern int FlushLocalBuffer(Buffer buffer, bool sync, bool release);
-extern void InitLocalBuffer(void);
extern void LocalBufferSync(void);
extern void ResetLocalBufferPool(void);
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: bufmgr.h,v 1.44 2000/11/28 23:27:57 tgl Exp $
+ * $Id: bufmgr.h,v 1.45 2000/11/30 01:39:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#define BUFMGR_H
#include "access/xlogdefs.h"
-#include "storage/buf_internals.h"
+#include "storage/buf.h"
+#include "storage/lock.h"
#include "storage/relfilenode.h"
+#include "utils/rel.h"
typedef void *Block;
+/* in globals.c ... this duplicates miscadmin.h */
+extern int NBuffers;
+
+/* in buf_init.c */
+extern Block *BufferBlockPointers;
+extern long *PrivateRefCount;
+
+/* in localbuf.c */
+extern int NLocBuffer;
+extern Block *LocalBufferBlockPointers;
+extern long *LocalRefCount;
+
/* special pageno for bget */
#define P_NEW InvalidBlockNumber /* grow the file to get a new page */
+/*
+ * Buffer context lock modes
+ */
+#define BUFFER_LOCK_UNLOCK 0
+#define BUFFER_LOCK_SHARE 1
+#define BUFFER_LOCK_EXCLUSIVE 2
+
/**********************************************************************
/*
* These routines are beaten on quite heavily, hence the macroization.
- * See buf_internals.h for a related comment.
*/
-#define BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1)
-extern int ShowPinTrace;
-
-/*
- * Buffer context lock modes
- */
-#define BUFFER_LOCK_UNLOCK 0
-#define BUFFER_LOCK_SHARE 1
-#define BUFFER_LOCK_EXCLUSIVE 2
+#define BAD_BUFFER_ID(bid) ((bid) < 1 || (bid) > NBuffers)
+#define INVALID_DESCRIPTOR (-3)
#define UnlockAndReleaseBuffer(buffer) \
( \
( \
AssertMacro(BufferIsValid(buffer)), \
BufferIsLocal(buffer) ? \
- ((Block) MAKE_PTR(LocalBufferDescriptors[-(buffer) - 1].data)) \
+ LocalBufferBlockPointers[-(buffer) - 1] \
: \
- ((Block) MAKE_PTR(BufferDescriptors[(buffer) - 1].data)) \
+ BufferBlockPointers[(buffer) - 1] \
)
extern void BufferSync(void);
#endif
+extern void InitLocalBuffer(void);
+
#endif