summaryrefslogtreecommitdiff
path: root/src/backend/storage/file/fd.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-03-18 07:43:01 -0400
committerRobert Haas <rhaas@postgresql.org>2017-03-18 07:43:01 -0400
commit249cf070e36721a65be74838c53acf8249faf935 (patch)
treea2d6e4d443fff0466598ab7751fe7f4a443449ab /src/backend/storage/file/fd.c
parent928250aef5f8363825acbf58540328089c26b0d4 (diff)
Create and use wait events for read, write, and fsync operations.
Previous commits, notably 53be0b1add7064ca5db3cd884302dfc3268d884e and 6f3bd98ebfc008cbd676da777bb0b2376c4c4bfa, made it possible to see from pg_stat_activity when a backend was stuck waiting for another backend, but it's also fairly common for a backend to be stuck waiting for an I/O. Add wait events for those operations, too. Rushabh Lathia, with further hacking by me. Reviewed and tested by Michael Paquier, Amit Kapila, Rajkumar Raghuwanshi, and Rahila Syed. Discussion: http://postgr.es/m/CAGPqQf0LsYHXREPAZqYGVkDqHSyjf=KsD=k0GTVPAuzyThh-VQ@mail.gmail.com
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r--src/backend/storage/file/fd.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index fd02fc019f1..f0ed2e9b5f4 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1550,7 +1550,7 @@ FileClose(File file)
* to read into.
*/
int
-FilePrefetch(File file, off_t offset, int amount)
+FilePrefetch(File file, off_t offset, int amount, uint32 wait_event_info)
{
#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
int returnCode;
@@ -1565,8 +1565,10 @@ FilePrefetch(File file, off_t offset, int amount)
if (returnCode < 0)
return returnCode;
+ pgstat_report_wait_start(wait_event_info);
returnCode = posix_fadvise(VfdCache[file].fd, offset, amount,
POSIX_FADV_WILLNEED);
+ pgstat_report_wait_end();
return returnCode;
#else
@@ -1576,7 +1578,7 @@ FilePrefetch(File file, off_t offset, int amount)
}
void
-FileWriteback(File file, off_t offset, off_t nbytes)
+FileWriteback(File file, off_t offset, off_t nbytes, uint32 wait_event_info)
{
int returnCode;
@@ -1597,11 +1599,13 @@ FileWriteback(File file, off_t offset, off_t nbytes)
if (returnCode < 0)
return;
+ pgstat_report_wait_start(wait_event_info);
pg_flush_data(VfdCache[file].fd, offset, nbytes);
+ pgstat_report_wait_end();
}
int
-FileRead(File file, char *buffer, int amount)
+FileRead(File file, char *buffer, int amount, uint32 wait_event_info)
{
int returnCode;
Vfd *vfdP;
@@ -1620,7 +1624,9 @@ FileRead(File file, char *buffer, int amount)
vfdP = &VfdCache[file];
retry:
+ pgstat_report_wait_start(wait_event_info);
returnCode = read(vfdP->fd, buffer, amount);
+ pgstat_report_wait_end();
if (returnCode >= 0)
{
@@ -1663,7 +1669,7 @@ retry:
}
int
-FileWrite(File file, char *buffer, int amount)
+FileWrite(File file, char *buffer, int amount, uint32 wait_event_info)
{
int returnCode;
Vfd *vfdP;
@@ -1721,7 +1727,9 @@ FileWrite(File file, char *buffer, int amount)
retry:
errno = 0;
+ pgstat_report_wait_start(wait_event_info);
returnCode = write(vfdP->fd, buffer, amount);
+ pgstat_report_wait_end();
/* if write didn't set errno, assume problem is no disk space */
if (returnCode != amount && errno == 0)
@@ -1782,7 +1790,7 @@ retry:
}
int
-FileSync(File file)
+FileSync(File file, uint32 wait_event_info)
{
int returnCode;
@@ -1795,7 +1803,11 @@ FileSync(File file)
if (returnCode < 0)
return returnCode;
- return pg_fsync(VfdCache[file].fd);
+ pgstat_report_wait_start(wait_event_info);
+ returnCode = pg_fsync(VfdCache[file].fd);
+ pgstat_report_wait_end();
+
+ return returnCode;
}
off_t
@@ -1887,7 +1899,7 @@ FileTell(File file)
#endif
int
-FileTruncate(File file, off_t offset)
+FileTruncate(File file, off_t offset, uint32 wait_event_info)
{
int returnCode;
@@ -1900,7 +1912,9 @@ FileTruncate(File file, off_t offset)
if (returnCode < 0)
return returnCode;
+ pgstat_report_wait_start(wait_event_info);
returnCode = ftruncate(VfdCache[file].fd, offset);
+ pgstat_report_wait_end();
if (returnCode == 0 && VfdCache[file].fileSize > offset)
{