Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit963d307

Browse files
Convert unloggedLSN to an atomic variable.
Currently, this variable is an XLogRecPtr protected by a spinlock.By converting it to an atomic variable, we can remove the spinlock,which saves a small amount of shared memory space. Since this codeis not performance-critical, we use atomic operations with fullbarrier semantics to make it easy to reason about correctness.Author: John MorrisReviewed-by: Michael Paquier, Robert Haas, Andres Freund, Stephen Frost, Bharath RupireddyDiscussion:https://postgr.es/m/BYAPR13MB26772534335255E50318C574A0409%40BYAPR13MB2677.namprd13.prod.outlook.comDiscussion:https://postgr.es/m/MN2PR13MB2688FD8B757316CB5C54C8A2A0DDA%40MN2PR13MB2688.namprd13.prod.outlook.com
1 parent3179701 commit963d307

File tree

1 file changed

+9
-17
lines changed
  • src/backend/access/transam

1 file changed

+9
-17
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,8 @@ typedef struct XLogCtlData
470470

471471
XLogSegNolastRemovedSegNo;/* latest removed/recycled XLOG segment */
472472

473-
/* Fake LSN counter, for unlogged relations. Protected by ulsn_lck. */
474-
XLogRecPtrunloggedLSN;
475-
slock_tulsn_lck;
473+
/* Fake LSN counter, for unlogged relations. */
474+
pg_atomic_uint64unloggedLSN;
476475

477476
/* Time and LSN of last xlog segment switch. Protected by WALWriteLock. */
478477
pg_time_tlastSegSwitchTime;
@@ -4498,14 +4497,7 @@ DataChecksumsEnabled(void)
44984497
XLogRecPtr
44994498
GetFakeLSNForUnloggedRel(void)
45004499
{
4501-
XLogRecPtrnextUnloggedLSN;
4502-
4503-
/* increment the unloggedLSN counter, need SpinLock */
4504-
SpinLockAcquire(&XLogCtl->ulsn_lck);
4505-
nextUnloggedLSN=XLogCtl->unloggedLSN++;
4506-
SpinLockRelease(&XLogCtl->ulsn_lck);
4507-
4508-
returnnextUnloggedLSN;
4500+
returnpg_atomic_fetch_add_u64(&XLogCtl->unloggedLSN,1);
45094501
}
45104502

45114503
/*
@@ -4921,7 +4913,7 @@ XLOGShmemInit(void)
49214913

49224914
SpinLockInit(&XLogCtl->Insert.insertpos_lck);
49234915
SpinLockInit(&XLogCtl->info_lck);
4924-
SpinLockInit(&XLogCtl->ulsn_lck);
4916+
pg_atomic_init_u64(&XLogCtl->unloggedLSN,InvalidXLogRecPtr);
49254917
}
49264918

49274919
/*
@@ -5526,9 +5518,11 @@ StartupXLOG(void)
55265518
* the unlogged LSN counter can be reset too.
55275519
*/
55285520
if (ControlFile->state==DB_SHUTDOWNED)
5529-
XLogCtl->unloggedLSN=ControlFile->unloggedLSN;
5521+
pg_atomic_write_membarrier_u64(&XLogCtl->unloggedLSN,
5522+
ControlFile->unloggedLSN);
55305523
else
5531-
XLogCtl->unloggedLSN=FirstNormalUnloggedLSN;
5524+
pg_atomic_write_membarrier_u64(&XLogCtl->unloggedLSN,
5525+
FirstNormalUnloggedLSN);
55325526

55335527
/*
55345528
* Copy any missing timeline history files between 'now' and the recovery
@@ -7110,9 +7104,7 @@ CreateCheckPoint(int flags)
71107104
* unused on non-shutdown checkpoints, but seems useful to store it always
71117105
* for debugging purposes.
71127106
*/
7113-
SpinLockAcquire(&XLogCtl->ulsn_lck);
7114-
ControlFile->unloggedLSN=XLogCtl->unloggedLSN;
7115-
SpinLockRelease(&XLogCtl->ulsn_lck);
7107+
ControlFile->unloggedLSN=pg_atomic_read_membarrier_u64(&XLogCtl->unloggedLSN);
71167108

71177109
UpdateControlFile();
71187110
LWLockRelease(ControlFileLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp