Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b25dc48

Browse files
committed
Fix oversight in sizing of shared buffer lookup hashtable. Because
BufferAlloc tries to insert a new mapping entry before deleting the old one for a buffer, we have a transient need for more than NBuffers entries --- one more in 8.1, and as many as NUM_BUFFER_PARTITIONS more in CVS HEAD. In theory this could lead to an "out of shared memory" failure if shmem had already been completely claimed by the time the extra entries were needed.
1 parent 10b9ca3 commit b25dc48

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/storage/buffer/freelist.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.55 2006/03/05 15:58:36 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.56 2006/07/23 18:34:45 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -213,8 +213,8 @@ StrategyShmemSize(void)
213213
{
214214
Size size = 0;
215215

216-
/* size of lookup hash table */
217-
size = add_size(size, BufTableShmemSize(NBuffers));
216+
/* size of lookup hash table ... see comment in StrategyInitialize */
217+
size = add_size(size, BufTableShmemSize(NBuffers + NUM_BUFFER_PARTITIONS));
218218

219219
/* size of the shared replacement strategy control block */
220220
size = add_size(size, MAXALIGN(sizeof(BufferStrategyControl)));
@@ -236,8 +236,15 @@ StrategyInitialize(bool init)
236236

237237
/*
238238
* Initialize the shared buffer lookup hashtable.
239+
*
240+
* Since we can't tolerate running out of lookup table entries, we
241+
* must be sure to specify an adequate table size here. The maximum
242+
* steady-state usage is of course NBuffers entries, but BufferAlloc()
243+
* tries to insert a new entry before deleting the old. In principle
244+
* this could be happening in each partition concurrently, so we
245+
* could need as many as NBuffers + NUM_BUFFER_PARTITIONS entries.
239246
*/
240-
InitBufTable(NBuffers);
247+
InitBufTable(NBuffers + NUM_BUFFER_PARTITIONS);
241248

242249
/*
243250
* Get or create the shared strategy control block

0 commit comments

Comments
 (0)