Skip to content

Commit 5fa6c81

Browse files
committed
Remove num_xloginsert_locks GUC, replace with a #define
I left the GUC in place for the beta period, so that people could experiment with different values. No-one's come up with any data that a different value would be better under some circumstances, so rather than try to document to users what the GUC, let's just hard-code the current value, 8.
1 parent a39e78b commit 5fa6c81

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

src/backend/access/transam/xlog.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ int sync_method = DEFAULT_SYNC_METHOD;
9191
int wal_level = WAL_LEVEL_MINIMAL;
9292
int CommitDelay = 0; /* precommit delay in microseconds */
9393
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
94-
int num_xloginsert_locks = 8;
9594

9695
#ifdef WAL_DEBUG
9796
bool 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);

src/backend/utils/misc/guc.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,17 +2143,6 @@ static struct config_int ConfigureNamesInt[] =
21432143
NULL, NULL, NULL
21442144
},
21452145

2146-
{
2147-
{"xloginsert_locks", PGC_POSTMASTER, WAL_SETTINGS,
2148-
gettext_noop("Sets the number of locks used for concurrent xlog insertions."),
2149-
NULL,
2150-
GUC_NOT_IN_SAMPLE
2151-
},
2152-
&num_xloginsert_locks,
2153-
8, 1, 1000,
2154-
NULL, NULL, NULL
2155-
},
2156-
21572146
{
21582147
/* see max_connections */
21592148
{"max_wal_senders", PGC_POSTMASTER, REPLICATION_SENDING,

src/include/access/xlog.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ extern bool EnableHotStandby;
194194
extern bool fullPageWrites;
195195
extern bool wal_log_hints;
196196
extern bool log_checkpoints;
197-
extern int num_xloginsert_locks;
198197

199198
/* WAL levels */
200199
typedef enum WalLevel

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy