mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
Create and use wait events for read, write, and fsync operations.
Previous commits, notably53be0b1addand6f3bd98ebf, 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
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user