File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -408,7 +408,7 @@ typedef struct
408
408
typedef union XLogInsertSlotPadded
409
409
{
410
410
XLogInsertSlot slot ;
411
- char pad [64 ];
411
+ char pad [CACHE_LINE_SIZE ];
412
412
} XLogInsertSlotPadded ;
413
413
414
414
/*
@@ -428,8 +428,14 @@ typedef struct XLogCtlInsert
428
428
uint64 CurrBytePos ;
429
429
uint64 PrevBytePos ;
430
430
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.
<
106D7
td data-grid-cell-id="diff-c1cb3ab2a19606390c1a7ed00ffe5a45531702ca5faf999d401c548f8951c65b-432-437-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
437
+ */
438
+ char pad [CACHE_LINE_SIZE ];
433
439
434
440
/*
435
441
* fullPageWrites is the master copy used by all backends to determine
@@ -455,6 +461,9 @@ typedef struct XLogCtlInsert
455
461
bool exclusiveBackup ;
456
462
int nonExclusiveBackups ;
457
463
XLogRecPtr lastBackupStart ;
464
+
465
+ /* insertion slots, see XLogInsertSlot struct above for details */
466
+ XLogInsertSlotPadded * insertSlots ;
458
467
} XLogCtlInsert ;
459
468
460
469
/*
Original file line number Diff line number Diff line change 199
199
#define USE_PPC_LWSYNC
200
200
#endif
201
201
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
+ #define CACHE_LINE_SIZE 128
212
+
202
213
/*
203
214
*------------------------------------------------------------------------
204
215
* The following symbols are for enabling debugging code, not for
You can’t perform that action at this time.
0 commit comments