diff options
| author | Tom Lane | 2020-05-13 17:08:12 +0000 |
|---|---|---|
| committer | Tom Lane | 2020-05-13 17:08:23 +0000 |
| commit | 81ca8686305c4c62d723ab224ad5c414f350a3a0 (patch) | |
| tree | 7b82a5eee2972eee5fd79a55a8c767493bf2c739 /src/include | |
| parent | 850196b610d2a1802b4ed7f9f608153a949eda34 (diff) | |
Improve management of SLRU statistics collection.
Instead of re-identifying which statistics bucket to use for a given
SLRU on every counter increment, do it once during shmem initialization.
This saves a fair number of cycles, and there's no real cost because
we could not have a bucket assignment that varies over time or across
backends anyway.
Also, get rid of the ill-considered decision to let pgstat.c pry
directly into SLRU's shared state; it's cleaner just to have slru.c
pass the stats bucket number.
In consequence of these changes, there's no longer any need to store
an SLRU's LWLock tranche info in shared memory, so get rid of that,
making this a net reduction in shmem consumption. (That partly
reverts fe702a7b3.)
This is basically code review for 28cac71bd, so I also cleaned up
some comments, removed a dangling extern declaration, fixed some
things that should be static and/or const, etc.
Discussion: https://postgr.es/m/3618.1589313035@sss.pgh.pa.us
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/access/slru.h | 10 | ||||
| -rw-r--r-- | src/include/pgstat.h | 26 |
2 files changed, 13 insertions, 23 deletions
diff --git a/src/include/access/slru.h b/src/include/access/slru.h index 00dbd803e1..61fbc80ef0 100644 --- a/src/include/access/slru.h +++ b/src/include/access/slru.h @@ -32,9 +32,6 @@ */ #define SLRU_PAGES_PER_SEGMENT 32 -/* Maximum length of an SLRU name */ -#define SLRU_MAX_NAME_LENGTH 32 - /* * Page status codes. Note that these do not include the "dirty" bit. * page_dirty can be true only in the VALID or WRITE_IN_PROGRESS states; @@ -68,6 +65,7 @@ typedef struct SlruSharedData bool *page_dirty; int *page_number; int *page_lru_count; + LWLockPadded *buffer_locks; /* * Optional array of WAL flush LSNs associated with entries in the SLRU @@ -98,10 +96,8 @@ typedef struct SlruSharedData */ int latest_page_number; - /* LWLocks */ - int lwlock_tranche_id; - char lwlock_tranche_name[SLRU_MAX_NAME_LENGTH]; - LWLockPadded *buffer_locks; + /* SLRU's index for statistics purposes (might not be unique) */ + int slru_stats_idx; } SlruSharedData; typedef SlruSharedData *SlruShared; diff --git a/src/include/pgstat.h b/src/include/pgstat.h index b8041d9988..ae9a39573c 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -11,7 +11,6 @@ #ifndef PGSTAT_H #define PGSTAT_H -#include "access/slru.h" #include "datatype/timestamp.h" #include "libpq/pqcomm.h" #include "miscadmin.h" @@ -438,7 +437,7 @@ typedef struct PgStat_MsgBgWriter } PgStat_MsgBgWriter; /* ---------- - * PgStat_MsgSLRU Sent by the SLRU to update statistics. + * PgStat_MsgSLRU Sent by a backend to update SLRU statistics. * ---------- */ typedef struct PgStat_MsgSLRU @@ -1261,11 +1260,6 @@ extern char *pgstat_stat_filename; extern PgStat_MsgBgWriter BgWriterStats; /* - * SLRU statistics counters are updated directly by slru. - */ -extern PgStat_MsgSLRU SlruStats[]; - -/* * Updated by pgstat_count_buffer_*_time macros */ extern PgStat_Counter pgStatBlockReadTime; @@ -1480,14 +1474,14 @@ extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void); extern PgStat_GlobalStats *pgstat_fetch_global(void); extern PgStat_SLRUStats *pgstat_fetch_slru(void); -extern void pgstat_count_slru_page_zeroed(SlruCtl ctl); -extern void pgstat_count_slru_page_hit(SlruCtl ctl); -extern void pgstat_count_slru_page_read(SlruCtl ctl); -extern void pgstat_count_slru_page_written(SlruCtl ctl); -extern void pgstat_count_slru_page_exists(SlruCtl ctl); -extern void pgstat_count_slru_flush(SlruCtl ctl); -extern void pgstat_count_slru_truncate(SlruCtl ctl); -extern char *pgstat_slru_name(int idx); -extern int pgstat_slru_index(const char *name); +extern void pgstat_count_slru_page_zeroed(int slru_idx); +extern void pgstat_count_slru_page_hit(int slru_idx); +extern void pgstat_count_slru_page_read(int slru_idx); +extern void pgstat_count_slru_page_written(int slru_idx); +extern void pgstat_count_slru_page_exists(int slru_idx); +extern void pgstat_count_slru_flush(int slru_idx); +extern void pgstat_count_slru_truncate(int slru_idx); +extern const char *pgstat_slru_name(int slru_idx); +extern int pgstat_slru_index(const char *name); #endif /* PGSTAT_H */ |
