Skip to content

Commit eccba07

Browse files
committed
Generate pgstat_count_slru*() functions for slru using macros
This change replaces seven functions definitions by macros, reducing a bit some repetitive patterns in the code. An interesting side effect is that this removes an inconsistency in the naming of SLRU increment functions with the field names. This change is similar to 850f4b4, 8018ffb or 83a1a1b. Author: Bertrand Drouvot <[email protected]> Discussion: https://postgr.es/m/aLHA//[email protected]
1 parent a850be2 commit eccba07

File tree

3 files changed

+31
-45
lines changed

3 files changed

+31
-45
lines changed

src/backend/access/transam/slru.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ SimpleLruZeroPage(SlruCtl ctl, int64 pageno)
408408
pg_atomic_write_u64(&shared->latest_page_number, pageno);
409409

410410
/* update the stats counter of zeroed pages */
411-
pgstat_count_slru_page_zeroed(shared->slru_stats_idx);
411+
pgstat_count_slru_blocks_zeroed(shared->slru_stats_idx);
412412

413413
return slotno;
414414
}
@@ -560,7 +560,7 @@ SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok,
560560
SlruRecentlyUsed(shared, slotno);
561561

562562
/* update the stats counter of pages found in the SLRU */
563-
pgstat_count_slru_page_hit(shared->slru_stats_idx);
563+
pgstat_count_slru_blocks_hit(shared->slru_stats_idx);
564564

565565
return slotno;
566566
}
@@ -605,7 +605,7 @@ SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok,
605605
SlruRecentlyUsed(shared, slotno);
606606

607607
/* update the stats counter of pages not found in SLRU */
608-
pgstat_count_slru_page_read(shared->slru_stats_idx);
608+
pgstat_count_slru_blocks_read(shared->slru_stats_idx);
609609

610610
return slotno;
611611
}
@@ -648,7 +648,7 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
648648
SlruRecentlyUsed(shared, slotno);
649649

650650
/* update the stats counter of pages found in the SLRU */
651-
pgstat_count_slru_page_hit(shared->slru_stats_idx);
651+
pgstat_count_slru_blocks_hit(shared->slru_stats_idx);
652652

653653
return slotno;
654654
}
@@ -778,7 +778,7 @@ SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int64 pageno)
778778
off_t endpos;
779779

780780
/* update the stats counter of checked pages */
781-
pgstat_count_slru_page_exists(ctl->shared->slru_stats_idx);
781+
pgstat_count_slru_blocks_exists(ctl->shared->slru_stats_idx);
782782

783783
SlruFileName(ctl, path, segno);
784784

@@ -907,7 +907,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int64 pageno, int slotno, SlruWriteAll fdata)
907907
int fd = -1;
908908

909909
/* update the stats counter of written pages */
910-
pgstat_count_slru_page_written(shared->slru_stats_idx);
910+
pgstat_count_slru_blocks_written(shared->slru_stats_idx);
911911

912912
/*
913913
* Honor the write-WAL-before-data rule, if appropriate, so that we do not

src/backend/utils/activity/pgstat_slru.c

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,47 +55,33 @@ pgstat_reset_slru(const char *name)
5555
* SLRU statistics count accumulation functions --- called from slru.c
5656
*/
5757

58-
void
59-
pgstat_count_slru_page_zeroed(int slru_idx)
60-
{
61-
get_slru_entry(slru_idx)->blocks_zeroed += 1;
58+
#define PGSTAT_COUNT_SLRU(stat) \
59+
void \
60+
CppConcat(pgstat_count_slru_,stat)(int slru_idx) \
61+
{ \
62+
get_slru_entry(slru_idx)->stat += 1; \
6263
}
6364

64-
void
65-
pgstat_count_slru_page_hit(int slru_idx)
66-
{
67-
get_slru_entry(slru_idx)->blocks_hit += 1;
68-
}
65+
/* pgstat_count_slru_blocks_zeroed */
66+
PGSTAT_COUNT_SLRU(blocks_zeroed)
6967

70-
void
71-
pgstat_count_slru_page_exists(int slru_idx)
72-
{
73-
get_slru_entry(slru_idx)->blocks_exists += 1;
74-
}
68+
/* pgstat_count_slru_blocks_hit */
69+
PGSTAT_COUNT_SLRU(blocks_hit)
7570

76-
void
77-
pgstat_count_slru_page_read(int slru_idx)
78-
{
79-
get_slru_entry(slru_idx)->blocks_read += 1;
80-
}
71+
/* pgstat_count_slru_blocks_exists */
72+
PGSTAT_COUNT_SLRU(blocks_exists)
8173

82-
void
83-
pgstat_count_slru_page_written(int slru_idx)
84-
{
85-
get_slru_entry(slru_idx)->blocks_written += 1;
86-
}
74+
/* pgstat_count_slru_blocks_read */
75+
PGSTAT_COUNT_SLRU(blocks_read)
8776

88-
void
89-
pgstat_count_slru_flush(int slru_idx)
90-
{
91-
get_slru_entry(slru_idx)->flush += 1;
92-
}
77+
/* pgstat_count_slru_blocks_written */
78+
PGSTAT_COUNT_SLRU(blocks_written)
9379

94-
void
95-
pgstat_count_slru_truncate(int slru_idx)
96-
{
97-
get_slru_entry(slru_idx)->truncate += 1;
98-
}
80+
/* pgstat_count_slru_flush */
81+
PGSTAT_COUNT_SLRU(flush)
82+
83+
/* pgstat_count_slru_truncate */
84+
PGSTAT_COUNT_SLRU(truncate)
9985

10086
/*
10187
* Support function for the SQL-callable pgstat* functions. Returns

src/include/pgstat.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,11 @@ extern PgStat_StatReplSlotEntry *pgstat_fetch_replslot(NameData slotname);
747747
*/
748748

749749
extern void pgstat_reset_slru(const char *);
750-
extern void pgstat_count_slru_page_zeroed(int slru_idx);
751-
extern void pgstat_count_slru_page_hit(int slru_idx);
752-
extern void pgstat_count_slru_page_read(int slru_idx);
753-
extern void pgstat_count_slru_page_written(int slru_idx);
754-
extern void pgstat_count_slru_page_exists(int slru_idx);
750+
extern void pgstat_count_slru_blocks_zeroed(int slru_idx);
751+
extern void pgstat_count_slru_blocks_hit(int slru_idx);
752+
extern void pgstat_count_slru_blocks_read(int slru_idx);
753+
extern void pgstat_count_slru_blocks_written(int slru_idx);
754+
extern void pgstat_count_slru_blocks_exists(int slru_idx);
755755
extern void pgstat_count_slru_flush(int slru_idx);
756756
extern void pgstat_count_slru_truncate(int slru_idx);
757757
extern const char *pgstat_get_slru_name(int slru_idx);

0 commit comments

Comments
 (0)