@@ -90,12 +90,18 @@ intsync_method = DEFAULT_SYNC_METHOD;
9090int wal_level = WAL_LEVEL_MINIMAL ;
9191int CommitDelay = 0 ;/* precommit delay in microseconds */
9292int CommitSiblings = 5 ;/* # concurrent xacts needed to sleep */
93- int num_xloginsert_locks = 8 ;
9493
9594#ifdef WAL_DEBUG
9695bool XLOG_DEBUG = false;
9796#endif
9897
98+ /*
99+ * Number of WAL insertion locks to use. A higher value allows more insertions
100+ * to happen concurrently, but adds some CPU overhead to flushing the WAL,
101+ * which needs to iterate all the locks.
102+ */
103+ #define NUM_XLOGINSERT_LOCKS 8
104+
99105/*
100106 * XLOGfileslop is the maximum number of preallocated future XLOG segments.
101107 * When we are done with an old XLOG segment file, we will recycle it as a
@@ -1089,9 +1095,9 @@ begin:;
10891095 * inserter acquires an insertion lock. In addition to just indicating that
10901096 * an insertion is in progress, the lock tells others how far the inserter
10911097 * has progressed. There is a small fixed number of insertion locks,
1092- * determined bythe num_xloginsert_locks GUC . When an inserter crosses a
1093- *page boundary, it updates the value stored in the lock to the how far it
1094- *has inserted, to allow the previous buffer to be flushed.
1098+ * determined byNUM_XLOGINSERT_LOCKS . When an inserter crosses a page
1099+ * boundary, it updates the value stored in the lock to the how far it has
1100+ * inserted, to allow the previous buffer to be flushed.
10951101 *
10961102 * Holding onto an insertion lock also protects RedoRecPtr and
10971103 * fullPageWrites from changing until the insertion is finished.
@@ -1572,7 +1578,7 @@ WALInsertLockAcquire(void)
15721578static int lockToTry = -1 ;
15731579
15741580if (lockToTry == -1 )
1575- lockToTry = MyProc -> pgprocno %num_xloginsert_locks ;
1581+ lockToTry = MyProc -> pgprocno %NUM_XLOGINSERT_LOCKS ;
15761582MyLockNo = lockToTry ;
15771583
15781584/*
@@ -1592,7 +1598,7 @@ WALInsertLockAcquire(void)
15921598 * than locks, it still helps to distribute the inserters evenly
15931599 * across the locks.
15941600 */
1595- lockToTry = (lockToTry + 1 ) %num_xloginsert_locks ;
1601+ lockToTry = (lockToTry + 1 ) %NUM_XLOGINSERT_LOCKS ;
15961602}
15971603}
15981604
@@ -1611,7 +1617,7 @@ WALInsertLockAcquireExclusive(void)
16111617 * than any real XLogRecPtr value, to make sure that no-one blocks waiting
16121618 * on those.
16131619 */
1614- for (i = 0 ;i < num_xloginsert_locks - 1 ;i ++ )
1620+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS - 1 ;i ++ )
16151621{
16161622LWLockAcquireWithVar (& WALInsertLocks [i ].l .lock ,
16171623& WALInsertLocks [i ].l .insertingAt ,
@@ -1634,7 +1640,7 @@ WALInsertLockRelease(void)
16341640{
16351641int i ;
16361642
1637- for (i = 0 ;i < num_xloginsert_locks ;i ++ )
1643+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS ;i ++ )
16381644LWLockRelease (& WALInsertLocks [i ].l .lock );
16391645
16401646holdingAllLocks = false;
@@ -1658,8 +1664,8 @@ WALInsertLockUpdateInsertingAt(XLogRecPtr insertingAt)
16581664 * We use the last lock to mark our actual position, see comments in
16591665 * WALInsertLockAcquireExclusive.
16601666 */
1661- LWLockUpdateVar (& WALInsertLocks [num_xloginsert_locks - 1 ].l .lock ,
1662- & WALInsertLocks [num_xloginsert_locks - 1 ].l .insertingAt ,
1667+ LWLockUpdateVar (& WALInsertLocks [NUM_XLOGINSERT_LOCKS - 1 ].l .lock ,
1668+ & WALInsertLocks [NUM_XLOGINSERT_LOCKS - 1 ].l .insertingAt ,
16631669insertingAt );
16641670}
16651671else
@@ -1726,7 +1732,7 @@ WaitXLogInsertionsToFinish(XLogRecPtr upto)
17261732 * out for any insertion that's still in progress.
17271733 */
17281734finishedUpto = reservedUpto ;
1729- for (i = 0 ;i < num_xloginsert_locks ;i ++ )
1735+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS ;i ++ )
17301736{
17311737XLogRecPtr insertingat = InvalidXLogRecPtr ;
17321738
@@ -4781,7 +4787,7 @@ XLOGShmemSize(void)
47814787size = sizeof (XLogCtlData );
47824788
47834789/* WAL insertion locks, plus alignment */
4784- size = add_size (size ,mul_size (sizeof (WALInsertLockPadded ),num_xloginsert_locks + 1 ));
4790+ size = add_size (size ,mul_size (sizeof (WALInsertLockPadded ),NUM_XLOGINSERT_LOCKS + 1 ));
47854791/* xlblocks array */
47864792size = add_size (size ,mul_size (sizeof (XLogRecPtr ),XLOGbuffers ));
47874793/* extra alignment padding for XLOG I/O buffers */
@@ -4840,7 +4846,7 @@ XLOGShmemInit(void)
48404846((uintptr_t )allocptr ) %sizeof (WALInsertLockPadded );
48414847WALInsertLocks = XLogCtl -> Insert .WALInsertLocks =
48424848(WALInsertLockPadded * )allocptr ;
4843- allocptr += sizeof (WALInsertLockPadded )* num_xloginsert_locks ;
4849+ allocptr += sizeof (WALInsertLockPadded )* NUM_XLOGINSERT_LOCKS ;
48444850
48454851XLogCtl -> Insert .WALInsertLockTrancheId = LWLockNewTrancheId ();
48464852
@@ -4849,7 +4855,7 @@ XLOGShmemInit(void)
48494855XLogCtl -> Insert .WALInsertLockTranche .array_stride = sizeof (WALInsertLockPadded );
48504856
48514857LWLockRegisterTranche (XLogCtl -> Insert .WALInsertLockTrancheId ,& XLogCtl -> Insert .WALInsertLockTranche );
4852- for (i = 0 ;i < num_xloginsert_locks ;i ++ )
4858+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS ;i ++ )
48534859{
48544860LWLockInitialize (& WALInsertLocks [i ].l .lock ,
48554861XLogCtl -> Insert .WALInsertLockTrancheId );