1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-13 16:22:44 +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:
Tom Lane
2005-08-20 23:26:37 +00:00
parent 2299ceab1c
commit 0007490e09
50 changed files with 774 additions and 275 deletions

View File

@@ -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;
}

View File

@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.41 2005/05/29 04:23:04 tgl Exp $
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.42 2005/08/20 23:26:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -37,7 +37,7 @@ static HTAB *SharedBufHash;
* Estimate space needed for mapping hashtable
* size is the desired hash table size (possibly more than NBuffers)
*/
int
Size
BufTableShmemSize(int size)
{
return hash_estimate_size(size, sizeof(BufferLookupEnt));

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.51 2005/03/04 20:21:06 tgl Exp $
* $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.52 2005/08/20 23:26:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -208,16 +208,16 @@ StrategyHintVacuum(bool vacuum_active)
* Note: for somewhat historical reasons, the buffer lookup hashtable size
* is also determined here.
*/
int
Size
StrategyShmemSize(void)
{
int size = 0;
Size size = 0;
/* size of lookup hash table */
size += BufTableShmemSize(NBuffers);
size = add_size(size, BufTableShmemSize(NBuffers));
/* size of the shared replacement strategy control block */
size += MAXALIGN(sizeof(BufferStrategyControl));
size = add_size(size, MAXALIGN(sizeof(BufferStrategyControl)));
return size;
}

View File

@@ -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;