aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/transam')
-rw-r--r--src/backend/access/transam/clog.c5
-rw-r--r--src/backend/access/transam/multixact.c15
-rw-r--r--src/backend/access/transam/slru.c5
-rw-r--r--src/backend/access/transam/subtrans.c5
-rw-r--r--src/backend/access/transam/twophase.c17
-rw-r--r--src/backend/access/transam/xlog.c96
6 files changed, 72 insertions, 71 deletions
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index 3768570ad3d..4a2e1f55927 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -24,7 +24,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -144,8 +144,7 @@ TransactionIdGetStatus(TransactionId xid)
/*
* Initialization of shared memory for CLOG
*/
-
-int
+Size
CLOGShmemSize(void)
{
return SimpleLruShmemSize();
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index d264d8ad57c..1adaebb6d80 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -42,7 +42,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -1159,13 +1159,20 @@ AtEOXact_MultiXact(void)
* 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
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index c7c12470209..67d9d3f54f3 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -48,7 +48,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -141,9 +141,10 @@ static int SlruSelectLRUPage(SlruCtl ctl, int pageno);
* 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;
}
diff --git a/src/backend/access/transam/subtrans.c b/src/backend/access/transam/subtrans.c
index cea778d6a1c..9b450350360 100644
--- a/src/backend/access/transam/subtrans.c
+++ b/src/backend/access/transam/subtrans.c
@@ -22,7 +22,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -161,8 +161,7 @@ SubTransGetTopmostTransaction(TransactionId xid)
/*
* Initialization of shared memory for SUBTRANS
*/
-
-int
+Size
SUBTRANSShmemSize(void)
{
return SimpleLruShmemSize();
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 62ebf9fb406..f65904f0376 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -7,7 +7,7 @@
* 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
@@ -152,13 +152,20 @@ static void ProcessRecords(char *bufptr, TransactionId xid,
/*
* 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
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index ae57ec0231a..a917616cffd 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -91,31 +91,6 @@
#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
@@ -135,6 +110,17 @@
#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"
@@ -173,8 +159,6 @@ static int open_sync_bit = DEFAULT_SYNC_FLAGBIT;
#define XLOG_SYNC_BIT (enableFsync ? open_sync_bit : 0)
-#define MinXLOGbuffers 4
-
/*
* ThisTimeLineID will be same in all backends --- it identifies current
@@ -3615,16 +3599,27 @@ UpdateControlFile(void)
/*
* 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
@@ -3632,17 +3627,10 @@ XLOGShmemInit(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);
@@ -3660,17 +3648,16 @@ XLOGShmemInit(void)
* 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);
/*
@@ -3728,8 +3715,9 @@ BootStrapXLOG(void)
/* 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 */
@@ -3824,7 +3812,7 @@ BootStrapXLOG(void)
BootStrapSUBTRANS();
BootStrapMultiXact();
- free(buffer);
+ pfree(buffer);
}
static char *