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/localbuf.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/backend/storage/buffer/localbuf.c') diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index 6ac0b543ae3..6dce5086562 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.68 2005/08/08 19:44:22 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.69 2005/08/20 23:26:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -255,15 +255,13 @@ InitLocalBuffers(void) int i; /* Allocate and zero buffer headers and auxiliary arrays */ - LocalBufferDescriptors = (BufferDesc *) - MemoryContextAllocZero(TopMemoryContext, - nbufs * sizeof(BufferDesc)); - LocalBufferBlockPointers = (Block *) - MemoryContextAllocZero(TopMemoryContext, - nbufs * sizeof(Block)); - LocalRefCount = (int32 *) - MemoryContextAllocZero(TopMemoryContext, - nbufs * sizeof(int32)); + LocalBufferDescriptors = (BufferDesc *) calloc(nbufs, sizeof(BufferDesc)); + LocalBufferBlockPointers = (Block *) calloc(nbufs, sizeof(Block)); + LocalRefCount = (int32 *) calloc(nbufs, sizeof(int32)); + if (!LocalBufferDescriptors || !LocalBufferBlockPointers || !LocalRefCount) + ereport(FATAL, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); nextFreeLocalBuf = 0; -- cgit v1.2.3