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

Commitcc4f58f

Browse files
committed
Ensure that all details of the ARC algorithm are hidden within freelist.c.
This refactoring does not change any algorithms or data structures, justremove visibility of the ARC datastructures from other source files.
1 parentad893a3 commitcc4f58f

File tree

4 files changed

+129
-93
lines changed

4 files changed

+129
-93
lines changed

‎src/backend/storage/buffer/buf_init.c

Lines changed: 12 additions & 15 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.70 2004/12/31 22:00:49 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.71 2005/02/03 23:29:11 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -73,7 +73,6 @@ long intLocalBufferFlushCount;
7373
*aborts, it should only unpin the buffers exactly the number of times it
7474
*has pinned them, so that it will not blow away buffers of another
7575
*backend.
76-
*
7776
*/
7877

7978

@@ -120,14 +119,17 @@ InitBufferPool(void)
120119
block=BufferBlocks;
121120

122121
/*
123-
* link the buffers into a single linked list. This will become
124-
* the LIFO list of unused buffers returned by
125-
* StrategyGetBuffer().
122+
* Initialize all the buffer headers.
126123
*/
127124
for (i=0;i<NBuffers;block+=BLCKSZ,buf++,i++)
128125
{
129126
Assert(ShmemIsValid((unsigned long)block));
130127

128+
/*
129+
* The bufNext fields link together all totally-unused buffers.
130+
* Subsequent management of this list is done by
131+
* StrategyGetBuffer().
132+
*/
131133
buf->bufNext=i+1;
132134

133135
CLEAR_BUFFERTAG(buf->tag);
@@ -142,7 +144,7 @@ InitBufferPool(void)
142144
buf->wait_backend_id=0;
143145
}
144146

145-
/* Correct last entry */
147+
/* Correct last entryof linked list*/
146148
BufferDescriptors[NBuffers-1].bufNext=-1;
147149

148150
LWLockRelease(BufMgrLock);
@@ -178,7 +180,8 @@ InitBufferPoolAccess(void)
178180

179181
/*
180182
* Convert shmem offsets into addresses as seen by this process. This
181-
* is just to speed up the BufferGetBlock() macro.
183+
* is just to speed up the BufferGetBlock() macro. It is OK to do this
184+
* without any lock since the data pointers never change.
182185
*/
183186
for (i=0;i<NBuffers;i++)
184187
BufferBlockPointers[i]= (Block)MAKE_PTR(BufferDescriptors[i].data);
@@ -201,14 +204,8 @@ BufferShmemSize(void)
201204
/* size of data pages */
202205
size+=NBuffers*MAXALIGN(BLCKSZ);
203206

204-
/* size of buffer hash table */
205-
size+=hash_estimate_size(NBuffers*2,sizeof(BufferLookupEnt));
206-
207-
/* size of the shared replacement strategy control block */
208-
size+=MAXALIGN(sizeof(BufferStrategyControl));
209-
210-
/* size of the ARC directory blocks */
211-
size+=MAXALIGN(NBuffers*2*sizeof(BufferStrategyCDB));
207+
/* size of stuff controlled by freelist.c */
208+
size+=StrategyShmemSize();
212209

213210
returnsize;
214211
}

‎src/backend/storage/buffer/buf_table.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*-------------------------------------------------------------------------
22
*
33
* buf_table.c
4-
* routines forfinding buffers in thebufferpool.
4+
* routines formapping BufferTags tobufferindexes.
55
*
6-
* NOTE:these days, what this table actually provides is a mapping from
7-
*BufferTags to CDB indexes, not directlytobuffers.The function names
8-
*are thus slight misnomers.
6+
* NOTE:this module is called only by freelist.c, and the "buffer IDs"
7+
*it deals with are whatever freelist.c needs themtobe; they may not be
8+
*directly equivalent to Buffer numbers.
99
*
1010
* Note: all routines in this file assume that the BufMgrLock is held
1111
* by the caller, so no synchronization is needed.
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.38 2004/12/31 22:00:49 pgsql Exp $
19+
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.39 2005/02/03 23:29:11 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -26,12 +26,29 @@
2626
#include"storage/bufmgr.h"
2727

2828

29+
/* entry for buffer lookup hashtable */
30+
typedefstruct
31+
{
32+
BufferTagkey;/* Tag of a disk page */
33+
intid;/* Associated buffer ID */
34+
}BufferLookupEnt;
35+
2936
staticHTAB*SharedBufHash;
3037

3138

39+
/*
40+
* Estimate space needed for mapping hashtable
41+
*size is the desired hash table size (possibly more than NBuffers)
42+
*/
43+
int
44+
BufTableShmemSize(intsize)
45+
{
46+
returnhash_estimate_size(size,sizeof(BufferLookupEnt));
47+
}
48+
3249
/*
3350
* Initialize shmem hash table for mapping buffers
34-
*size is the desired hash table size (2*NBuffers for ARC algorithm)
51+
*size is the desired hash table size (possibly more than NBuffers)
3552
*/
3653
void
3754
InitBufTable(intsize)
@@ -56,7 +73,7 @@ InitBufTable(int size)
5673

