aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-07-23 18:34:45 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-07-23 18:34:45 +0000
commitb25dc481c8cf2d5ec894b6267ca97939997c698e (patch)
tree6ee3756b32df6bacc8216f97e10213e56c5fdea4 /src
parent10b9ca3d054a75e3c361b12388c50a11c828aa24 (diff)
downloadpostgresql-b25dc481c8cf2d5ec894b6267ca97939997c698e.tar.gz
postgresql-b25dc481c8cf2d5ec894b6267ca97939997c698e.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/buffer/freelist.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c
index 7db8b766aaa..333053c1c93 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.55 2006/03/05 15:58:36 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.56 2006/07/23 18:34:45 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 + NUM_BUFFER_PARTITIONS));
/* size of the shared replacement strategy control block */
size = add_size(size, MAXALIGN(sizeof(BufferStrategyControl)));
@@ -236,8 +236,15 @@ 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. In principle
+ * this could be happening in each partition concurrently, so we
+ * could need as many as NBuffers + NUM_BUFFER_PARTITIONS entries.
*/
- InitBufTable(NBuffers);
+ InitBufTable(NBuffers + NUM_BUFFER_PARTITIONS);
/*
* Get or create the shared strategy control block