1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +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

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.283 2005/08/19 18:58:18 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.284 2005/08/20 23:26:26 tgl Exp $
*
*--------------------------------------------------------------------
*/
@ -78,6 +78,13 @@
#define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new"
#endif
/* upper limit for GUC variables measured in kilobytes of memory */
#if SIZEOF_SIZE_T > 4
#define MAX_KILOBYTES INT_MAX
#else
#define MAX_KILOBYTES (INT_MAX / 1024)
#endif
/* XXX these should appear in other modules' header files */
extern bool Log_disconnections;
extern DLLIMPORT bool check_function_bodies;
@ -1027,6 +1034,10 @@ static struct config_int ConfigureNamesInt[] =
* constraints here are partially unused. Similarly, the superuser
* reserved number is checked to ensure it is less than the max
* backends number.
*
* MaxBackends is limited to INT_MAX/4 because some places compute
* 4*MaxBackends without any overflow check. Likewise we have to
* limit NBuffers to INT_MAX/2.
*/
{
{"max_connections", PGC_POSTMASTER, CONN_AUTH_SETTINGS,
@ -1034,7 +1045,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&MaxBackends,
100, 1, INT_MAX / BLCKSZ, NULL, NULL
100, 1, INT_MAX / 4, NULL, NULL
},
{
@ -1043,7 +1054,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&ReservedBackends,
2, 0, INT_MAX / BLCKSZ, NULL, NULL
2, 0, INT_MAX / 4, NULL, NULL
},
{
@ -1052,7 +1063,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&NBuffers,
1000, 16, INT_MAX / BLCKSZ, NULL, NULL
1000, 16, INT_MAX / 2, NULL, NULL
},
{
@ -1061,7 +1072,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&num_temp_buffers,
1000, 100, INT_MAX / BLCKSZ, NULL, show_num_temp_buffers
1000, 100, INT_MAX / 2, NULL, show_num_temp_buffers
},
{
@ -1094,7 +1105,7 @@ static struct config_int ConfigureNamesInt[] =
"temporary disk files.")
},
&work_mem,
1024, 8 * BLCKSZ / 1024, INT_MAX / 1024, NULL, NULL
1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
},
{
@ -1103,7 +1114,7 @@ static struct config_int ConfigureNamesInt[] =
gettext_noop("This includes operations such as VACUUM and CREATE INDEX.")
},
&maintenance_work_mem,
16384, 1024, INT_MAX / 1024, NULL, NULL
16384, 1024, MAX_KILOBYTES, NULL, NULL
},
{
@ -1112,7 +1123,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&max_stack_depth,
2048, 100, INT_MAX / 1024, assign_max_stack_depth, NULL
2048, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
},
{
@ -1193,7 +1204,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&max_prepared_xacts,
50, 0, 10000, NULL, NULL
50, 0, INT_MAX, NULL, NULL
},
#ifdef LOCK_DEBUG
@ -1310,7 +1321,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&XLOGbuffers,
8, 4, INT_MAX / BLCKSZ, NULL, NULL
8, 4, INT_MAX, NULL, NULL
},
{