Skip to content

Commit dfdd59e

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Adjusted calculation of shared memory requirements to new
ARC buffer replacement strategy. Jan
1 parent cfd7fb7 commit dfdd59e

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

src/backend/storage/buffer/buf_init.c

+9-3
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.60 2003/12/20 17:31:21 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.61 2004/01/15 16:14:26 wieck Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -231,13 +231,19 @@ BufferShmemSize(void)
231231
size += hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt));
232232

233233
/* size of buffer descriptors */
234-
size += MAXALIGN((NBuffers + 1) * sizeof(BufferDesc));
234+
size += MAXALIGN(NBuffers * sizeof(BufferDesc));
235+
236+
/* size of the shared replacement strategy control block */
237+
size += MAXALIGN(sizeof(BufferStrategyControl));
238+
239+
/* size of the ARC directory blocks */
240+
size += MAXALIGN(NBuffers * 2 * sizeof(BufferStrategyCDB));
235241

236242
/* size of data pages */
237243
size += NBuffers * MAXALIGN(BLCKSZ);
238244

239245
/* size of buffer hash table */
240-
size += hash_estimate_size(NBuffers, sizeof(BufferLookupEnt));
246+
size += hash_estimate_size(NBuffers * 2, sizeof(BufferLookupEnt));
241247

242248
return size;
243249
}

src/backend/storage/buffer/freelist.c

+1-42
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.38 2003/11/29 19:51:56 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.39 2004/01/15 16:14:26 wieck Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -32,54 +32,13 @@
3232
#include "storage/proc.h"
3333
#include "access/xact.h"
3434

35-
#define STRAT_LIST_UNUSED -1
36-
#define STRAT_LIST_B1 0
37-
#define STRAT_LIST_T1 1
38-
#define STRAT_LIST_T2 2
39-
#define STRAT_LIST_B2 3
40-
#define STRAT_NUM_LISTS 4
41-
4235
#ifndef MAX
4336
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
4437
#endif
4538
#ifndef MIN
4639
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
4740
#endif
4841

49-
/*
50-
* The Cache Directory Block (CDB) of the Adaptive Replacement Cache (ARC)
51-
*/
52-
typedef struct bufstratcdb
53-
{
54-
int prev; /* links in the queue */
55-
int next;
56-
int list; /* current list */
57-
BufferTag buf_tag; /* buffer key */
58-
Buffer buf_id; /* currently assigned data buffer */
59-
TransactionId t1_xid; /* the xid this entry went onto T1 */
60-
} BufferStrategyCDB;
61-
62-
/*
63-
* The shared ARC control information.
64-
*/
65-
typedef struct bufstratcontrol
66-
{
67-
68-
int target_T1_size; /* What T1 size are we aiming for */
69-
int listUnusedCDB; /* All unused StrategyCDB */
70-
int listHead[STRAT_NUM_LISTS]; /* ARC lists B1, T1, T2 and B2 */
71-
int listTail[STRAT_NUM_LISTS];
72-
int listSize[STRAT_NUM_LISTS];
73-
Buffer listFreeBuffers; /* List of unused buffers */
74-
75-
long num_lookup; /* Some hit statistics */
76-
long num_hit[STRAT_NUM_LISTS];
77-
time_t stat_report;
78-
79-
BufferStrategyCDB cdb[1]; /* The cache directory */
80-
} BufferStrategyControl;
81-
82-
8342
static BufferStrategyControl *StrategyControl = NULL;
8443
static BufferStrategyCDB *StrategyCDB = NULL;
8544

src/include/storage/buf_internals.h

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/*-------------------------------------------------------------------------
22
*
33
* buf_internals.h
4-
* Internal definitions for buffer manager.
4+
* Internal definitions for buffer manager and the buffer replacement
5+
* strategy.
56
*
67
*
78
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
89
* Portions Copyright (c) 1994, Regents of the University of California
910
*
10-
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.66 2003/12/14 00:34:47 neilc Exp $
11+
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.67 2004/01/15 16:14:26 wieck Exp $
1112
*
1213
*-------------------------------------------------------------------------
1314
*/
@@ -135,6 +136,49 @@ typedef struct
135136
Buffer id;
136137
} BufferLookupEnt;
137138

139+
/*
140+
* Definitions for the buffer replacement strategy
141+
*/
142+
#define STRAT_LIST_UNUSED -1
143+
#define STRAT_LIST_B1 0
144+
#define STRAT_LIST_T1 1
145+
#define STRAT_LIST_T2 2
146+
#define STRAT_LIST_B2 3
147+
#define STRAT_NUM_LISTS 4
148+
149+
/*
150+
* The Cache Directory Block (CDB) of the Adaptive Replacement Cache (ARC)
151+
*/
152+
typedef struct
153+
{
154+
int prev; /* links in the queue */
155+
int next;
156+
int list; /* current list */
157+
BufferTag buf_tag; /* buffer key */
158+
Buffer buf_id; /* currently assigned data buffer */
159+
TransactionId t1_xid; /* the xid this entry went onto T1 */
160+
} BufferStrategyCDB;
161+
162+
/*
163+
* The shared ARC control information.
164+
*/
165+
typedef struct
166+
{
167+
168+
int target_T1_size; /* What T1 size are we aiming for */
169+
int listUnusedCDB; /* All unused StrategyCDB */
170+
int listHead[STRAT_NUM_LISTS]; /* ARC lists B1, T1, T2 and B2 */
171+
int listTail[STRAT_NUM_LISTS];
172+
int listSize[STRAT_NUM_LISTS];
173+
Buffer listFreeBuffers; /* List of unused buffers */
174+
175+
long num_lookup; /* Some hit statistics */
176+
long num_hit[STRAT_NUM_LISTS];
177+
time_t stat_report;
178+
179+
BufferStrategyCDB cdb[1]; /* The cache directory */
180+
} BufferStrategyControl;
181+
138182
/* counters in buf_init.c */
139183
extern long int ReadBufferCount;
140184
extern long int ReadLocalBufferCount;

0 commit comments

Comments
 (0)