mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
Collect statistics about SLRU caches
There's a number of SLRU caches used to access important data like clog, commit timestamps, multixact, asynchronous notifications, etc. Until now we had no easy way to monitor these shared caches, compute hit ratios, number of reads/writes etc. This commit extends the statistics collector to track this information for a predefined list of SLRUs, and also introduces a new system view pg_stat_slru displaying the data. The list of built-in SLRUs is fixed, but additional SLRUs may be defined in extensions. Unfortunately, there's no suitable registry of SLRUs, so this patch simply defines a fixed list of SLRUs with entries for the built-in ones and one entry for all additional SLRUs. Extensions adding their own SLRU are fairly rare, so this seems acceptable. This patch only allows monitoring of SLRUs, not tuning. The SLRU sizes are still fixed (hard-coded in the code) and it's not entirely clear which of the SLRUs might need a GUC to tune size. In a way, allowing us to determine that is one of the goals of this patch. Bump catversion as the patch introduces new functions and system view. Author: Tomas Vondra Reviewed-by: Alvaro Herrera Discussion: https://www.postgresql.org/message-id/flat/20200119143707.gyinppnigokesjok@development
This commit is contained in:
@@ -286,6 +286,9 @@ SimpleLruZeroPage(SlruCtl ctl, int pageno)
|
||||
/* Assume this page is now the latest active page */
|
||||
shared->latest_page_number = pageno;
|
||||
|
||||
/* update the stats counter of zeroed pages */
|
||||
pgstat_count_slru_page_zeroed(ctl);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
|
||||
@@ -403,6 +406,10 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
|
||||
}
|
||||
/* Otherwise, it's ready to use */
|
||||
SlruRecentlyUsed(shared, slotno);
|
||||
|
||||
/* update the stats counter of pages found in the SLRU */
|
||||
pgstat_count_slru_page_hit(ctl);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
|
||||
@@ -444,6 +451,10 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
|
||||
SlruReportIOError(ctl, pageno, xid);
|
||||
|
||||
SlruRecentlyUsed(shared, slotno);
|
||||
|
||||
/* update the stats counter of pages not found in SLRU */
|
||||
pgstat_count_slru_page_read(ctl);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
}
|
||||
@@ -596,6 +607,9 @@ SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno)
|
||||
bool result;
|
||||
off_t endpos;
|
||||
|
||||
/* update the stats counter of checked pages */
|
||||
pgstat_count_slru_page_exists(ctl);
|
||||
|
||||
SlruFileName(ctl, path, segno);
|
||||
|
||||
fd = OpenTransientFile(path, O_RDONLY | PG_BINARY);
|
||||
@@ -730,6 +744,9 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
|
||||
char path[MAXPGPATH];
|
||||
int fd = -1;
|
||||
|
||||
/* update the stats counter of written pages */
|
||||
pgstat_count_slru_page_written(ctl);
|
||||
|
||||
/*
|
||||
* Honor the write-WAL-before-data rule, if appropriate, so that we do not
|
||||
* write out data before associated WAL records. This is the same action
|
||||
@@ -1125,6 +1142,9 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
|
||||
int i;
|
||||
bool ok;
|
||||
|
||||
/* update the stats counter of flushes */
|
||||
pgstat_count_slru_flush(ctl);
|
||||
|
||||
/*
|
||||
* Find and write dirty pages
|
||||
*/
|
||||
@@ -1186,6 +1206,9 @@ SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
|
||||
SlruShared shared = ctl->shared;
|
||||
int slotno;
|
||||
|
||||
/* update the stats counter of truncates */
|
||||
pgstat_count_slru_truncate(ctl);
|
||||
|
||||
/*
|
||||
* The cutoff point is the start of the segment containing cutoffPage.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user