mirror of
https://github.com/postgres/postgres.git
synced 2025-08-17 01:02:17 +03:00
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.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.84 2005/05/29 04:23:04 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.85 2005/08/20 23:26:20 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -141,8 +141,8 @@ InitShmemAllocation(void *seghdr, bool init)
|
||||
void *
|
||||
ShmemAlloc(Size size)
|
||||
{
|
||||
uint32 newStart;
|
||||
uint32 newFree;
|
||||
Size newStart;
|
||||
Size newFree;
|
||||
void *newSpace;
|
||||
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
@@ -415,3 +415,40 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
SpinLockRelease(ShmemIndexLock);
|
||||
return structPtr;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add two Size values, checking for overflow
|
||||
*/
|
||||
Size
|
||||
add_size(Size s1, Size s2)
|
||||
{
|
||||
Size result;
|
||||
|
||||
result = s1 + s2;
|
||||
/* We are assuming Size is an unsigned type here... */
|
||||
if (result < s1 || result < s2)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("requested shared memory size overflows size_t")));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Multiply two Size values, checking for overflow
|
||||
*/
|
||||
Size
|
||||
mul_size(Size s1, Size s2)
|
||||
{
|
||||
Size result;
|
||||
|
||||
if (s1 == 0 || s2 == 0)
|
||||
return 0;
|
||||
result = s1 * s2;
|
||||
/* We are assuming Size is an unsigned type here... */
|
||||
if (result / s2 != s1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("requested shared memory size overflows size_t")));
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user