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.
+# And one for the size of size_t (enables tweaks for > 32bit address space)
+echo "$as_me:$LINENO: checking for size_t" >&5
+echo $ECHO_N "checking for size_t... $ECHO_C" >&6
+if test "${ac_cv_type_size_t+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+if ((size_t *) 0)
+ return 0;
+if (sizeof (size_t))
+ return 0;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_type_size_t=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_size_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5
+echo "${ECHO_T}$ac_cv_type_size_t" >&6
+
+echo "$as_me:$LINENO: checking size of size_t" >&5
+echo $ECHO_N "checking size of size_t... $ECHO_C" >&6
+if test "${ac_cv_sizeof_size_t+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test "$ac_cv_type_size_t" = yes; then
+ # The cast to unsigned long works around a bug in the HP C Compiler
+ # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+ # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+ # This bug is HP SR number 8606223364.
+ if test "$cross_compiling" = yes; then
+ # Depending upon the size, compute the lo and hi bounds.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) >= 0)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_lo=0 ac_mid=0
+ while :; do
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) <= $ac_mid)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_hi=$ac_mid; break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo=`expr $ac_mid + 1`
+ if test $ac_lo -le $ac_mid; then
+ ac_lo= ac_hi=
+ break
+ fi
+ ac_mid=`expr 2 '*' $ac_mid + 1`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ done
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) < 0)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_hi=-1 ac_mid=-1
+ while :; do
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) >= $ac_mid)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_lo=$ac_mid; break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_hi=`expr '(' $ac_mid ')' - 1`
+ if test $ac_mid -le $ac_hi; then
+ ac_lo= ac_hi=
+ break
+ fi
+ ac_mid=`expr 2 '*' $ac_mid`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ done
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo= ac_hi=
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+ ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (size_t))) <= $ac_mid)];
+test_array [0] = 0
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_hi=$ac_mid
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo=`expr '(' $ac_mid ')' + 1`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in
+?*) ac_cv_sizeof_size_t=$ac_lo;;
+'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; } ;;
+esac
+else
+ if test "$cross_compiling" = yes; then
+ { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+long longval () { return (long) (sizeof (size_t)); }
+unsigned long ulongval () { return (long) (sizeof (size_t)); }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+ FILE *f = fopen ("conftest.val", "w");
+ if (! f)
+ exit (1);
+ if (((long) (sizeof (size_t))) < 0)
+ {
+ long i = longval ();
+ if (i != ((long) (sizeof (size_t))))
+ exit (1);
+ fprintf (f, "%ld\n", i);
+ }
+ else
+ {
+ unsigned long i = ulongval ();
+ if (i != ((long) (sizeof (size_t))))
+ exit (1);
+ fprintf (f, "%lu\n", i);
+ }
+ exit (ferror (f) || fclose (f) != 0);
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_sizeof_size_t=`cat conftest.val`
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+{ { echo "$as_me:$LINENO: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (size_t), 77
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+rm -f conftest.val
+else
+ ac_cv_sizeof_size_t=0
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sizeof_size_t" >&5
+echo "${ECHO_T}$ac_cv_sizeof_size_t" >&6
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t
+_ACEOF
+
+
+
# Determine memory alignment requirements for the basic C data types.
echo "$as_me:$LINENO: checking for short" >&5
dnl Process this file with autoconf to produce a configure script.
-dnl $PostgreSQL: pgsql/configure.in,v 1.419 2005/08/17 20:20:10 tgl Exp $
+dnl $PostgreSQL: pgsql/configure.in,v 1.420 2005/08/20 23:26:06 tgl Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
# Need a #define for the size of Datum (unsigned long)
AC_CHECK_SIZEOF([unsigned long])
+# And one for the size of size_t (enables tweaks for > 32bit address space)
+AC_CHECK_SIZEOF([size_t])
+
# Determine memory alignment requirements for the basic C data types.
PGAC_CHECK_ALIGNOF(short)
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.31 2005/06/30 00:00:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.32 2005/08/20 23:26:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Initialization of shared memory for CLOG
*/
-
-int
+Size
CLOGShmemSize(void)
{
return SimpleLruShmemSize();
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.7 2005/08/20 01:29:27 ishii Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.8 2005/08/20 23:26:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* thus double memory. Also, reserve space for the shared MultiXactState
* struct and the per-backend MultiXactId arrays (two of those, too).
*/
-int
+Size
MultiXactShmemSize(void)
{
+ Size size;
+
#define SHARED_MULTIXACT_STATE_SIZE \
- (sizeof(MultiXactStateData) + sizeof(MultiXactId) * 2 * MaxBackends)
+ add_size(sizeof(MultiXactStateData), \
+ mul_size(sizeof(MultiXactId) * 2, MaxBackends))
+
+ size = SHARED_MULTIXACT_STATE_SIZE;
+ size = add_size(size, SimpleLruShmemSize());
+ size = add_size(size, SimpleLruShmemSize());
- return (SimpleLruShmemSize() * 2 + SHARED_MULTIXACT_STATE_SIZE);
+ return size;
}
void
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.26 2005/07/04 04:51:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.27 2005/08/20 23:26:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Initialization of shared memory
*/
-int
+Size
SimpleLruShmemSize(void)
{
+ /* we assume NUM_SLRU_BUFFERS isn't so large as to risk overflow */
return BUFFERALIGN(sizeof(SlruSharedData)) + BLCKSZ * NUM_SLRU_BUFFERS;
}
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.9 2005/06/17 22:32:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.10 2005/08/20 23:26:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Initialization of shared memory for SUBTRANS
*/
-
-int
+Size
SUBTRANSShmemSize(void)
{
return SimpleLruShmemSize();
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.9 2005/07/31 17:19:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.10 2005/08/20 23:26:10 tgl Exp $
*
* NOTES
* Each global transaction is associated with a global transaction
/*
* Initialization of shared memory
*/
-int
+Size
TwoPhaseShmemSize(void)
{
+ Size size;
+
/* Need the fixed struct, the array of pointers, and the GTD structs */
- return MAXALIGN(offsetof(TwoPhaseStateData, prepXacts) +
- sizeof(GlobalTransaction) * max_prepared_xacts) +
- sizeof(GlobalTransactionData) * max_prepared_xacts;
+ size = offsetof(TwoPhaseStateData, prepXacts);
+ size = add_size(size, mul_size(max_prepared_xacts,
+ sizeof(GlobalTransaction)));
+ size = MAXALIGN(size);
+ size = add_size(size, mul_size(max_prepared_xacts,
+ sizeof(GlobalTransactionData)));
+
+ return size;
}
void
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.215 2005/08/11 21:11:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.216 2005/08/20 23:26:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#endif
#endif
-/*
- * Limitation of buffer-alignment for direct io depend on OS and filesystem,
- * but BLCKSZ is assumed to be enough for it.
- */
-#ifdef O_DIRECT
-#define ALIGNOF_XLOG_BUFFER BLCKSZ
-#else
-#define ALIGNOF_XLOG_BUFFER MAXIMUM_ALIGNOF
-#endif
-
-/*
- * Switch the alignment routine because ShmemAlloc() returns a max-aligned
- * buffer and ALIGNOF_XLOG_BUFFER may be greater than MAXIMUM_ALIGNOF.
- */
-#if ALIGNOF_XLOG_BUFFER <= MAXIMUM_ALIGNOF
-#define XLOG_BUFFER_ALIGN(LEN) MAXALIGN((LEN))
-#else
-#define XLOG_BUFFER_ALIGN(LEN) ((LEN) + (ALIGNOF_XLOG_BUFFER))
-#endif
-/* assume sizeof(ptrdiff_t) == sizeof(void*) */
-#define POINTERALIGN(ALIGNVAL,PTR) \
- ((char *)(((ptrdiff_t) (PTR) + (ALIGNVAL-1)) & ~((ptrdiff_t) (ALIGNVAL-1))))
-#define XLOG_BUFFER_POINTERALIGN(PTR) \
- POINTERALIGN((ALIGNOF_XLOG_BUFFER), (PTR))
-
#ifdef OPEN_DATASYNC_FLAG
#define DEFAULT_SYNC_METHOD_STR "open_datasync"
#define DEFAULT_SYNC_METHOD SYNC_METHOD_OPEN
#endif
+/*
+ * Limitation of buffer-alignment for direct IO depends on OS and filesystem,
+ * but BLCKSZ is assumed to be enough for it.
+ */
+#ifdef O_DIRECT
+#define ALIGNOF_XLOG_BUFFER BLCKSZ
+#else
+#define ALIGNOF_XLOG_BUFFER ALIGNOF_BUFFER
+#endif
+
+
/* File path names (all relative to $PGDATA) */
#define BACKUP_LABEL_FILE "backup_label"
#define RECOVERY_COMMAND_FILE "recovery.conf"
#define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
-#define MinXLOGbuffers 4
-
/*
* ThisTimeLineID will be same in all backends --- it identifies current
/*
* Initialization of shared memory for XLOG
*/
-
-int
+Size
XLOGShmemSize(void)
{
- if (XLOGbuffers < MinXLOGbuffers)
- XLOGbuffers = MinXLOGbuffers;
+ Size size;
- return XLOG_BUFFER_ALIGN(sizeof(XLogCtlData) + sizeof(XLogRecPtr) * XLOGbuffers)
- + BLCKSZ * XLOGbuffers +
- MAXALIGN(sizeof(ControlFileData));
+ /* XLogCtl */
+ size = sizeof(XLogCtlData);
+ /* xlblocks array */
+ size = add_size(size, mul_size(sizeof(XLogRecPtr), XLOGbuffers));
+ /* extra alignment padding for XLOG I/O buffers */
+ size = add_size(size, ALIGNOF_XLOG_BUFFER);
+ /* and the buffers themselves */
+ size = add_size(size, mul_size(BLCKSZ, XLOGbuffers));
+
+ /*
+ * Note: we don't count ControlFileData, it comes out of the "slop
+ * factor" added by CreateSharedMemoryAndSemaphores. This lets us
+ * use this routine again below to compute the actual allocation size.
+ */
+
+ return size;
}
void
{
bool foundXLog,
foundCFile;
-
- /* this must agree with space requested by XLOGShmemSize() */
- if (XLOGbuffers < MinXLOGbuffers)
- XLOGbuffers = MinXLOGbuffers;
+ char *allocptr;
XLogCtl = (XLogCtlData *)
- ShmemInitStruct("XLOG Ctl",
- XLOG_BUFFER_ALIGN(sizeof(XLogCtlData) +
- sizeof(XLogRecPtr) * XLOGbuffers)
- + BLCKSZ * XLOGbuffers,
- &foundXLog);
+ ShmemInitStruct("XLOG Ctl", XLOGShmemSize(), &foundXLog);
ControlFile = (ControlFileData *)
ShmemInitStruct("Control File", sizeof(ControlFileData), &foundCFile);
* a multiple of the alignment for same, so no extra alignment padding
* is needed here.
*/
- XLogCtl->xlblocks = (XLogRecPtr *)
- (((char *) XLogCtl) + sizeof(XLogCtlData));
+ allocptr = ((char *) XLogCtl) + sizeof(XLogCtlData);
+ XLogCtl->xlblocks = (XLogRecPtr *) allocptr;
memset(XLogCtl->xlblocks, 0, sizeof(XLogRecPtr) * XLOGbuffers);
+ allocptr += sizeof(XLogRecPtr) * XLOGbuffers;
/*
- * Here, on the other hand, we must MAXALIGN to ensure the page
- * buffers have worst-case alignment.
+ * Align the start of the page buffers to an ALIGNOF_XLOG_BUFFER boundary.
*/
- XLogCtl->pages = XLOG_BUFFER_POINTERALIGN(
- ((char *) XLogCtl)
- + sizeof(XLogCtlData) + sizeof(XLogRecPtr) * XLOGbuffers);
+ allocptr = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, allocptr);
+ XLogCtl->pages = allocptr;
memset(XLogCtl->pages, 0, BLCKSZ * XLOGbuffers);
/*
/* First timeline ID is always 1 */
ThisTimeLineID = 1;
- buffer = (char *) malloc(BLCKSZ + ALIGNOF_XLOG_BUFFER);
- page = (XLogPageHeader) XLOG_BUFFER_POINTERALIGN(buffer);
+ /* page buffer must be aligned suitably for O_DIRECT */
+ buffer = (char *) palloc(BLCKSZ + ALIGNOF_XLOG_BUFFER);
+ page = (XLogPageHeader) TYPEALIGN(ALIGNOF_XLOG_BUFFER, buffer);
memset(page, 0, BLCKSZ);
/* Set up information for the initial checkpoint record */
BootStrapSUBTRANS();
BootStrapMultiXact();
- free(buffer);
+ pfree(buffer);
}
static char *
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.56 2005/07/29 19:30:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.57 2005/08/20 23:26:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static void
lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
{
- int maxtuples;
+ long maxtuples;
int maxpages;
- maxtuples = (int) ((maintenance_work_mem * 1024L) / sizeof(ItemPointerData));
+ maxtuples = (maintenance_work_mem * 1024L) / sizeof(ItemPointerData);
+ maxtuples = Min(maxtuples, INT_MAX);
/* stay sane if small maintenance_work_mem */
- if (maxtuples < MAX_TUPLES_PER_PAGE)
- maxtuples = MAX_TUPLES_PER_PAGE;
+ maxtuples = Max(maxtuples, MAX_TUPLES_PER_PAGE);
vacrelstats->num_dead_tuples = 0;
- vacrelstats->max_dead_tuples = maxtuples;
+ vacrelstats->max_dead_tuples = (int) maxtuples;
vacrelstats->dead_tuples = (ItemPointer)
palloc(maxtuples * sizeof(ItemPointerData));
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.42 2004/12/31 22:00:30 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.43 2005/08/20 23:26:13 tgl Exp $
*
*-------------------------------------------------------------------------
*/
unsigned long UsedShmemSegID = 0;
void *UsedShmemSegAddr = NULL;
-static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size);
+static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size);
static void IpcMemoryDetach(int status, Datum shmaddr);
static void IpcMemoryDelete(int status, Datum shmId);
static PGShmemHeader *PGSharedMemoryAttach(IpcMemoryKey key,
* print out an error and abort. Other types of errors are not recoverable.
*/
static void *
-InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
+InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
{
IpcMemoryId shmid;
void *memAddress;
*/
ereport(FATAL,
(errmsg("could not create shared memory segment: %m"),
- errdetail("Failed system call was shmget(key=%lu, size=%u, 0%o).",
- (unsigned long) memKey, size,
+ errdetail("Failed system call was shmget(key=%lu, size=%lu, 0%o).",
+ (unsigned long) memKey, (unsigned long) size,
IPC_CREAT | IPC_EXCL | IPCProtection),
(errno == EINVAL) ?
errhint("This error usually means that PostgreSQL's request for a shared memory "
"segment exceeded your kernel's SHMMAX parameter. You can either "
"reduce the request size or reconfigure the kernel with larger SHMMAX. "
- "To reduce the request size (currently %u bytes), reduce "
+ "To reduce the request size (currently %lu bytes), reduce "
"PostgreSQL's shared_buffers parameter (currently %d) and/or "
"its max_connections parameter (currently %d).\n"
"If the request size is already small, it's possible that it is less than "
"reconfiguring SHMMIN is called for.\n"
"The PostgreSQL documentation contains more information about shared "
"memory configuration.",
- size, NBuffers, MaxBackends) : 0,
+ (unsigned long) size, NBuffers, MaxBackends) : 0,
(errno == ENOMEM) ?
errhint("This error usually means that PostgreSQL's request for a shared "
"memory segment exceeded available memory or swap space. "
- "To reduce the request size (currently %u bytes), reduce "
+ "To reduce the request size (currently %lu bytes), reduce "
"PostgreSQL's shared_buffers parameter (currently %d) and/or "
"its max_connections parameter (currently %d).\n"
"The PostgreSQL documentation contains more information about shared "
"memory configuration.",
- size, NBuffers, MaxBackends) : 0,
+ (unsigned long) size, NBuffers, MaxBackends) : 0,
(errno == ENOSPC) ?
errhint("This error does *not* mean that you have run out of disk space. "
"It occurs either if all available shared memory IDs have been taken, "
"in which case you need to raise the SHMMNI parameter in your kernel, "
"or because the system's overall limit for shared memory has been "
"reached. If you cannot increase the shared memory limit, "
- "reduce PostgreSQL's shared memory request (currently %u bytes), "
+ "reduce PostgreSQL's shared memory request (currently %lu bytes), "
"by reducing its shared_buffers parameter (currently %d) and/or "
"its max_connections parameter (currently %d).\n"
"The PostgreSQL documentation contains more information about shared "
"memory configuration.",
- size, NBuffers, MaxBackends) : 0));
+ (unsigned long) size, NBuffers, MaxBackends) : 0));
}
/* Register on-exit routine to delete the new segment */
* zero will be passed.
*/
PGShmemHeader *
-PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
+PGSharedMemoryCreate(Size size, bool makePrivate, int port)
{
IpcMemoryKey NextShmemSegID;
void *memAddress;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.18 2005/08/02 20:52:08 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.19 2005/08/20 23:26:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* BgWriterShmemSize
* Compute space needed for bgwriter-related shared memory
*/
-int
+Size
BgWriterShmemSize(void)
{
+ Size size;
+
/*
* Currently, the size of the requests[] array is arbitrarily set
* equal to NBuffers. This may prove too large or small ...
*/
- return MAXALIGN(sizeof(BgWriterShmemStruct) +
- (NBuffers - 1) *sizeof(BgWriterRequest));
+ size = offsetof(BgWriterShmemStruct, requests);
+ size = add_size(size, mul_size(NBuffers, sizeof(BgWriterRequest)));
+
+ return size;
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.466 2005/08/12 19:43:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.467 2005/08/20 23:26:17 tgl Exp $
*
* NOTES
*
* Initialize the child pid/HANDLE arrays for signal handling.
*/
win32_childPIDArray = (pid_t *)
- malloc(NUM_BACKENDARRAY_ELEMS * sizeof(pid_t));
+ malloc(mul_size(NUM_BACKENDARRAY_ELEMS, sizeof(pid_t)));
win32_childHNDArray = (HANDLE *)
- malloc(NUM_BACKENDARRAY_ELEMS * sizeof(HANDLE));
+ malloc(mul_size(NUM_BACKENDARRAY_ELEMS, sizeof(HANDLE)));
if (!win32_childPIDArray || !win32_childHNDArray)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
}
-size_t
+Size
ShmemBackendArraySize(void)
{
- return (NUM_BACKENDARRAY_ELEMS * sizeof(Backend));
+ return mul_size(NUM_BACKENDARRAY_ELEMS, sizeof(Backend));
}
void
ShmemBackendArrayAllocation(void)
{
- size_t size = ShmemBackendArraySize();
+ Size size = ShmemBackendArraySize();
ShmemBackendArray = (Backend *) ShmemAlloc(size);
/* Mark all slots as empty */
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
BufferBlocks = (char *)
ShmemInitStruct("Buffer Blocks",
- NBuffers * BLCKSZ, &foundBufs);
+ NBuffers * (Size) BLCKSZ, &foundBufs);
if (foundDescs || foundBufs)
{
/*
* 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")));
}
/*
* 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;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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));
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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;
* 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:
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));
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),
/*
* 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;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
/*
* Set up shared-inval messaging
*/
- CreateSharedInvalidationState(MaxBackends);
+ CreateSharedInvalidationState();
/*
* Set up free-space map
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.18 2004/12/31 22:00:56 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.19 2005/08/20 23:26:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool found;
PMSignalFlags = (sig_atomic_t *)
- ShmemInitStruct("PMSignalFlags", NUM_PMSIGNALS * sizeof(sig_atomic_t), &found);
+ ShmemInitStruct("PMSignalFlags",
+ NUM_PMSIGNALS * sizeof(sig_atomic_t),
+ &found);
if (!found)
MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.5 2005/08/20 01:26:36 ishii Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.6 2005/08/20 23:26:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Report shared-memory space needed by CreateSharedProcArray.
*/
-int
+Size
ProcArrayShmemSize(void)
{
- return MAXALIGN(offsetof(ProcArrayStruct, procs) +
- (MaxBackends + max_prepared_xacts) * sizeof(PGPROC *));
+ Size size;
+
+ size = offsetof(ProcArrayStruct, procs);
+ size = add_size(size, mul_size(sizeof(PGPROC *),
+ add_size(MaxBackends, max_prepared_xacts)));
+
+ return size;
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
void *
ShmemAlloc(Size size)
{
- uint32 newStart;
- uint32 newFree;
+ Size newStart;
+ Size newFree;
void *newSpace;
/* use volatile pointer to prevent code rearrangement */
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;
+}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.76 2005/05/19 21:35:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.77 2005/08/20 23:26:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* should be called only by the POSTMASTER */
/****************************************************************************/
void
-CreateSharedInvalidationState(int maxBackends)
+CreateSharedInvalidationState(void)
{
/* SInvalLock must be initialized already, during LWLock init */
- SIBufferInit(maxBackends);
+ SIBufferInit();
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.59 2005/05/19 21:35:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.60 2005/08/20 23:26:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* SInvalShmemSize --- return shared-memory space needed
*/
-int
-SInvalShmemSize(int maxBackends)
+Size
+SInvalShmemSize(void)
{
- /*
- * Figure space needed. Note sizeof(SISeg) includes the first
- * ProcState entry.
- */
- return sizeof(SISeg) + sizeof(ProcState) * (maxBackends - 1);
+ Size size;
+
+ size = offsetof(SISeg, procState);
+ size = add_size(size, mul_size(sizeof(ProcState), MaxBackends));
+
+ return size;
}
/*
* Create and initialize a new SI message buffer
*/
void
-SIBufferInit(int maxBackends)
+SIBufferInit(void)
{
- int segSize;
SISeg *segP;
int i;
bool found;
/* Allocate space in shared memory */
- segSize = SInvalShmemSize(maxBackends);
- shmInvalBuffer = segP = (SISeg *) ShmemInitStruct("shmInvalBuffer", segSize, &found);
+ shmInvalBuffer = segP = (SISeg *)
+ ShmemInitStruct("shmInvalBuffer", SInvalShmemSize(), &found);
if (found)
return;
segP->minMsgNum = 0;
segP->maxMsgNum = 0;
segP->lastBackend = 0;
- segP->maxBackends = maxBackends;
- segP->freeBackends = maxBackends;
+ segP->maxBackends = MaxBackends;
+ segP->freeBackends = MaxBackends;
/* The buffer[] array is initially all unused, so we need not fill it */
/* Mark all backends inactive */
- for (i = 0; i < maxBackends; i++)
+ for (i = 0; i < segP->maxBackends; i++)
{
segP->procState[i].nextMsgNum = -1; /* inactive */
segP->procState[i].resetState = false;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.156 2005/06/17 22:32:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.157 2005/08/20 23:26:23 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
/* This configuration variable is used to set the lock table size */
int max_locks_per_xact; /* set by guc.c */
-#define NLOCKENTS() (max_locks_per_xact * (MaxBackends + max_prepared_xacts))
+#define NLOCKENTS() \
+ mul_size(max_locks_per_xact, add_size(MaxBackends, max_prepared_xacts))
/* Record that's written to 2PC state file when a lock is persisted */
/*
* Estimate shared-memory space used for lock tables
*/
-int
+Size
LockShmemSize(void)
{
- int size = 0;
+ Size size;
long max_table_size = NLOCKENTS();
/* lock method headers */
- size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData));
+ size = MAX_LOCK_METHODS * MAXALIGN(sizeof(LockMethodData));
/* lockHash table */
- size += hash_estimate_size(max_table_size, sizeof(LOCK));
+ size = add_size(size, hash_estimate_size(max_table_size, sizeof(LOCK)));
/* proclockHash table */
- size += hash_estimate_size(max_table_size, sizeof(PROCLOCK));
+ size = add_size(size, hash_estimate_size(max_table_size, sizeof(PROCLOCK)));
/*
* Note we count only one pair of hash tables, since the userlocks
* Since the lockHash entry count above is only an estimate, add 10%
* safety margin.
*/
- size += size / 10;
+ size = add_size(size, size / 10);
return size;
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.28 2005/04/28 21:47:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.29 2005/08/20 23:26:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Compute shmem space needed for LWLocks.
*/
-int
+Size
LWLockShmemSize(void)
{
+ Size size;
int numLocks = NumLWLocks();
- uint32 spaceLocks;
/* Allocate the LWLocks plus space for shared allocation counter. */
- spaceLocks = numLocks * sizeof(LWLock) + 2 * sizeof(int);
- spaceLocks = MAXALIGN(spaceLocks);
+ size = mul_size(numLocks, sizeof(LWLock));
+
+ size = add_size(size, 2 * sizeof(int));
- return (int) spaceLocks;
+ return size;
}
CreateLWLocks(void)
{
int numLocks = NumLWLocks();
- uint32 spaceLocks = LWLockShmemSize();
+ Size spaceLocks = LWLockShmemSize();
LWLock *lock;
int id;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.162 2005/08/08 03:11:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.163 2005/08/20 23:26:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Report shared-memory space needed by InitProcGlobal.
*/
-int
+Size
ProcGlobalShmemSize(void)
{
- int size = 0;
-
- size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */
- size += MAXALIGN(NUM_DUMMY_PROCS * sizeof(PGPROC)); /* DummyProcs */
- size += MAXALIGN(MaxBackends * sizeof(PGPROC)); /* MyProcs */
- size += MAXALIGN(sizeof(slock_t)); /* ProcStructLock */
+ Size size = 0;
+
+ /* ProcGlobal */
+ size = add_size(size, sizeof(PROC_HDR));
+ /* DummyProcs */
+ size = add_size(size, mul_size(NUM_DUMMY_PROCS, sizeof(PGPROC)));
+ /* MyProcs */
+ size = add_size(size, mul_size(MaxBackends, sizeof(PGPROC)));
+ /* ProcStructLock */
+ size = add_size(size, sizeof(slock_t));
return size;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.63 2005/06/26 23:32:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.64 2005/08/20 23:26:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
+#include "storage/shmem.h"
#include "utils/dynahash.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
* memory; therefore it does not count HTAB which is in local memory.
* NB: assumes that all hash structure parameters have default values!
*/
-long
+Size
hash_estimate_size(long num_entries, Size entrysize)
{
- long size = 0;
+ Size size;
long nBuckets,
nSegments,
nDirEntries,
nDirEntries <<= 1; /* dir_alloc doubles dsize at each call */
/* fixed control info */
- size += MAXALIGN(sizeof(HASHHDR)); /* but not HTAB, per above */
+ size = MAXALIGN(sizeof(HASHHDR)); /* but not HTAB, per above */
/* directory */
- size += MAXALIGN(nDirEntries * sizeof(HASHSEGMENT));
+ size = add_size(size, mul_size(nDirEntries, sizeof(HASHSEGMENT)));
/* segments */
- size += nSegments * MAXALIGN(DEF_SEGSIZE * sizeof(HASHBUCKET));
+ size = add_size(size, mul_size(nSegments,
+ MAXALIGN(DEF_SEGSIZE * sizeof(HASHBUCKET))));
/* elements --- allocated in groups of up to HASHELEMENT_ALLOC_MAX */
elementSize = MAXALIGN(sizeof(HASHELEMENT)) + MAXALIGN(entrysize);
elementAllocCnt = Min(num_entries, HASHELEMENT_ALLOC_MAX);
elementAllocCnt = Max(elementAllocCnt, 1);
nElementAllocs = (num_entries - 1) / elementAllocCnt + 1;
- size += nElementAllocs * elementAllocCnt * elementSize;
+ size = add_size(size,
+ mul_size(nElementAllocs,
+ mul_size(elementAllocCnt, elementSize)));
return size;
}
* 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 $
*
*--------------------------------------------------------------------
*/
#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;
* 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,
NULL
},
&MaxBackends,
- 100, 1, INT_MAX / BLCKSZ, NULL, NULL
+ 100, 1, INT_MAX / 4, NULL, NULL
},
{
NULL
},
&ReservedBackends,
- 2, 0, INT_MAX / BLCKSZ, NULL, NULL
+ 2, 0, INT_MAX / 4, NULL, NULL
},
{
NULL
},
&NBuffers,
- 1000, 16, INT_MAX / BLCKSZ, NULL, NULL
+ 1000, 16, INT_MAX / 2, NULL, NULL
},
{
NULL
},
&num_temp_buffers,
- 1000, 100, INT_MAX / BLCKSZ, NULL, show_num_temp_buffers
+ 1000, 100, INT_MAX / 2, NULL, show_num_temp_buffers
},
{
"temporary disk files.")
},
&work_mem,
- 1024, 8 * BLCKSZ / 1024, INT_MAX / 1024, NULL, NULL
+ 1024, 8 * BLCKSZ / 1024, MAX_KILOBYTES, NULL, NULL
},
{
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
},
{
NULL
},
&max_stack_depth,
- 2048, 100, INT_MAX / 1024, assign_max_stack_depth, NULL
+ 2048, 100, MAX_KILOBYTES, assign_max_stack_depth, NULL
},
{
NULL
},
&max_prepared_xacts,
- 50, 0, 10000, NULL, NULL
+ 50, 0, INT_MAX, NULL, NULL
},
#ifdef LOCK_DEBUG
NULL
},
&XLOGbuffers,
- 8, 4, INT_MAX / BLCKSZ, NULL, NULL
+ 8, 4, INT_MAX, NULL, NULL
},
{
#shared_buffers = 1000 # min 16 or max_connections*2, 8KB each
#temp_buffers = 1000 # min 100, 8KB each
-#max_prepared_transactions = 50 # 0-10000
+#max_prepared_transactions = 50 # can be 0 or more
#work_mem = 1024 # min 64, size in KB
#maintenance_work_mem = 16384 # min 1024, size in KB
#max_stack_depth = 2048 # min 100, size in KB
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/clog.h,v 1.13 2005/06/06 17:01:24 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/clog.h,v 1.14 2005/08/20 23:26:29 tgl Exp $
*/
#ifndef CLOG_H
#define CLOG_H
extern void TransactionIdSetStatus(TransactionId xid, XidStatus status);
extern XidStatus TransactionIdGetStatus(TransactionId xid);
-extern int CLOGShmemSize(void);
+extern Size CLOGShmemSize(void);
extern void CLOGShmemInit(void);
extern void BootStrapCLOG(void);
extern void StartupCLOG(void);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/multixact.h,v 1.5 2005/08/20 01:29:16 ishii Exp $
+ * $PostgreSQL: pgsql/src/include/access/multixact.h,v 1.6 2005/08/20 23:26:29 tgl Exp $
*/
#ifndef MULTIXACT_H
#define MULTIXACT_H
extern void AtEOXact_MultiXact(void);
-extern int MultiXactShmemSize(void);
+extern Size MultiXactShmemSize(void);
extern void MultiXactShmemInit(void);
extern void BootStrapMultiXact(void);
extern void StartupMultiXact(void);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.12 2005/07/04 04:51:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.13 2005/08/20 23:26:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
typedef struct SlruFlushData *SlruFlush;
-extern int SimpleLruShmemSize(void);
+extern Size SimpleLruShmemSize(void);
extern void SimpleLruInit(SlruCtl ctl, const char *name,
LWLockId ctllock, const char *subdir);
extern int SimpleLruZeroPage(SlruCtl ctl, int pageno);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/subtrans.h,v 1.6 2005/06/17 22:32:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/subtrans.h,v 1.7 2005/08/20 23:26:29 tgl Exp $
*/
#ifndef SUBTRANS_H
#define SUBTRANS_H
extern TransactionId SubTransGetParent(TransactionId xid);
extern TransactionId SubTransGetTopmostTransaction(TransactionId xid);
-extern int SUBTRANSShmemSize(void);
+extern Size SUBTRANSShmemSize(void);
extern void SUBTRANSShmemInit(void);
extern void BootStrapSUBTRANS(void);
extern void StartupSUBTRANS(TransactionId oldestActiveXID);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/twophase.h,v 1.4 2005/06/28 05:09:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/twophase.h,v 1.5 2005/08/20 23:26:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* GUC variable */
extern int max_prepared_xacts;
-extern int TwoPhaseShmemSize(void);
+extern Size TwoPhaseShmemSize(void);
extern void TwoPhaseShmemInit(void);
extern PGPROC *TwoPhaseGetDummyProc(TransactionId xid);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.67 2005/07/29 19:30:08 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.68 2005/08/20 23:26:29 tgl Exp $
*/
#ifndef XLOG_H
#define XLOG_H
extern void xlog_desc(char *buf, uint8 xl_info, char *rec);
extern void UpdateControlFile(void);
-extern int XLOGShmemSize(void);
+extern Size XLOGShmemSize(void);
extern void XLOGShmemInit(void);
extern void BootStrapXLOG(void);
extern void StartupXLOG(void);
your system. */
#undef PTHREAD_CREATE_JOINABLE
+/* The size of a `size_t', as computed by sizeof. */
+#undef SIZEOF_SIZE_T
+
/* The size of a `unsigned long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/include/postmaster/bgwriter.h,v 1.6 2005/06/30 00:00:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/postmaster/bgwriter.h,v 1.7 2005/08/20 23:26:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern bool ForwardFsyncRequest(RelFileNode rnode, BlockNumber segno);
extern void AbsorbFsyncRequests(void);
-extern int BgWriterShmemSize(void);
+extern Size BgWriterShmemSize(void);
extern void BgWriterShmemInit(void);
#endif /* _BGWRITER_H */
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.10 2005/05/15 00:26:19 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.11 2005/08/20 23:26:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern pid_t postmaster_forkexec(int argc, char *argv[]);
extern int SubPostmasterMain(int argc, char *argv[]);
-extern size_t ShmemBackendArraySize(void);
+extern Size ShmemBackendArraySize(void);
extern void ShmemBackendArrayAllocation(void);
#endif
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.78 2005/05/19 21:35:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.79 2005/08/20 23:26:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern BufferDesc *StrategyGetBuffer(void);
extern void StrategyFreeBuffer(BufferDesc *buf, bool at_head);
extern int StrategySyncStart(void);
-extern int StrategyShmemSize(void);
+extern Size StrategyShmemSize(void);
extern void StrategyInitialize(bool init);
/* buf_table.c */
-extern int BufTableShmemSize(int size);
+extern Size BufTableShmemSize(int size);
extern void InitBufTable(int size);
extern int BufTableLookup(BufferTag *tagPtr);
extern int BufTableInsert(BufferTag *tagPtr, int buf_id);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.95 2005/08/12 05:05:51 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.96 2005/08/20 23:26:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifdef NOT_USED
extern void PrintPinnedBufs(void);
#endif
-extern int BufferShmemSize(void);
+extern Size BufferShmemSize(void);
extern RelFileNode BufferGetFileNode(Buffer buffer);
extern void SetBufferCommitInfoNeedsSave(Buffer buffer);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.17 2004/12/31 22:03:42 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.18 2005/08/20 23:26:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* function prototypes
*/
extern void InitFreeSpaceMap(void);
-extern int FreeSpaceShmemSize(void);
+extern Size FreeSpaceShmemSize(void);
extern BlockNumber GetPageWithFreeSpace(RelFileNode *rel, Size spaceNeeded);
extern BlockNumber RecordAndGetPageWithFreeSpace(RelFileNode *rel,
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.89 2005/06/17 22:32:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/lock.h,v 1.90 2005/08/20 23:26:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode);
extern void GrantAwaitedLock(void);
extern void RemoveFromWaitQueue(PGPROC *proc);
-extern int LockShmemSize(void);
+extern Size LockShmemSize(void);
extern bool DeadLockCheck(PGPROC *proc);
extern void DeadLockReport(void);
extern void RememberSimpleDeadLock(PGPROC *proc1,
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.21 2005/07/27 08:05:36 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/storage/lwlock.h,v 1.22 2005/08/20 23:26:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern bool LWLockHeldByMe(LWLockId lockid);
extern int NumLWLocks(void);
-extern int LWLockShmemSize(void);
+extern Size LWLockShmemSize(void);
extern void CreateLWLocks(void);
#endif /* LWLOCK_H */
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.14 2004/12/31 22:03:42 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.15 2005/08/20 23:26:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int32 magic; /* magic # to identify Postgres segments */
#define PGShmemMagic 679834893
pid_t creatorPID; /* PID of creating process */
- uint32 totalsize; /* total size of segment */
- uint32 freeoffset; /* offset to first free space */
+ Size totalsize; /* total size of segment */
+ Size freeoffset; /* offset to first free space */
#ifndef WIN32 /* Windows doesn't have useful inode#s */
dev_t device; /* device data directory is on */
ino_t inode; /* inode number of data directory */
extern void PGSharedMemoryReAttach(void);
#endif
-extern PGShmemHeader *PGSharedMemoryCreate(uint32 size, bool makePrivate,
- int port);
+extern PGShmemHeader *PGSharedMemoryCreate(Size size, bool makePrivate,
+ int port);
extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);
extern void PGSharedMemoryDetach(void);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.80 2005/07/31 17:19:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.81 2005/08/20 23:26:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Function Prototypes
*/
extern int ProcGlobalSemas(void);
-extern int ProcGlobalShmemSize(void);
+extern Size ProcGlobalShmemSize(void);
extern void InitProcGlobal(void);
extern void InitProcess(void);
extern void InitDummyProcess(int proctype);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.4 2005/08/20 01:26:29 ishii Exp $
+ * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.5 2005/08/20 23:26:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "storage/lock.h"
-extern int ProcArrayShmemSize(void);
+extern Size ProcArrayShmemSize(void);
extern void CreateSharedProcArray(void);
extern void ProcArrayAdd(PGPROC *proc);
extern void ProcArrayRemove(PGPROC *proc);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.44 2004/12/31 22:03:42 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/storage/shmem.h,v 1.45 2005/08/20 23:26:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern HTAB *ShmemInitHash(const char *name, long init_size, long max_size,
HASHCTL *infoP, int hash_flags);
extern void *ShmemInitStruct(const char *name, Size size, bool *foundPtr);
-
+extern Size add_size(Size s1, Size s2);
+extern Size mul_size(Size s1, Size s2);
/* size constants for the shmem index table */
/* max size of data structure string name */
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/sinval.h,v 1.41 2005/05/19 21:35:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/sinval.h,v 1.42 2005/08/20 23:26:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
} SharedInvalidationMessage;
-extern int SInvalShmemSize(int maxBackends);
-extern void CreateSharedInvalidationState(int maxBackends);
+extern Size SInvalShmemSize(void);
+extern void CreateSharedInvalidationState(void);
extern void InitBackendSharedInvalidationState(void);
extern void SendSharedInvalidMessage(SharedInvalidationMessage *msg);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/sinvaladt.h,v 1.38 2005/05/19 21:35:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/storage/sinvaladt.h,v 1.39 2005/08/20 23:26:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* prototypes for functions in sinvaladt.c
*/
-extern void SIBufferInit(int maxBackends);
+extern void SIBufferInit(void);
extern int SIBackendInit(SISeg *segP);
extern bool SIInsertDataEntry(SISeg *segP, SharedInvalidationMessage *data);
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.39 2005/06/26 23:32:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.40 2005/08/20 23:26:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool *foundPtr);
extern void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp);
extern void *hash_seq_search(HASH_SEQ_STATUS *status);
-extern long hash_estimate_size(long num_entries, Size entrysize);
+extern Size hash_estimate_size(long num_entries, Size entrysize);
extern long hash_select_dirsize(long num_entries);
/*