wip: xlog: async commit: reduce frequency of latch sets.
authorAndres Freund <[email protected]>
Thu, 31 Dec 2020 04:21:49 +0000 (20:21 -0800)
committerAndres Freund <[email protected]>
Mon, 11 Jan 2021 23:09:15 +0000 (15:09 -0800)
Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

src/backend/access/transam/xlog.c

index dec645c4169d338e8aba96a2bc8dc1c4212d47d6..37b0cf32a46ac909802ec401fc6c8be012312b80 100644 (file)
@@ -698,6 +698,7 @@ typedef struct XLogCtlData
    XLogRecPtr  RedoRecPtr;     /* a recent copy of Insert->RedoRecPtr */
    FullTransactionId ckptFullXid;  /* nextXid of latest checkpoint */
    XLogRecPtr  asyncXactLSN;   /* LSN of newest async commit/abort */
+   XLogRecPtr  asyncXactNotifiedLSN;   /*  */
    XLogRecPtr  replicationSlotMinLSN;  /* oldest LSN needed by any slot */
 
    XLogSegNo   lastRemovedSegNo;   /* latest removed/recycled XLOG segment */
@@ -3896,6 +3897,7 @@ void
 XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
 {
    XLogRecPtr  WriteRqstPtr = asyncXactLSN;
+   XLogRecPtr  LastNotifiedLSN;
    bool        sleeping;
 
    SpinLockAcquire(&XLogCtl->info_lck);
@@ -3903,6 +3905,7 @@ XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
    sleeping = XLogCtl->WalWriterSleeping;
    if (XLogCtl->asyncXactLSN < asyncXactLSN)
        XLogCtl->asyncXactLSN = asyncXactLSN;
+   LastNotifiedLSN = XLogCtl->asyncXactNotifiedLSN;
    SpinLockRelease(&XLogCtl->info_lck);
 
    /*
@@ -3916,8 +3919,24 @@ XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
        WriteRqstPtr -= WriteRqstPtr % XLOG_BLCKSZ;
 
        /* if we have already flushed that far, we're done */
-       if (WriteRqstPtr <= LogwrtResult.FlushDone)
+       if (WriteRqstPtr <= LogwrtResult.FlushInit)
            return;
+
+       if (WriteRqstPtr <= LogwrtResult.FlushInit + WalWriterFlushAfter * XLOG_BLCKSZ)
+           return;
+
+       if (WriteRqstPtr <= LastNotifiedLSN)
+           return;
+#if 1
+       SpinLockAcquire(&XLogCtl->info_lck);
+       LastNotifiedLSN = XLogCtl->asyncXactNotifiedLSN;
+       if (LastNotifiedLSN < WriteRqstPtr)
+           XLogCtl->asyncXactNotifiedLSN = WriteRqstPtr;
+       SpinLockRelease(&XLogCtl->info_lck);
+
+       if (WriteRqstPtr <= LastNotifiedLSN)
+           return;
+#endif
    }
 
    /*