@@ -91,12 +91,18 @@ int sync_method = DEFAULT_SYNC_METHOD;
9191int wal_level = WAL_LEVEL_MINIMAL ;
9292int CommitDelay = 0 ; /* precommit delay in microseconds */
9393int CommitSiblings = 5 ; /* # concurrent xacts needed to sleep */
94- int num_xloginsert_locks = 8 ;
9594
9695#ifdef WAL_DEBUG
9796bool XLOG_DEBUG = false;
9897#endif
9998
99+ /*
100+ * Number of WAL insertion locks to use. A higher value allows more insertions
101+ * to happen concurrently, but adds some CPU overhead to flushing the WAL,
102+ * which needs to iterate all the locks.
103+ */
104+ #define NUM_XLOGINSERT_LOCKS 8
105+
100106/*
101107 * XLOGfileslop is the maximum number of preallocated future XLOG segments.
102108 * When we are done with an old XLOG segment file, we will recycle it as a
@@ -1095,9 +1101,9 @@ begin:;
10951101 * inserter acquires an insertion lock. In addition to just indicating that
10961102 * an insertion is in progress, the lock tells others how far the inserter
10971103 * has progressed. There is a small fixed number of insertion locks,
1098- * determined by the num_xloginsert_locks GUC . When an inserter crosses a
1099- * page boundary, it updates the value stored in the lock to the how far it
1100- * has inserted, to allow the previous buffer to be flushed.
1104+ * determined by NUM_XLOGINSERT_LOCKS . When an inserter crosses a page
1105+ * boundary, it updates the value stored in the lock to the how far it has
1106+ * inserted, to allow the previous buffer to be flushed.
11011107 *
11021108 * Holding onto an insertion lock also protects RedoRecPtr and
11031109 * fullPageWrites from changing until the insertion is finished.
@@ -1578,7 +1584,7 @@ WALInsertLockAcquire(void)
15781584 static int lockToTry = -1 ;
15791585
15801586 if (lockToTry == -1 )
1581- lockToTry = MyProc -> pgprocno % num_xloginsert_locks ;
1587+ lockToTry = MyProc -> pgprocno % NUM_XLOGINSERT_LOCKS ;
15821588 MyLockNo = lockToTry ;
15831589
15841590 /*
@@ -1598,7 +1604,7 @@ WALInsertLockAcquire(void)
15981604 * than locks, it still helps to distribute the inserters evenly
15991605 * across the locks.
16001606 */
1601- lockToTry = (lockToTry + 1 ) % num_xloginsert_locks ;
1607+ lockToTry = (lockToTry + 1 ) % NUM_XLOGINSERT_LOCKS ;
16021608 }
16031609}
16041610
@@ -1617,7 +1623,7 @@ WALInsertLockAcquireExclusive(void)
16171623 * than any real XLogRecPtr value, to make sure that no-one blocks waiting
16181624 * on those.
16191625 */
1620- for (i = 0 ; i < num_xloginsert_locks - 1 ; i ++ )
1626+ for (i = 0 ; i < NUM_XLOGINSERT_LOCKS - 1 ; i ++ )
16211627 {
16221628 LWLockAcquireWithVar (& WALInsertLocks [i ].l .lock ,
16231629 & WALInsertLocks [i ].l .insertingAt ,
@@ -1640,7 +1646,7 @@ WALInsertLockRelease(void)
16401646 {
16411647 int i ;
16421648
1643- for (i = 0 ; i < num_xloginsert_locks ; i ++ )
1649+ for (i = 0 ; i < NUM_XLOGINSERT_LOCKS ; i ++ )
16441650 LWLockRelease (& WALInsertLocks [i ].l .lock );
16451651
16461652 holdingAllLocks = false;
@@ -1664,8 +1670,8 @@ WALInsertLockUpdateInsertingAt(XLogRecPtr insertingAt)
16641670 * We use the last lock to mark our actual position, see comments in
16651671 * WALInsertLockAcquireExclusive.
16661672 */
1667- LWLockUpdateVar (& WALInsertLocks [num_xloginsert_locks - 1 ].l .lock ,
1668- & WALInsertLocks [num_xloginsert_locks - 1 ].l .insertingAt ,
1673+ LWLockUpdateVar (& WALInsertLocks [NUM_XLOGINSERT_LOCKS - 1 ].l .lock ,
1674+ & WALInsertLocks [NUM_XLOGINSERT_LOCKS - 1 ].l .insertingAt ,
16691675 insertingAt );
16701676 }
16711677 else
@@ -1732,7 +1738,7 @@ WaitXLogInsertionsToFinish(XLogRecPtr upto)
17321738 * out for any insertion that's still in progress.
17331739 */
17341740 finishedUpto = reservedUpto ;
1735- for (i = 0 ; i < num_xloginsert_locks ; i ++ )
1741+ for (i = 0 ; i < NUM_XLOGINSERT_LOCKS ; i ++ )
17361742 {
17371743 XLogRecPtr insertingat = InvalidXLogRecPtr ;
17381744
@@ -4752,7 +4758,7 @@ XLOGShmemSize(void)
47524758 size = sizeof (XLogCtlData );
47534759
47544760 /* WAL insertion locks, plus alignment */
4755- size = add_size (size , mul_size (sizeof (WALInsertLockPadded ), num_xloginsert_locks + 1 ));
4761+ size = add_size (size , mul_size (sizeof (WALInsertLockPadded ), NUM_XLOGINSERT_LOCKS + 1 ));
47564762 /* xlblocks array */
47574763 size = add_size (size , mul_size (sizeof (XLogRecPtr ), XLOGbuffers ));
47584764 /* extra alignment padding for XLOG I/O buffers */
@@ -4829,7 +4835,7 @@ XLOGShmemInit(void)
48294835 ((uintptr_t ) allocptr ) %sizeof (WALInsertLockPadded );
48304836 WALInsertLocks = XLogCtl -> Insert .WALInsertLocks =
48314837 (WALInsertLockPadded * ) allocptr ;
4832- allocptr += sizeof (WALInsertLockPadded ) * num_xloginsert_locks ;
4838+ allocptr += sizeof (WALInsertLockPadded ) * NUM_XLOGINSERT_LOCKS ;
48334839
48344840 XLogCtl -> Insert .WALInsertLockTrancheId = LWLockNewTrancheId ();
48354841
@@ -4838,7 +4844,7 @@ XLOGShmemInit(void)
48384844 XLogCtl -> Insert .WALInsertLockTranche .array_stride = sizeof (WALInsertLockPadded );
48394845
48404846 LWLockRegisterTranche (XLogCtl -> Insert .WALInsertLockTrancheId , & XLogCtl -> Insert .WALInsertLockTranche );
4841- for (i = 0 ; i < num_xloginsert_locks ; i ++ )
4847+ for (i = 0 ; i < NUM_XLOGINSERT_LOCKS ; i ++ )
48424848 {
48434849 LWLockInitialize (& WALInsertLocks [i ].l .lock ,
48444850 XLogCtl -> Insert .WALInsertLockTrancheId );
0 commit comments