From 69f3a5c9ed7bf369db49a1696ec430d2710ef9e1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 23 Jul 2006 18:34:50 +0000 Subject: [PATCH] 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. --- src/backend/storage/buffer/freelist.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c index e204b0d0094..c822819528d 100644 --- a/src/backend/storage/buffer/freelist.c +++ b/src/backend/storage/buffer/freelist.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.54 2005/10/15 02:49:25 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.54.2.1 2006/07/23 18:34:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -213,8 +213,8 @@ StrategyShmemSize(void) { Size size = 0; - /* size of lookup hash table */ - size = add_size(size, BufTableShmemSize(NBuffers)); + /* size of lookup hash table ... see comment in StrategyInitialize */ + size = add_size(size, BufTableShmemSize(NBuffers + 1)); /* size of the shared replacement strategy control block */ size = add_size(size, MAXALIGN(sizeof(BufferStrategyControl))); @@ -236,8 +236,13 @@ StrategyInitialize(bool init) /* * Initialize the shared buffer lookup hashtable. + * + * Since we can't tolerate running out of lookup table entries, we + * must be sure to specify an adequate table size here. The maximum + * steady-state usage is of course NBuffers entries, but BufferAlloc() + * tries to insert a new entry before deleting the old. */ - InitBufTable(NBuffers); + InitBufTable(NBuffers + 1); /* * Get or create the shared strategy control block -- 2.39.5