From 0007490e0964d194a606ba79bb11ae1642da3372 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 20 Aug 2005 23:26:37 +0000 Subject: Convert the arithmetic for shared memory size calculation from 'int' to 'Size' (that is, size_t), and install overflow detection checks in it. This allows us to remove the former arbitrary restrictions on NBuffers etc. It won't make any difference in a 32-bit machine, but in a 64-bit machine you could theoretically have terabytes of shared buffers. (How efficiently we could manage 'em remains to be seen.) Similarly, num_temp_buffers, work_mem, and maintenance_work_mem can be set above 2Gb on a 64-bit machine. Original patch from Koichi Suzuki, additional work by moi. --- src/backend/storage/buffer/buf_init.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/backend/storage/buffer/buf_init.c') diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c index 5051e762d85..d74d356f0e6 100644 --- a/src/backend/storage/buffer/buf_init.c +++ b/src/backend/storage/buffer/buf_init.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.75 2005/08/12 05:05:50 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/buf_init.c,v 1.76 2005/08/20 23:26:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -89,7 +89,7 @@ InitBufferPool(void) BufferBlocks = (char *) ShmemInitStruct("Buffer Blocks", - NBuffers * BLCKSZ, &foundBufs); + NBuffers * (Size) BLCKSZ, &foundBufs); if (foundDescs || foundBufs) { @@ -155,8 +155,11 @@ InitBufferPoolAccess(void) /* * Allocate and zero local arrays of per-buffer info. */ - PrivateRefCount = (int32 *) calloc(NBuffers, - sizeof(*PrivateRefCount)); + PrivateRefCount = (int32 *) calloc(NBuffers, sizeof(int32)); + if (!PrivateRefCount) + ereport(FATAL, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); } /* @@ -165,19 +168,19 @@ InitBufferPoolAccess(void) * compute the size of shared memory for the buffer pool including * data pages, buffer descriptors, hash tables, etc. */ -int +Size BufferShmemSize(void) { - int size = 0; + Size size = 0; /* size of buffer descriptors */ - size += MAXALIGN(NBuffers * sizeof(BufferDesc)); + size = add_size(size, mul_size(NBuffers, sizeof(BufferDesc))); /* size of data pages */ - size += NBuffers * MAXALIGN(BLCKSZ); + size = add_size(size, mul_size(NBuffers, BLCKSZ)); /* size of stuff controlled by freelist.c */ - size += StrategyShmemSize(); + size = add_size(size, StrategyShmemSize()); return size; } -- cgit v1.2.3