Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6bad580

Browse files
Avoid SnapshotResetXmin() during AtEOXact_Snapshot()
For normal commits and aborts we already reset PgXact->xmin, so we can simply avoid running SnapshotResetXmin() twice. During performance tests by Alexander Korotkov, diagnosis by Andres Freund showed PgXact array as a bottleneck. After manual analysis by me of the code paths that touch those memory locations, I was able to identify extraneous code in the main transaction commit path. Avoiding touching highly contented shmem improves concurrent performance slightly on all workloads, confirmed by tests run by Ashutosh Sharma and Alexander Korotkov. Simon Riggs Discussion: CANP8+jJdXE9b+b9F8CQT-LuxxO0PBCB-SZFfMVAdp+akqo4zfg@mail.gmail.com
1 parent fd01983 commit 6bad580

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/backend/access/transam/xact.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ CommitTransaction(void)
21372137
AtEOXact_ComboCid();
21382138
AtEOXact_HashTables(true);
21392139
AtEOXact_PgStat(true);
2140-
AtEOXact_Snapshot(true);
2140+
AtEOXact_Snapshot(true, false);
21412141
AtCommit_ApplyLauncher();
21422142
pgstat_report_xact_timestamp(0);
21432143

@@ -2409,7 +2409,7 @@ PrepareTransaction(void)
24092409
AtEOXact_ComboCid();
24102410
AtEOXact_HashTables(true);
24112411
/* don't call AtEOXact_PgStat here; we fixed pgstat state above */
2412-
AtEOXact_Snapshot(true);
2412+
AtEOXact_Snapshot(true, true);
24132413
pgstat_report_xact_timestamp(0);
24142414

24152415
CurrentResourceOwner = NULL;
@@ -2640,7 +2640,7 @@ CleanupTransaction(void)
26402640
* do abort cleanup processing
26412641
*/
26422642
AtCleanup_Portals(); /* now safe to release portal memory */
2643-
AtEOXact_Snapshot(false); /* and release the transaction's snapshots */
2643+
AtEOXact_Snapshot(false, false); /* and release the transaction's snapshots */
26442644

26452645
CurrentResourceOwner = NULL; /* and resource owner */
26462646
if (TopTransactionResourceOwner)

src/backend/utils/time/snapmgr.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ AtSubAbort_Snapshot(int level)
10511051
* Snapshot manager's cleanup function for end of transaction
10521052
*/
10531053
void
1054-
AtEOXact_Snapshot(bool isCommit)
1054+
AtEOXact_Snapshot(bool isCommit, bool isPrepare)
10551055
{
10561056
/*
10571057
* In transaction-snapshot mode we must release our privately-managed
@@ -1136,7 +1136,17 @@ AtEOXact_Snapshot(bool isCommit)
11361136

11371137
FirstSnapshotSet = false;
11381138

1139-
SnapshotResetXmin();
1139+
/*
1140+
* During normal commit and abort processing, we call
1141+
* ProcArrayEndTransaction() or ProcArrayClearTransaction() to
1142+
* reset the PgXact->xmin. That call happens prior to the call to
1143+
* AtEOXact_Snapshot(), so we need not touch xmin here at all,
1144+
* accept when we are preparing a transaction.
1145+
*/
1146+
if (isPrepare)
1147+
SnapshotResetXmin();
1148+
1149+
Assert(isPrepare || MyPgXact->xmin == 0);
11401150
}
11411151

11421152

src/include/utils/snapmgr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extern void UnregisterSnapshotFromOwner(Snapshot snapshot, ResourceOwner owner);
8585

8686
extern void AtSubCommit_Snapshot(int level);
8787
extern void AtSubAbort_Snapshot(int level);
88-
extern void AtEOXact_Snapshot(bool isCommit);
88+
extern void AtEOXact_Snapshot(bool isCommit, bool isPrepare);
8989

9090
extern void ImportSnapshot(const char *idstr);
9191
extern bool XactHasExportedSnapshots(void);

0 commit comments

Comments
 (0)