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

Commit6b86d62

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
2nd try for the ARC strategy.
I added a couple more Assertions while tracking down the exactcause of the former bug.All 93 regression tests pass now.Jan
1 parent923e994 commit6b86d62

File tree

9 files changed

+958
-216
lines changed

9 files changed

+958
-216
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.267 2003/11/1305:34:57 wieck Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.268 2003/11/1314:57:15 wieck Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -33,6 +33,7 @@
3333
#include"commands/vacuum.h"
3434
#include"executor/executor.h"
3535
#include"miscadmin.h"
36+
#include"storage/buf_internals.h"
3637
#include"storage/freespace.h"
3738
#include"storage/sinval.h"
3839
#include"storage/smgr.h"
@@ -310,8 +311,16 @@ vacuum(VacuumStmt *vacstmt)
310311
else
311312
old_context=MemoryContextSwitchTo(anl_context);
312313

314+
/*
315+
* Tell the buffer replacement strategy that vacuum is
316+
* causing the IO
317+
*/
318+
StrategyHintVacuum(true);
319+
313320
analyze_rel(relid,vacstmt);
314321

322+
StrategyHintVacuum(false);
323+
315324
if (vacstmt->vacuum)
316325
CommitTransactionCommand();
317326
else
@@ -749,6 +758,12 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
749758
SetQuerySnapshot();/* might be needed for functions in
750759
* indexes */
751760

761+
/*
762+
* Tell the cache replacement strategy that vacuum is causing
763+
* all following IO
764+
*/
765+
StrategyHintVacuum(true);
766+
752767
/*
753768
* Check for user-requested abort.Note we want this to be inside a
754769
* transaction, so xact.c doesn't issue useless WARNING.
@@ -763,6 +778,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
763778
ObjectIdGetDatum(relid),
764779
0,0,0))
765780
{
781+
StrategyHintVacuum(false);
766782
CommitTransactionCommand();
767783
return true;/* okay 'cause no data there */
768784
}
@@ -796,6 +812,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
796812
(errmsg("skipping \"%s\" --- only table or database owner can vacuum it",
797813
RelationGetRelationName(onerel))));
798814
relation_close(onerel,lmode);
815+
StrategyHintVacuum(false);
799816
CommitTransactionCommand();
800817
return false;
801818
}
@@ -810,6 +827,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
810827
(errmsg("skipping \"%s\" --- cannot vacuum indexes, views, or special system tables",
811828
RelationGetRelationName(onerel))));
812829
relation_close(onerel,lmode);
830+
StrategyHintVacuum(false);
813831
CommitTransactionCommand();
814832
return false;
815833
}
@@ -824,6 +842,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
824842
if (isOtherTempNamespace(RelationGetNamespace(onerel)))
825843
{
826844
relation_close(onerel,lmode);
845+
StrategyHintVacuum(false);
827846
CommitTransactionCommand();
828847
return true;/* assume no long-lived data in temp
829848
* tables */
@@ -863,6 +882,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
863882
/*
864883
* Complete the transaction and free all temporary memory used.
865884
*/
885+
StrategyHintVacuum(false);
866886
CommitTransactionCommand();
867887

868888
/*

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.56 2003/11/1305:34:58 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.57 2003/11/1314:57:15 wieck Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -48,9 +48,6 @@ long *CurTraceBuf;
4848
intShowPinTrace=0;
4949

5050
intData_Descriptors;
51-
intFree_List_Descriptor;
52-
intLookup_List_Descriptor;
53-
intNum_Descriptors;
5451

5552
BufferDesc*BufferDescriptors;
5653
Block*BufferBlockPointers;
@@ -133,9 +130,6 @@ InitBufferPool(void)
133130
inti;
134131

135132
Data_Descriptors=NBuffers;
136-
Free_List_Descriptor=Data_Descriptors;
137-
Lookup_List_Descriptor=Data_Descriptors+1;
138-
Num_Descriptors=Data_Descriptors+1;
139133

140134
/*
141135
* It's probably not really necessary to grab the lock --- if there's
@@ -156,7 +150,7 @@ InitBufferPool(void)
156150

157151
BufferDescriptors= (BufferDesc*)
158152
ShmemInitStruct("Buffer Descriptors",
159-
Num_Descriptors*sizeof(BufferDesc),&foundDescs);
153+
Data_Descriptors*sizeof(BufferDesc),&foundDescs);
160154

161155
BufferBlocks= (char*)
162156
ShmemInitStruct("Buffer Blocks",
@@ -176,16 +170,14 @@ InitBufferPool(void)
176170
block=BufferBlocks;
177171

178172
/*
179-
* link the buffers into a circular, doubly-linked list to
180-
* initialize free list, and initialize the buffer headers. Still
181-
* don't know anything about replacement strategy in this file.
173+
* link the buffers into a single linked list. This will become the
174+
* LiFo list of unused buffers returned by StragegyGetBuffer().
182175
*/
183176
for (i=0;i<Data_Descriptors;block+=BLCKSZ,buf++,i++)
184177
{
185178
Assert(ShmemIsValid((unsigned long)block));
186179

187-
buf->freeNext=i+1;
188-
buf->freePrev=i-1;
180+
buf->bufNext=i+1;
189181

190182
CLEAR_BUFFERTAG(&(buf->tag));
191183
buf->buf_id=i;
@@ -199,14 +191,12 @@ InitBufferPool(void)
199191
buf->wait_backend_id=0;
200192
}
201193

202-
/* close the circular queue */
203-
BufferDescriptors[0].freePrev=Data_Descriptors-1;
204-
BufferDescriptors[Data_Descriptors-1].freeNext=0;
194+
/* Correct last entry */
195+
BufferDescriptors[Data_Descriptors-1].bufNext=-1;
205196
}
206197

