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

Commit375d852

Browse files
committed
Keep heavily-contended fields in XLogCtlInsert on different cache lines.
Performance testing shows that if the insertpos_lck spinlock and the fieldsthat it protects are on the same cache line with other variables that arefrequently accessed, the false sharing can hurt performance a lot. Keepthem apart by adding some padding.
1 parentcc52d5b commit375d852

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ typedef struct
408408
typedefunionXLogInsertSlotPadded
409409
{
410410
XLogInsertSlotslot;
411-
charpad[64];
411+
charpad[CACHE_LINE_SIZE];
412412
}XLogInsertSlotPadded;
413413

414414
/*
@@ -428,8 +428,14 @@ typedef struct XLogCtlInsert
428428
uint64CurrBytePos;
429429
uint64PrevBytePos;
430430

431-
/* insertion slots, see above for details */
432-
XLogInsertSlotPadded*insertSlots;
431+
/*
432+
* Make sure the above heavily-contended spinlock and byte positions are
433+
* on their own cache line. In particular, the RedoRecPtr and full page
434+
* write variables below should be on a different cache line. They are
435+
* read on every WAL insertion, but updated rarely, and we don't want
436+
* those reads to steal the cache line containing Curr/PrevBytePos.
437+
*/
438+
charpad[CACHE_LINE_SIZE];
433439

434440
/*
435441
* fullPageWrites is the master copy used by all backends to determine
@@ -455,6 +461,9 @@ typedef struct XLogCtlInsert
455461
boolexclusiveBackup;
456462
intnonExclusiveBackups;
457463
XLogRecPtrlastBackupStart;
464+
465+
/* insertion slots, see XLogInsertSlot struct above for details */
466+
XLogInsertSlotPadded*insertSlots;
458467
}XLogCtlInsert;
459468

460469
/*

‎src/include/pg_config_manual.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@
199199
#defineUSE_PPC_LWSYNC
200200
#endif
201201

202+
/*
203+
* Assumed cache line size. This doesn't affect correctness, but can be
204+
* used for low-level optimizations. Currently, this is only used to pad
205+
* some data structures in xlog.c, to ensure that highly-contended fields
206+
* are on different cache lines. Too small a value can hurt performance due
207+
* to false sharing, while the only downside of too large a value is a few
208+
* bytes of wasted memory. The default is 128, which should be large enough
209+
* for all supported platforms.
210+
*/
211+
#defineCACHE_LINE_SIZE128
212+
202213
/*
203214
*------------------------------------------------------------------------
204215
* The following symbols are for enabling debugging code, not for

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp