Skip to content

Commit 3ae7e4a

Browse files
committed
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.
1 parent b609695 commit 3ae7e4a

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

src/backend/storage/buffer/buf_init.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.74 2005/08/08 03:11:44 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.75 2005/08/12 05:05:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -19,11 +19,9 @@
1919

2020

2121
BufferDesc *BufferDescriptors;
22-
Block *BufferBlockPointers;
22+
char *BufferBlocks;
2323
int32 *PrivateRefCount;
2424

25-
static char *BufferBlocks;
26-
2725
/* statistics counters */
2826
long int ReadBufferCount;
2927
long int ReadLocalBufferCount;
@@ -154,30 +152,11 @@ InitBufferPool(void)
154152
void
155153
InitBufferPoolAccess(void)
156154
{
157-
char *block;
158-
int i;
159-
160155
/*
161156
* Allocate and zero local arrays of per-buffer info.
162157
*/
163-
BufferBlockPointers = (Block *) calloc(NBuffers,
164-
sizeof(*BufferBlockPointers));
165158
PrivateRefCount = (int32 *) calloc(NBuffers,
166159
sizeof(*PrivateRefCount));
167-
168-
/*
169-
* Construct addresses for the individual buffer data blocks. We do
170-
* this just to speed up the BufferGetBlock() macro. (Since the
171-
* addresses should be the same in every backend, we could inherit
172-
* this data from the postmaster --- but in the EXEC_BACKEND case
173-
* that doesn't work.)
174-
*/
175-
block = BufferBlocks;
176-
for (i = 0; i < NBuffers; i++)
177-
{
178-
BufferBlockPointers[i] = (Block) block;
179-
block += BLCKSZ;
180-
}
181160
}
182161

183162
/*

src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.192 2005/08/08 19:44:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.193 2005/08/12 05:05:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -54,7 +54,7 @@
5454

5555

5656
/* Note: these two macros only work on shared buffers, not local ones! */
57-
#define BufHdrGetBlock(bufHdr) BufferBlockPointers[(bufHdr)->buf_id]
57+
#define BufHdrGetBlock(bufHdr) ((Block) (BufferBlocks + ((Size) (bufHdr)->buf_id) * BLCKSZ))
5858
#define BufferGetLSN(bufHdr) (*((XLogRecPtr*) BufHdrGetBlock(bufHdr)))
5959

6060
/* Note: this macro only works on local buffers, not shared ones! */

src/include/storage/bufmgr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.94 2005/08/08 03:12:16 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.95 2005/08/12 05:05:51 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -33,7 +33,7 @@ extern int bgwriter_lru_maxpages;
3333
extern int bgwriter_all_maxpages;
3434

3535
/* in buf_init.c */
36-
extern DLLIMPORT Block *BufferBlockPointers;
36+
extern DLLIMPORT char *BufferBlocks;
3737
extern DLLIMPORT int32 *PrivateRefCount;
3838

3939
/* in localbuf.c */
@@ -107,7 +107,7 @@ extern DLLIMPORT int32 *LocalRefCount;
107107
BufferIsLocal(buffer) ? \
108108
LocalBufferBlockPointers[-(buffer) - 1] \
109109
: \
110-
BufferBlockPointers[(buffer) - 1] \
110+
(Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \
111111
)
112112

113113
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy