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/ipc/ipci.c | |
parent | 2299ceab1cc5e141431f19eaf70c30f0d84eb28b (diff) |
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/ipc/ipci.c')
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 0761a8fdf51..48ef94a3ecb 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.77 2005/06/17 22:32:45 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.78 2005/08/20 23:26:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -61,36 +61,44 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) if (!IsUnderPostmaster) { - int size; + Size size; int numSemas; /* * Size of the Postgres shared-memory block is estimated via * moderately-accurate estimates for the big hogs, plus 100K for * the stuff that's too small to bother with estimating. + * + * We take some care during this phase to ensure that the total + * size request doesn't overflow size_t. If this gets through, + * we don't need to be so careful during the actual allocation + * phase. */ - size = hash_estimate_size(SHMEM_INDEX_SIZE, sizeof(ShmemIndexEnt)); - size += BufferShmemSize(); - size += LockShmemSize(); - size += ProcGlobalShmemSize(); - size += XLOGShmemSize(); - size += CLOGShmemSize(); - size += SUBTRANSShmemSize(); - size += TwoPhaseShmemSize(); - size += MultiXactShmemSize(); - size += LWLockShmemSize(); - size += ProcArrayShmemSize(); - size += SInvalShmemSize(MaxBackends); - size += FreeSpaceShmemSize(); - size += BgWriterShmemSize(); + size = 100000; + size = add_size(size, hash_estimate_size(SHMEM_INDEX_SIZE, + sizeof(ShmemIndexEnt))); + size = add_size(size, BufferShmemSize()); + size = add_size(size, LockShmemSize()); + size = add_size(size, ProcGlobalShmemSize()); + size = add_size(size, XLOGShmemSize()); + size = add_size(size, CLOGShmemSize()); + size = add_size(size, SUBTRANSShmemSize()); + size = add_size(size, TwoPhaseShmemSize()); + size = add_size(size, MultiXactShmemSize()); + size = add_size(size, LWLockShmemSize()); + size = add_size(size, ProcArrayShmemSize()); + size = add_size(size, SInvalShmemSize()); + size = add_size(size, FreeSpaceShmemSize()); + size = add_size(size, BgWriterShmemSize()); #ifdef EXEC_BACKEND - size += ShmemBackendArraySize(); + size = add_size(size, ShmemBackendArraySize()); #endif - size += 100000; + /* might as well round it off to a multiple of a typical page size */ - size += 8192 - (size % 8192); + size = add_size(size, 8192 - (size % 8192)); - elog(DEBUG3, "invoking IpcMemoryCreate(size=%d)", size); + elog(DEBUG3, "invoking IpcMemoryCreate(size=%lu)", + (unsigned long) size); /* * Create the shmem segment @@ -163,7 +171,7 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) /* * Set up shared-inval messaging */ - CreateSharedInvalidationState(MaxBackends); + CreateSharedInvalidationState(); /* * Set up free-space map |