5774
/*
5875
* BufTableLookup
59-
*Lookup the given BufferTag; returnCDB index, or -1 if not found
76+
*Lookup the given BufferTag; returnbuffer ID, or -1 if not found
6077
*/
6178
int
6279
BufTableLookup(BufferTag*tagPtr)
@@ -76,10 +93,10 @@ BufTableLookup(BufferTag *tagPtr)
7693

7794
/*
7895
* BufTableInsert
79-
*Insert a hashtable entry for given tag andCDB index
96+
*Insert a hashtable entry for given tag andbuffer ID
8097
*/
8198
void
82-
BufTableInsert(BufferTag*tagPtr,intcdb_id)
99+
BufTableInsert(BufferTag*tagPtr,intbuf_id)
83100
{
84101
BufferLookupEnt*result;
85102
boolfound;
@@ -92,15 +109,15 @@ BufTableInsert(BufferTag *tagPtr, int cdb_id)
92109
(errcode(ERRCODE_OUT_OF_MEMORY),
93110
errmsg("out of shared memory")));
94111

95-
if (found)/* found somethingelse in the table? */
112+
if (found)/* found somethingalready in the table? */
96113
elog(ERROR,"shared buffer hash table corrupted");
97114

98-
result->id=cdb_id;
115+
result->id=buf_id;
99116
}
100117

101118
/*
102119
* BufTableDelete
103-
*Delete the hashtable entry for given tag
120+
*Delete the hashtable entry for given tag (which must exist)
104121
*/
105122
void
106123
BufTableDelete(BufferTag*tagPtr)

‎src/backend/storage/buffer/freelist.c

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* freelist.c
44
* routines for manipulating the buffer pool's replacement strategy.
55
*
6+
* The name "freelist.c" is now a bit of a misnomer, since this module
7+
* controls not only the list of free buffers per se, but the entire
8+
* mechanism for looking up existing shared buffers and the strategy
9+
* for choosing replacement victims when needed.
10+
*
611
* Note: all routines in this file assume that the BufMgrLock is held
712
* by the caller, so no synchronization is needed.
813
*
@@ -12,7 +17,7 @@
1217
*
1318
*
1419
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.49 2004/12/31 22:00:49 pgsql Exp $
20+
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.50 2005/02/03 23:29:11 tgl Exp $
1621
*
1722
*-------------------------------------------------------------------------
1823
*/
@@ -25,6 +30,51 @@
2530
#include"storage/bufmgr.h"
2631

2732

33+
/*
34+
* Definitions for the buffer replacement strategy
35+
*/
36+
#defineSTRAT_LIST_UNUSED(-1)
37+
#defineSTRAT_LIST_B10
38+
#defineSTRAT_LIST_T11
39+
#defineSTRAT_LIST_T22
40+
#defineSTRAT_LIST_B23
41+
#defineSTRAT_NUM_LISTS4
42+
43+
/*
44+
* The Cache Directory Block (CDB) of the Adaptive Replacement Cache (ARC)
45+
*/
46+
typedefstruct
47+
{
48+
intprev;/* list links */
49+
intnext;
50+
shortlist;/* ID of list it is currently in */
51+
boolt1_vacuum;/* t => present only because of VACUUM */
52+
TransactionIdt1_xid;/* the xid this entry went onto T1 */
53+
BufferTagbuf_tag;/* page identifier */
54+
intbuf_id;/* currently assigned data buffer, or -1 */
55+
}BufferStrategyCDB;
56+
57+
/*
58+
* The shared ARC control information.
59+
*/
60+
typedefstruct
61+
{
62+
inttarget_T1_size;/* What T1 size are we aiming for */
63+
intlistUnusedCDB;/* All unused StrategyCDB */
64+
intlistHead[STRAT_NUM_LISTS];/* ARC lists B1, T1, T2
65+
* and B2 */
66+
intlistTail[STRAT_NUM_LISTS];
67+
intlistSize[STRAT_NUM_LISTS];
68+
BufferlistFreeBuffers;/* List of unused buffers */
69+
70+
longnum_lookup;/* Some hit statistics */
71+
longnum_hit[STRAT_NUM_LISTS];
72+
time_tstat_report;
73+
74+
/* Array of CDB's starts here */
75+
BufferStrategyCDBcdb[1];/* VARIABLE SIZE ARRAY */
76+
}BufferStrategyControl;
77+
2878
/* GUC variable: time in seconds between statistics reports */
2979
intDebugSharedBuffers=0;
3080

@@ -812,6 +862,28 @@ StrategyDirtyBufferList(BufferDesc **buffers, BufferTag *buftags,
812862
}
813863

814864

865+
/*
866+
* StrategyShmemSize
867+
*
868+
* estimate the size of shared memory used by the freelist-related structures.
869+
*/
870+
int
871+
StrategyShmemSize(void)
872+
{
873+
intsize=0;
874+
875+
/* size of CDB lookup hash table */
876+
size+=BufTableShmemSize(NBuffers*2);
877+
878+
/* size of the shared replacement strategy control block */
879+
size+=MAXALIGN(sizeof(BufferStrategyControl));
880+
881+
/* size of the ARC directory blocks */
882+
size+=MAXALIGN(NBuffers*2*sizeof(BufferStrategyCDB));
883+
884+
returnsize;
885+
}
886+
815887
/*
816888
* StrategyInitialize -- initialize the buffer cache replacement
817889
*strategy.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp