@@ -90,12 +90,18 @@ intsync_method = DEFAULT_SYNC_METHOD;
90
90
int wal_level = WAL_LEVEL_MINIMAL ;
91
91
int CommitDelay = 0 ;/* precommit delay in microseconds */
92
92
int CommitSiblings = 5 ;/* # concurrent xacts needed to sleep */
93
- int num_xloginsert_locks = 8 ;
94
93
95
94
#ifdef WAL_DEBUG
96
95
bool XLOG_DEBUG = false;
97
96
#endif
98
97
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
+
99
105
/*
100
106
* XLOGfileslop is the maximum number of preallocated future XLOG segments.
101
107
* When we are done with an old XLOG segment file, we will recycle it as a
@@ -1089,9 +1095,9 @@ begin:;
1089
1095
* inserter acquires an insertion lock. In addition to just indicating that
1090
1096
* an insertion is in progress, the lock tells others how far the inserter
1091
1097
* 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.
1095
1101
*
1096
1102
* Holding onto an insertion lock also protects RedoRecPtr and
1097
1103
* fullPageWrites from changing until the insertion is finished.
@@ -1572,7 +1578,7 @@ WALInsertLockAcquire(void)
1572
1578
static int lockToTry = -1 ;
1573
1579
1574
1580
if (lockToTry == -1 )
1575
- lockToTry = MyProc -> pgprocno %num_xloginsert_locks ;
1581
+ lockToTry = MyProc -> pgprocno %NUM_XLOGINSERT_LOCKS ;
1576
1582
MyLockNo = lockToTry ;
1577
1583
1578
1584
/*
@@ -1592,7 +1598,7 @@ WALInsertLockAcquire(void)
1592
1598
* than locks, it still helps to distribute the inserters evenly
1593
1599
* across the locks.
1594
1600
*/
1595
- lockToTry = (lockToTry + 1 ) %num_xloginsert_locks ;
1601
+ lockToTry = (lockToTry + 1 ) %NUM_XLOGINSERT_LOCKS ;
1596
1602
}
1597
1603
}
1598
1604
@@ -1611,7 +1617,7 @@ WALInsertLockAcquireExclusive(void)
1611
1617
* than any real XLogRecPtr value, to make sure that no-one blocks waiting
1612
1618
* on those.
1613
1619
*/
1614
- for (i = 0 ;i < num_xloginsert_locks - 1 ;i ++ )
1620
+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS - 1 ;i ++ )
1615
1621
{
1616
1622
LWLockAcquireWithVar (& WALInsertLocks [i ].l .lock ,
1617
1623
& WALInsertLocks [i ].l .insertingAt ,
@@ -1634,7 +1640,7 @@ WALInsertLockRelease(void)
1634
1640
{
1635
1641
int i ;
1636
1642
1637
- for (i = 0 ;i < num_xloginsert_locks ;i ++ )
1643
+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS ;i ++ )
1638
1644
LWLockRelease (& WALInsertLocks [i ].l .lock );
1639
1645
1640
1646
holdingAllLocks = false;
@@ -1658,8 +1664,8 @@ WALInsertLockUpdateInsertingAt(XLogRecPtr insertingAt)
1658
1664
* We use the last lock to mark our actual position, see comments in
1659
1665
* WALInsertLockAcquireExclusive.
1660
1666
*/
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 ,
1663
1669
insertingAt );
1664
1670
}
1665
1671
else
@@ -1726,7 +1732,7 @@ WaitXLogInsertionsToFinish(XLogRecPtr upto)
1726
1732
* out for any insertion that's still in progress.
1727
1733
*/
1728
1734
finishedUpto = reservedUpto ;
1729
- for (i = 0 ;i < num_xloginsert_locks ;i ++ )
1735
+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS ;i ++ )
1730
1736
{
1731
1737
XLogRecPtr insertingat = InvalidXLogRecPtr ;
1732
1738
@@ -4781,7 +4787,7 @@ XLOGShmemSize(void)
4781
4787
size = sizeof (XLogCtlData );
4782
4788
4783
4789
/* 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 ));
4785
4791
/* xlblocks array */
4786
4792
size = add_size (size ,mul_size (sizeof (XLogRecPtr ),XLOGbuffers ));
4787
4793
/* extra alignment padding for XLOG I/O buffers */
@@ -4840,7 +4846,7 @@ XLOGShmemInit(void)
4840
4846
((uintptr_t )allocptr ) %sizeof (WALInsertLockPadded );
4841
4847
WALInsertLocks = XLogCtl -> Insert .WALInsertLocks =
4842
4848
(WALInsertLockPadded * )allocptr ;
4843
- allocptr += sizeof (WALInsertLockPadded )* num_xloginsert_locks ;
4849
+ allocptr += sizeof (WALInsertLockPadded )* NUM_XLOGINSERT_LOCKS ;
4844
4850
4845
4851
XLogCtl -> Insert .WALInsertLockTrancheId = LWLockNewTrancheId ();
4846
4852
@@ -4849,7 +4855,7 @@ XLOGShmemInit(void)
4849
4855
XLogCtl -> Insert .WALInsertLockTranche .array_stride = sizeof (WALInsertLockPadded );
4850
4856
4851
4857
LWLockRegisterTranche (XLogCtl -> Insert .WALInsertLockTrancheId ,& XLogCtl -> Insert .WALInsertLockTranche );
4852
- for (i = 0 ;i < num_xloginsert_locks ;i ++ )
4858
+ for (i = 0 ;i < NUM_XLOGINSERT_LOCKS ;i ++ )
4853
4859
{
4854
4860
LWLockInitialize (& WALInsertLocks [i ].l .lock ,
4855
4861
XLogCtl -> Insert .WALInsertLockTrancheId );