1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

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
This commit is contained in:
Tom Lane
2020-05-13 13:08:12 -04:00
parent 850196b610
commit 81ca868630
5 changed files with 77 additions and 86 deletions

View File

@ -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
@ -1260,11 +1259,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
*/
@ -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 */