summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2012-05-10 03:36:01 +0000
committerTom Lane2012-05-10 03:37:10 +0000
commit6308ba05a7a24b5137d97508300131ffa42051c2 (patch)
tree819c0ef45e7322380b7992631e3331638e20c782 /src/include
parent668f959dcb7786654943d4726d1af07ad468a5be (diff)
Improve control logic for bgwriter hibernation mode.
Commit 6d90eaaa89a007e0d365f49d6436f35d2392cfeb added a hibernation mode to the bgwriter to reduce the server's idle-power consumption. However, its interaction with the detailed behavior of BgBufferSync's feedback control loop wasn't very well thought out. That control loop depends primarily on the rate of buffer allocation, not the rate of buffer dirtying, so the hibernation mode has to be designed to operate only when no new buffer allocations are happening. Also, the check for whether the system is effectively idle was not quite right and would fail to detect a constant low level of activity, thus allowing the bgwriter to go into hibernation mode in a way that would let the cycle time vary quite a bit, possibly further confusing the feedback loop. To fix, move the wakeup support from MarkBufferDirty and SetBufferCommitInfoNeedsSave into StrategyGetBuffer, and prevent the bgwriter from entering hibernation mode unless no buffer allocations have happened recently. In addition, fix the delaying logic to remove the problem of possibly not responding to signals promptly, which was basically caused by trying to use the process latch's is_set flag for multiple purposes. I can't prove it but I'm suspicious that that hack was responsible for the intermittent "postmaster does not shut down" failures we've been seeing in the buildfarm lately. In any case it did nothing to improve the readability or robustness of the code. In passing, express the hibernation sleep time as a multiplier on BgWriterDelay, not a constant. I'm not sure whether there's any value in exposing the longer sleep time as an independently configurable setting, but we can at least make it act like this for little extra code.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/postmaster/bgwriter.h6
-rw-r--r--src/include/storage/buf_internals.h3
-rw-r--r--src/include/storage/proc.h2
3 files changed, 7 insertions, 4 deletions
diff --git a/src/include/postmaster/bgwriter.h b/src/include/postmaster/bgwriter.h
index 540c4e9cc0..d17dd17487 100644
--- a/src/include/postmaster/bgwriter.h
+++ b/src/include/postmaster/bgwriter.h
@@ -1,7 +1,10 @@
/*-------------------------------------------------------------------------
*
* bgwriter.h
- * Exports from postmaster/bgwriter.c.
+ * Exports from postmaster/bgwriter.c and postmaster/checkpointer.c.
+ *
+ * The bgwriter process used to handle checkpointing duties too. Now
+ * there is a separate process, but we did not bother to split this header.
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
*
@@ -32,7 +35,6 @@ extern bool ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,
BlockNumber segno);
extern void AbsorbFsyncRequests(void);
-/* These were previously called BgWriterShmem... */
extern Size CheckpointerShmemSize(void);
extern void CheckpointerShmemInit(void);
diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h
index e43719ed73..4129ce5244 100644
--- a/src/include/storage/buf_internals.h
+++ b/src/include/storage/buf_internals.h
@@ -16,6 +16,7 @@
#define BUFMGR_INTERNALS_H
#include "storage/buf.h"
+#include "storage/latch.h"
#include "storage/lwlock.h"
#include "storage/shmem.h"
#include "storage/smgr.h"
@@ -188,6 +189,8 @@ extern bool StrategyRejectBuffer(BufferAccessStrategy strategy,
volatile BufferDesc *buf);
extern int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc);
+extern void StrategyNotifyBgWriter(Latch *bgwriterLatch);
+
extern Size StrategyShmemSize(void);
extern void StrategyInitialize(bool init);
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index c4808f44a0..7552e188f3 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -188,8 +188,6 @@ typedef struct PROC_HDR
PGPROC *freeProcs;
/* Head of list of autovacuum's free PGPROC structures */
PGPROC *autovacFreeProcs;
- /* BGWriter process's latch */
- Latch *bgwriterLatch;
/* WALWriter process's latch */
Latch *walwriterLatch;
/* Checkpointer process's latch */