summaryrefslogtreecommitdiff
path: root/src/backend/postmaster
diff options
context:
space:
mode:
authorRobert Haas2010-11-15 17:42:59 +0000
committerRobert Haas2010-11-15 17:42:59 +0000
commit3134d8863e8473e3ed791e27d484f9e548220411 (patch)
tree57892334bf423c03ac4d69265ea15adc31977af0 /src/backend/postmaster
parent8d70ed84ba577abf9e985518024fb92e2081dac9 (diff)
Add new buffers_backend_fsync field to pg_stat_bgwriter.
This new field counts the number of times that a backend which writes a buffer out to the OS must also fsync() it. This happens when the bgwriter fsync request queue is full, and is generally detrimental to performance, so it's good to know when it's happening. Along the way, log a new message at level DEBUG1 whenever we fail to hand off an fsync, so that the problem can also be seen in examination of log files (if the logging level is cranked up high enough). Greg Smith, with minor tweaks by me.
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r--src/backend/postmaster/bgwriter.c16
-rw-r--r--src/backend/postmaster/pgstat.c1
2 files changed, 13 insertions, 4 deletions
diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c
index 0690ab521e7..620b1972a67 100644
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -102,13 +102,15 @@
*
* num_backend_writes is used to count the number of buffer writes performed
* by non-bgwriter processes. This counter should be wide enough that it
- * can't overflow during a single bgwriter cycle.
+ * can't overflow during a single bgwriter cycle. num_backend_fsync
+ * counts the subset of those writes that also had to do their own fsync,
+ * because the background writer failed to absorb their request.
*
* The requests array holds fsync requests sent by backends and not yet
* absorbed by the bgwriter.
*
- * Unlike the checkpoint fields, num_backend_writes and the requests
- * fields are protected by BgWriterCommLock.
+ * Unlike the checkpoint fields, num_backend_writes, num_backend_fsync, and
+ * the requests fields are protected by BgWriterCommLock.
*----------
*/
typedef struct
@@ -132,6 +134,7 @@ typedef struct
int ckpt_flags; /* checkpoint flags, as defined in xlog.h */
uint32 num_backend_writes; /* counts non-bgwriter buffer writes */
+ uint32 num_backend_fsync; /* counts non-bgwriter fsync calls */
int num_requests; /* current # of requests */
int max_requests; /* allocated array size */
@@ -1084,12 +1087,14 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,
LWLockAcquire(BgWriterCommLock, LW_EXCLUSIVE);
- /* we count non-bgwriter writes even when the request queue overflows */
+ /* Count all backend writes regardless of if they fit in the queue */
BgWriterShmem->num_backend_writes++;
if (BgWriterShmem->bgwriter_pid == 0 ||
BgWriterShmem->num_requests >= BgWriterShmem->max_requests)
{
+ /* Also count the subset where backends have to do their own fsync */
+ BgWriterShmem->num_backend_fsync++;
LWLockRelease(BgWriterCommLock);
return false;
}
@@ -1137,7 +1142,10 @@ AbsorbFsyncRequests(void)
/* Transfer write count into pending pgstats message */
BgWriterStats.m_buf_written_backend += BgWriterShmem->num_backend_writes;
+ BgWriterStats.m_buf_fsync_backend += BgWriterShmem->num_backend_fsync;
+
BgWriterShmem->num_backend_writes = 0;
+ BgWriterShmem->num_backend_fsync = 0;
n = BgWriterShmem->num_requests;
if (n > 0)
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index a1ad3429535..c3c136a1612 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -4188,6 +4188,7 @@ pgstat_recv_bgwriter(PgStat_MsgBgWriter *msg, int len)
globalStats.buf_written_clean += msg->m_buf_written_clean;
globalStats.maxwritten_clean += msg->m_maxwritten_clean;
globalStats.buf_written_backend += msg->m_buf_written_backend;
+ globalStats.buf_fsync_backend += msg->m_buf_fsync_backend;
globalStats.buf_alloc += msg->m_buf_alloc;
}