207198
/* Init other shared buffer-management stuff */
208-
InitBufTable();
209-
InitFreeList(!foundDescs);
199+
StrategyInitialize(!foundDescs);
210200

211201
LWLockRelease(BufMgrLock);
212202
}

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

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.31 2003/11/1305:34:58 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.32 2003/11/1314:57:15 wieck Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -38,7 +38,7 @@ static HTAB *SharedBufHash;
3838
* Initialize shmem hash table for mapping buffers
3939
*/
4040
void
41-
InitBufTable(void)
41+
InitBufTable(intsize)
4242
{
4343
HASHCTLinfo;
4444

@@ -50,87 +50,71 @@ InitBufTable(void)
5050
info.hash=tag_hash;
5151

5252
SharedBufHash=ShmemInitHash("Shared Buffer Lookup Table",
53-
NBuffers,NBuffers,
53+
size,size,
5454
&info,
5555
HASH_ELEM |HASH_FUNCTION);
5656

5757
if (!SharedBufHash)
5858
elog(FATAL,"could not initialize shared buffer hash table");
5959
}
6060

61-
BufferDesc*
61+
/*
62+
* BufTableLookup
63+
*/
64+
int
6265
BufTableLookup(BufferTag*tagPtr)
6366
{
6467
BufferLookupEnt*result;
6568

6669
if (tagPtr->blockNum==P_NEW)
67-
returnNULL;
70+
return-1;
6871

6972
result= (BufferLookupEnt*)
7073
hash_search(SharedBufHash, (void*)tagPtr,HASH_FIND,NULL);
7174
if (!result)
72-
returnNULL;
75+
return-1;
7376

74-
return&(BufferDescriptors[result->id]);
77+
returnresult->id;
7578
}
7679

7780
/*
7881
* BufTableDelete
7982
*/
8083
bool
81-
BufTableDelete(BufferDesc*buf)
84+
BufTableInsert(BufferTag*tagPtr,Bufferbuf_id)
8285
{
8386
BufferLookupEnt*result;
84-
85-
/*
86-
* buffer not initialized or has been removed from table already.
87-
* BM_DELETED keeps us from removing buffer twice.
88-
*/
89-
if (buf->flags&BM_DELETED)
90-
return TRUE;
91-
92-
buf->flags |=BM_DELETED;
87+
boolfound;
9388

9489
result= (BufferLookupEnt*)
95-
hash_search(SharedBufHash, (void*)&(buf->tag),HASH_REMOVE,NULL);
90+
hash_search(SharedBufHash, (void*)tagPtr,HASH_ENTER,&found);
9691

97-
if (!result)/* shouldn't happen */
98-
elog(ERROR,"shared buffer hash table corrupted");
92+
if (!result)
93+
ereport(ERROR,
94+
(errcode(ERRCODE_OUT_OF_MEMORY),
95+
errmsg("out of shared memory")));
9996

100-
/*
101-
* Clear the buffer's tag. This doesn't matter for the hash table,
102-
* since the buffer is already removed from it, but it ensures that
103-
* sequential searches through the buffer table won't think the buffer
104-
* is still valid for its old page.
105-
*/
106-
buf->tag.rnode.relNode=InvalidOid;
107-
buf->tag.rnode.tblNode=InvalidOid;
97+
if (found)/* found something else in the table? */
98+
elog(ERROR,"shared buffer hash table corrupted");
10899

100+
result->id=buf_id;
109101
return TRUE;
110102
}
111103

104+
/*
105+
* BufTableDelete
106+
*/
112107
bool
113-
BufTableInsert(BufferDesc*buf)
108+
BufTableDelete(BufferTag*tagPtr)
114109
{
115110
BufferLookupEnt*result;
116-
boolfound;
117-
118-
/* cannot insert it twice */
119-
Assert(buf->flags&BM_DELETED);
120-
buf->flags &= ~(BM_DELETED);
121111

122112
result= (BufferLookupEnt*)
123-
hash_search(SharedBufHash, (void*)&(buf->tag),HASH_ENTER,&found);
124-
125-
if (!result)
126-
ereport(ERROR,
127-
(errcode(ERRCODE_OUT_OF_MEMORY),
128-
errmsg("out of shared memory")));
113+
hash_search(SharedBufHash, (void*)tagPtr,HASH_REMOVE,NULL);
129114

130-
if (found)/*found something else in the table? */
115+
if (!result)/*shouldn't happen */
131116
elog(ERROR,"shared buffer hash table corrupted");
132117

133-
result->id=buf->buf_id;
134118
return TRUE;
135119
}
136120

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp