diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-08-20 23:26:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-08-20 23:26:37 +0000 |
commit | 0007490e0964d194a606ba79bb11ae1642da3372 (patch) | |
tree | 91db8ec49d812ba2c4307fcf858dfb7fd3890819 /src/backend/storage/freespace/freespace.c | |
parent | 2299ceab1cc5e141431f19eaf70c30f0d84eb28b (diff) | |
download | postgresql-0007490e0964d194a606ba79bb11ae1642da3372.tar.gz postgresql-0007490e0964d194a606ba79bb11ae1642da3372.zip |
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.
Diffstat (limited to 'src/backend/storage/freespace/freespace.c')
-rw-r--r-- | src/backend/storage/freespace/freespace.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/backend/storage/freespace/freespace.c b/src/backend/storage/freespace/freespace.c index f8e32d23854..11fc45ea8e7 100644 --- a/src/backend/storage/freespace/freespace.c +++ b/src/backend/storage/freespace/freespace.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.47 2005/08/17 03:50:59 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.48 2005/08/20 23:26:20 tgl Exp $ * * * NOTES: @@ -271,11 +271,13 @@ InitFreeSpaceMap(void) bool found; /* Create table header */ - FreeSpaceMap = (FSMHeader *) ShmemInitStruct("Free Space Map Header", sizeof(FSMHeader), &found); + FreeSpaceMap = (FSMHeader *) ShmemInitStruct("Free Space Map Header", + sizeof(FSMHeader), + &found); if (FreeSpaceMap == NULL) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), - errmsg("insufficient shared memory for free space map"))); + errmsg("insufficient shared memory for free space map"))); if (!found) MemSet(FreeSpaceMap, 0, sizeof(FSMHeader)); @@ -308,7 +310,7 @@ InitFreeSpaceMap(void) errmsg("max_fsm_pages must exceed max_fsm_relations * %d", CHUNKPAGES))); - FreeSpaceMap->arena = (char *) ShmemAlloc(nchunks * CHUNKBYTES); + FreeSpaceMap->arena = (char *) ShmemAlloc((Size) nchunks * CHUNKBYTES); if (FreeSpaceMap->arena == NULL) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), @@ -322,27 +324,22 @@ InitFreeSpaceMap(void) /* * Estimate amount of shmem space needed for FSM. */ -int +Size FreeSpaceShmemSize(void) { - int size; + Size size; int nchunks; /* table header */ size = MAXALIGN(sizeof(FSMHeader)); /* hash table, including the FSMRelation objects */ - size += hash_estimate_size(MaxFSMRelations + 1, sizeof(FSMRelation)); + size = add_size(size, hash_estimate_size(MaxFSMRelations + 1, + sizeof(FSMRelation))); /* page-storage arena */ nchunks = (MaxFSMPages - 1) / CHUNKPAGES + 1; - - if (nchunks >= (INT_MAX / CHUNKBYTES)) - ereport(FATAL, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("max_fsm_pages is too large"))); - - size += MAXALIGN(nchunks * CHUNKBYTES); + size = add_size(size, mul_size(nchunks, CHUNKBYTES)); return size; } |