@ -1,6 +1,6 @@
/*-------------------------------------------------------------------------
*
* 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 .
*
@ -16,18 +16,20 @@
*
*
* 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"
@ -35,6 +37,7 @@ extern long int LocalBufferFlushCount;
int NLocBuffer = 64 ;
BufferDesc * LocalBufferDescriptors = NULL ;
Block * LocalBufferBlockPointers = NULL ;
long * LocalRefCount = NULL ;
static int nextFreeLocalBuf = 0 ;
@ -131,14 +134,24 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
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 ;
@ -175,7 +188,7 @@ WriteLocalBuffer(Buffer buffer, bool release)
/*
* 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
@ -187,8 +200,9 @@ InitLocalBuffer(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 + + )
@ -203,9 +217,6 @@ InitLocalBuffer(void)
*/
buf - > buf_id = - i - 2 ;
}
LocalRefCount = ( long * ) malloc ( sizeof ( long ) * NLocBuffer ) ;
MemSet ( LocalRefCount , 0 , sizeof ( long ) * NLocBuffer ) ;
}
/*
@ -238,7 +249,7 @@ LocalBufferSync(void)
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 + + ;
@ -266,7 +277,6 @@ ResetLocalBufferPool(void)
buf - > tag . rnode . relNode = InvalidOid ;
buf - > flags & = ~ BM_DIRTY ;
buf - > cntxDirty = false ;
buf - > buf_id = - i - 2 ;
}
MemSet ( LocalRefCount , 0 , sizeof ( long ) * NLocBuffer ) ;