mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Remove BufferBlockPointers array in favor of a base + (bufnum) * BLCKSZ
computation. On modern machines this is as fast if not faster, and we don't have to clog the CPU's L2 cache with a tens-of-KB pointer array. If we ever decide to adopt a more dynamic allocation method for shared buffers, we'll probably have to revert this patch, but in the meantime we might as well save a few bytes and nanoseconds. Per Qingqing Zhou.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.74 2005/08/08 03:11:44 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.75 2005/08/12 05:05:50 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -19,11 +19,9 @@
|
|||||||
|
|
||||||
|
|
||||||
BufferDesc *BufferDescriptors;
|
BufferDesc *BufferDescriptors;
|
||||||
Block *BufferBlockPointers;
|
char *BufferBlocks;
|
||||||
int32 *PrivateRefCount;
|
int32 *PrivateRefCount;
|
||||||
|
|
||||||
static char *BufferBlocks;
|
|
||||||
|
|
||||||
/* statistics counters */
|
/* statistics counters */
|
||||||
long int ReadBufferCount;
|
long int ReadBufferCount;
|
||||||
long int ReadLocalBufferCount;
|
long int ReadLocalBufferCount;
|
||||||
@ -154,30 +152,11 @@ InitBufferPool(void)
|
|||||||
void
|
void
|
||||||
InitBufferPoolAccess(void)
|
InitBufferPoolAccess(void)
|
||||||
{
|
{
|
||||||
char *block;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate and zero local arrays of per-buffer info.
|
* Allocate and zero local arrays of per-buffer info.
|
||||||
*/
|
*/
|
||||||
BufferBlockPointers = (Block *) calloc(NBuffers,
|
|
||||||
sizeof(*BufferBlockPointers));
|
|
||||||
PrivateRefCount = (int32 *) calloc(NBuffers,
|
PrivateRefCount = (int32 *) calloc(NBuffers,
|
||||||
sizeof(*PrivateRefCount));
|
sizeof(*PrivateRefCount));
|
||||||
|
|
||||||
/*
|
|
||||||
* Construct addresses for the individual buffer data blocks. We do
|
|
||||||
* this just to speed up the BufferGetBlock() macro. (Since the
|
|
||||||
* addresses should be the same in every backend, we could inherit
|
|
||||||
* this data from the postmaster --- but in the EXEC_BACKEND case
|
|
||||||
* that doesn't work.)
|
|
||||||
*/
|
|
||||||
block = BufferBlocks;
|
|
||||||
for (i = 0; i < NBuffers; i++)
|
|
||||||
{
|
|
||||||
BufferBlockPointers[i] = (Block) block;
|
|
||||||
block += BLCKSZ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.192 2005/08/08 19:44:22 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.193 2005/08/12 05:05:50 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Note: these two macros only work on shared buffers, not local ones! */
|
/* Note: these two macros only work on shared buffers, not local ones! */
|
||||||
#define BufHdrGetBlock(bufHdr) BufferBlockPointers[(bufHdr)->buf_id]
|
#define BufHdrGetBlock(bufHdr) ((Block) (BufferBlocks + ((Size) (bufHdr)->buf_id) * BLCKSZ))
|
||||||
#define BufferGetLSN(bufHdr) (*((XLogRecPtr*) BufHdrGetBlock(bufHdr)))
|
#define BufferGetLSN(bufHdr) (*((XLogRecPtr*) BufHdrGetBlock(bufHdr)))
|
||||||
|
|
||||||
/* Note: this macro only works on local buffers, not shared ones! */
|
/* Note: this macro only works on local buffers, not shared ones! */
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.94 2005/08/08 03:12:16 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.95 2005/08/12 05:05:51 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -33,7 +33,7 @@ extern int bgwriter_lru_maxpages;
|
|||||||
extern int bgwriter_all_maxpages;
|
extern int bgwriter_all_maxpages;
|
||||||
|
|
||||||
/* in buf_init.c */
|
/* in buf_init.c */
|
||||||
extern DLLIMPORT Block *BufferBlockPointers;
|
extern DLLIMPORT char *BufferBlocks;
|
||||||
extern DLLIMPORT int32 *PrivateRefCount;
|
extern DLLIMPORT int32 *PrivateRefCount;
|
||||||
|
|
||||||
/* in localbuf.c */
|
/* in localbuf.c */
|
||||||
@ -107,7 +107,7 @@ extern DLLIMPORT int32 *LocalRefCount;
|
|||||||
BufferIsLocal(buffer) ? \
|
BufferIsLocal(buffer) ? \
|
||||||
LocalBufferBlockPointers[-(buffer) - 1] \
|
LocalBufferBlockPointers[-(buffer) - 1] \
|
||||||
: \
|
: \
|
||||||
BufferBlockPointers[(buffer) - 1] \
|
(Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user