Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3ae7e4a

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 wedon'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 sharedbuffers, we'll probably have to revert this patch, but in the meantimewe might as well save a few bytes and nanoseconds. Per Qingqing Zhou.
1 parentb609695 commit3ae7e4a

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-
staticchar*BufferBlocks;
26-
2725
/* statistics counters */
2826
longintReadBufferCount;
2927
longintReadLocalBufferCount;
@@ -154,30 +152,11 @@ InitBufferPool(void)
154152
void
155153
InitBufferPoolAccess(void)
156154
{
157-
char*block;
158-
inti;
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-
#defineBufHdrGetBlock(bufHdr)BufferBlockPointers[(bufHdr)->buf_id]
57+
#defineBufHdrGetBlock(bufHdr)((Block) (BufferBlocks + ((Size) (bufHdr)->buf_id) * BLCKSZ))
5858
#defineBufferGetLSN(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 intbgwriter_lru_maxpages;
3333
externintbgwriter_all_maxpages;
3434

3535
/* in buf_init.c */
36-
externDLLIMPORTBlock*BufferBlockPointers;
36+
externDLLIMPORTchar*BufferBlocks;
3737
externDLLIMPORTint32*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)

[8]ページ先頭

©2009-2025 Movatter.jp