remove BufferBlockPointers for speed and space - Mailing list pgsql-patches
From | Qingqing Zhou |
---|---|
Subject | remove BufferBlockPointers for speed and space |
Date | |
Msg-id | ddeo30$87d$1@news.hub.org Whole thread Raw |
Responses |
Re: remove BufferBlockPointers for speed and space
|
List | pgsql-patches |
It is said that the BufferBlockPointers is used to speedup the BufferGetBlock() macro. I compared three ways of getting block pointers. I.e., existing method (arrary method), calculating block pointer by adding base addr and offset*blockid method (mul method) and optimizing mul method by using bit shift (shift method). All of them calculate the block pointer 80000 times (i.e., the BufferBlockPointers array is of size 80000), and each take 3 rounds. The result is: SunOS/gcc 3.2 duration round 1 of array method: 4.179 ms duration round 2 of array method: 4.160 ms duration round 3 of array method: 4.143 ms duration round 1 of mul method: 3.311 ms duration round 2 of mul method: 3.233 ms duration round 3 of mul method: 3.233 ms duration round 1 of shift method: 3.554 ms duration round 2 of shift method: 3.235 ms duration round 3 of shift method: 3.233 ms Linux/gcc 3.2 duration round 1 of array method: 0.422 ms duration round 2 of array method: 0.324 ms duration round 3 of array method: 0.354 ms duration round 1 of mul method: 0.271 ms duration round 2 of mul method: 0.248 ms duration round 3 of mul method: 0.304 ms duration round 1 of shift method: 0.322 ms duration round 2 of shift method: 0.239 ms duration round 3 of shift method: 0.265 ms We can conclude that: (1) mul or shift are definitely better than array method; (2) mul and shift are comparable; So we can remove BufferBlockPointers for speed and space. Regards, Qingqing -------- Updated files: /include/storage/bufmgr.h /storage/buffer/buf_init.c /storage/buffer/bufmgr.c Index: bufmgr.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/storage/bufmgr.h,v retrieving revision 1.94 diff -c -r1.94 bufmgr.h *** bufmgr.h 8 Aug 2005 03:12:16 -0000 1.94 --- bufmgr.h 11 Aug 2005 05:15:04 -0000 *************** *** 33,39 **** extern int bgwriter_all_maxpages; /* in buf_init.c */ ! extern DLLIMPORT Block *BufferBlockPointers; extern DLLIMPORT int32 *PrivateRefCount; /* in localbuf.c */ --- 33,39 ---- extern int bgwriter_all_maxpages; /* in buf_init.c */ ! extern DLLIMPORT char *BufferBlocks; extern DLLIMPORT int32 *PrivateRefCount; /* in localbuf.c */ *************** *** 107,113 **** BufferIsLocal(buffer) ? \ LocalBufferBlockPointers[-(buffer) - 1] \ : \ ! BufferBlockPointers[(buffer) - 1] \ ) /* --- 107,113 ---- BufferIsLocal(buffer) ? \ LocalBufferBlockPointers[-(buffer) - 1] \ : \ ! BufferBlocks + ((buffer) - 1)*BLCKSZ \ ) /* Index: buf_init.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v retrieving revision 1.74 diff -c -r1.74 buf_init.c *** buf_init.c 8 Aug 2005 03:11:44 -0000 1.74 --- buf_init.c 11 Aug 2005 05:17:38 -0000 *************** *** 19,28 **** BufferDesc *BufferDescriptors; - Block *BufferBlockPointers; int32 *PrivateRefCount; ! ! static char *BufferBlocks; /* statistics counters */ long int ReadBufferCount; --- 19,26 ---- BufferDesc *BufferDescriptors; int32 *PrivateRefCount; ! char *BufferBlocks; /* statistics counters */ long int ReadBufferCount; *************** *** 154,183 **** void InitBufferPoolAccess(void) { - char *block; - int i; - /* * Allocate and zero local arrays of per-buffer info. */ - BufferBlockPointers = (Block *) calloc(NBuffers, - sizeof(*BufferBlockPointers)); PrivateRefCount = (int32 *) calloc(NBuffers, 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; - } } /* --- 152,162 ---- Index: bufmgr.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v retrieving revision 1.192 diff -c -r1.192 bufmgr.c *** bufmgr.c 8 Aug 2005 19:44:22 -0000 1.192 --- bufmgr.c 11 Aug 2005 05:18:35 -0000 *************** *** 54,60 **** /* Note: these two macros only work on shared buffers, not local ones! */ ! #define BufHdrGetBlock(bufHdr) BufferBlockPointers[(bufHdr)->buf_id] #define BufferGetLSN(bufHdr) (*((XLogRecPtr*) BufHdrGetBlock(bufHdr))) /* Note: this macro only works on local buffers, not shared ones! */ --- 54,60 ---- /* Note: these two macros only work on shared buffers, not local ones! */ ! #define BufHdrGetBlock(bufHdr) (BufferBlocks + ((bufHdr)->buf_id)*BLCKSZ) #define BufferGetLSN(bufHdr) (*((XLogRecPtr*) BufHdrGetBlock(bufHdr))) /* Note: this macro only works on local buffers, not shared ones! */
pgsql-patches by date: