diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-01-30 16:40:58 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-01-30 16:53:48 +0200 |
commit | 9b38d46d9f5517dab67dda1dd0459683fc9cda9f (patch) | |
tree | f305cd2fc3d24b8ac487a45583946d4ec709bd13 /src/include/storage/lwlock.h | |
parent | ba1868ba3138b2119f8290969b9a3936fbc297ce (diff) | |
download | postgresql-9b38d46d9f5517dab67dda1dd0459683fc9cda9f.tar.gz postgresql-9b38d46d9f5517dab67dda1dd0459683fc9cda9f.zip |
Make group commit more effective.
When a backend needs to flush the WAL, and someone else is already flushing
the WAL, wait until it releases the WALInsertLock and check if we still need
to do the flush or if the other backend already did the work for us, before
acquiring WALInsertLock. This helps group commit, because when the WAL flush
finishes, all the backends that were waiting for it can be woken up in one
go, and the can all concurrently observe that they're done, rather than
waking them up one by one in a cascading fashion.
This is based on a new LWLock function, LWLockWaitUntilFree(), which has
peculiar semantics. If the lock is immediately free, it grabs the lock and
returns true. If it's not free, it waits until it is released, but then
returns false without grabbing the lock. This is used in XLogFlush(), so
that when the lock is acquired, the backend flushes the WAL, but if it's
not, the backend first checks the current flush location before retrying.
Original patch and benchmarking by Peter Geoghegan and Simon Riggs, although
this patch as committed ended up being very different from that.
Diffstat (limited to 'src/include/storage/lwlock.h')
-rw-r--r-- | src/include/storage/lwlock.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index df3df298ae9..c684964a34f 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -94,7 +94,10 @@ typedef enum LWLockId typedef enum LWLockMode { LW_EXCLUSIVE, - LW_SHARED + LW_SHARED, + LW_WAIT_UNTIL_FREE /* A special mode used in PGPROC->lwlockMode, when + * waiting for lock to become free. Not to be used + * as LWLockAcquire argument */ } LWLockMode; @@ -105,6 +108,7 @@ extern bool Trace_lwlocks; extern LWLockId LWLockAssign(void); extern void LWLockAcquire(LWLockId lockid, LWLockMode mode); extern bool LWLockConditionalAcquire(LWLockId lockid, LWLockMode mode); +extern bool LWLockWaitUntilFree(LWLockId lockid, LWLockMode mode); extern void LWLockRelease(LWLockId lockid); extern void LWLockReleaseAll(void); extern bool LWLockHeldByMe(LWLockId lockid); |