mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +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:
@@ -191,6 +191,8 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
|
||||
|
||||
/* shared->latest_page_number will be set later */
|
||||
|
||||
shared->slru_stats_idx = pgstat_slru_index(name);
|
||||
|
||||
ptr = (char *) shared;
|
||||
offset = MAXALIGN(sizeof(SlruSharedData));
|
||||
shared->page_buffer = (char **) (ptr + offset);
|
||||
@@ -214,15 +216,11 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
|
||||
offset += MAXALIGN(nslots * nlsns * sizeof(XLogRecPtr));
|
||||
}
|
||||
|
||||
Assert(strlen(name) + 1 < SLRU_MAX_NAME_LENGTH);
|
||||
strlcpy(shared->lwlock_tranche_name, name, SLRU_MAX_NAME_LENGTH);
|
||||
shared->lwlock_tranche_id = tranche_id;
|
||||
|
||||
ptr += BUFFERALIGN(offset);
|
||||
for (slotno = 0; slotno < nslots; slotno++)
|
||||
{
|
||||
LWLockInitialize(&shared->buffer_locks[slotno].lock,
|
||||
shared->lwlock_tranche_id);
|
||||
tranche_id);
|
||||
|
||||
shared->page_buffer[slotno] = ptr;
|
||||
shared->page_status[slotno] = SLRU_PAGE_EMPTY;
|
||||
@@ -238,8 +236,7 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
|
||||
Assert(found);
|
||||
|
||||
/* Register SLRU tranche in the main tranches array */
|
||||
LWLockRegisterTranche(shared->lwlock_tranche_id,
|
||||
shared->lwlock_tranche_name);
|
||||
LWLockRegisterTranche(tranche_id, name);
|
||||
|
||||
/*
|
||||
* Initialize the unshared control struct, including directory path. We
|
||||
@@ -287,7 +284,7 @@ SimpleLruZeroPage(SlruCtl ctl, int pageno)
|
||||
shared->latest_page_number = pageno;
|
||||
|
||||
/* update the stats counter of zeroed pages */
|
||||
pgstat_count_slru_page_zeroed(ctl);
|
||||
pgstat_count_slru_page_zeroed(shared->slru_stats_idx);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
@@ -408,7 +405,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
|
||||
SlruRecentlyUsed(shared, slotno);
|
||||
|
||||
/* update the stats counter of pages found in the SLRU */
|
||||
pgstat_count_slru_page_hit(ctl);
|
||||
pgstat_count_slru_page_hit(shared->slru_stats_idx);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
@@ -453,7 +450,7 @@ SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
|
||||
SlruRecentlyUsed(shared, slotno);
|
||||
|
||||
/* update the stats counter of pages not found in SLRU */
|
||||
pgstat_count_slru_page_read(ctl);
|
||||
pgstat_count_slru_page_read(shared->slru_stats_idx);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
@@ -493,7 +490,7 @@ SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
|
||||
SlruRecentlyUsed(shared, slotno);
|
||||
|
||||
/* update the stats counter of pages found in the SLRU */
|
||||
pgstat_count_slru_page_hit(ctl);
|
||||
pgstat_count_slru_page_hit(shared->slru_stats_idx);
|
||||
|
||||
return slotno;
|
||||
}
|
||||
@@ -612,7 +609,7 @@ SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno)
|
||||
off_t endpos;
|
||||
|
||||
/* update the stats counter of checked pages */
|
||||
pgstat_count_slru_page_exists(ctl);
|
||||
pgstat_count_slru_page_exists(ctl->shared->slru_stats_idx);
|
||||
|
||||
SlruFileName(ctl, path, segno);
|
||||
|
||||
@@ -749,7 +746,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
|
||||
int fd = -1;
|
||||
|
||||
/* update the stats counter of written pages */
|
||||
pgstat_count_slru_page_written(ctl);
|
||||
pgstat_count_slru_page_written(shared->slru_stats_idx);
|
||||
|
||||
/*
|
||||
* Honor the write-WAL-before-data rule, if appropriate, so that we do not
|
||||
@@ -1147,7 +1144,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
|
||||
bool ok;
|
||||
|
||||
/* update the stats counter of flushes */
|
||||
pgstat_count_slru_flush(ctl);
|
||||
pgstat_count_slru_flush(shared->slru_stats_idx);
|
||||
|
||||
/*
|
||||
* Find and write dirty pages
|
||||
@@ -1211,7 +1208,7 @@ SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
|
||||
int slotno;
|
||||
|
||||
/* update the stats counter of truncates */
|
||||
pgstat_count_slru_truncate(ctl);
|
||||
pgstat_count_slru_truncate(shared->slru_stats_idx);
|
||||
|
||||
/*
|
||||
* The cutoff point is the start of the segment containing cutoffPage.
|
||||
|
Reference in New Issue
Block a user