diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2011-11-13 09:00:57 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2011-11-13 09:00:57 +0000 |
commit | 4de82f7d7c50a81ec8e70e2cb0ab413ab9134c0b (patch) | |
tree | 7ee129540269debbdf22771e1e99244445213e6a /src/backend/access/transam/xlog.c | |
parent | 02d88efea1f719e59ce684c2e14bad23d55fdd15 (diff) | |
download | postgresql-4de82f7d7c50a81ec8e70e2cb0ab413ab9134c0b.tar.gz postgresql-4de82f7d7c50a81ec8e70e2cb0ab413ab9134c0b.zip |
Wakeup WALWriter as needed for asynchronous commit performance.
Previously we waited for wal_writer_delay before flushing WAL. Now
we also wake WALWriter as soon as a WAL buffer page has filled.
Significant effect observed on performance of asynchronous commits
by Robert Haas, attributed to the ability to set hint bits on tuples
earlier and so reducing contention caused by clog lookups.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 0d494e2e3bf..20c04240b70 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -433,6 +433,11 @@ typedef struct XLogCtlData Latch recoveryWakeupLatch; /* + * WALWriterLatch is used to wake up the WALWriter to write some WAL. + */ + Latch WALWriterLatch; + + /* * During recovery, we keep a copy of the latest checkpoint record here. * Used by the background writer when it wants to create a restartpoint. * @@ -1916,19 +1921,35 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch) } /* - * Record the LSN for an asynchronous transaction commit/abort. + * Record the LSN for an asynchronous transaction commit/abort + * and nudge the WALWriter if there is a complete page to write. * (This should not be called for for synchronous commits.) */ void XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN) { + XLogRecPtr WriteRqstPtr = asyncXactLSN; + /* use volatile pointer to prevent code rearrangement */ volatile XLogCtlData *xlogctl = XLogCtl; SpinLockAcquire(&xlogctl->info_lck); + LogwrtResult = xlogctl->LogwrtResult; if (XLByteLT(xlogctl->asyncXactLSN, asyncXactLSN)) xlogctl->asyncXactLSN = asyncXactLSN; SpinLockRelease(&xlogctl->info_lck); + + /* back off to last completed page boundary */ + WriteRqstPtr.xrecoff -= WriteRqstPtr.xrecoff % XLOG_BLCKSZ; + + /* if we have already flushed that far, we're done */ + if (XLByteLE(WriteRqstPtr, LogwrtResult.Flush)) + return; + + /* + * Nudge the WALWriter if we have a full page of WAL to write. + */ + SetLatch(&XLogCtl->WALWriterLatch); } /* @@ -5072,6 +5093,7 @@ XLOGShmemInit(void) XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages); SpinLockInit(&XLogCtl->info_lck); InitSharedLatch(&XLogCtl->recoveryWakeupLatch); + InitSharedLatch(&XLogCtl->WALWriterLatch); /* * If we are not in bootstrap mode, pg_control should already exist. Read @@ -10013,3 +10035,12 @@ WakeupRecovery(void) { SetLatch(&XLogCtl->recoveryWakeupLatch); } + +/* + * Manage the WALWriterLatch + */ +Latch * +WALWriterLatch(void) +{ + return &XLogCtl->WALWriterLatch; +} |