mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Use pgBufferUsage for buffer usage tracking in analyze.
Previously, (auto)analyze used global variables VacuumPageHit, VacuumPageMiss, and VacuumPageDirty to track buffer usage. However, pgBufferUsage provides a more generic way to track buffer usage with support functions. This change replaces those global variables with pgBufferUsage in analyze. Since analyze was the sole user of those variables, it removes their declarations. Vacuum previously used those variables but replaced them with pgBufferUsage as part of a bug fix, commit 5cd72cc0c. Additionally, it adjusts the buffer usage message in both vacuum and analyze for better consistency. Author: Anthonin Bonnefoy Reviewed-by: Masahiko Sawada, Michael Paquier Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com
This commit is contained in:
parent
2488058dc3
commit
c584781bcc
@ -608,6 +608,9 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
|
||||
int32 diff;
|
||||
double read_rate = 0,
|
||||
write_rate = 0;
|
||||
int64 total_blks_hit;
|
||||
int64 total_blks_read;
|
||||
int64 total_blks_dirtied;
|
||||
|
||||
TimestampDifference(starttime, endtime, &secs_dur, &usecs_dur);
|
||||
memset(&walusage, 0, sizeof(WalUsage));
|
||||
@ -615,6 +618,13 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
|
||||
memset(&bufferusage, 0, sizeof(BufferUsage));
|
||||
BufferUsageAccumDiff(&bufferusage, &pgBufferUsage, &startbufferusage);
|
||||
|
||||
total_blks_hit = bufferusage.shared_blks_hit +
|
||||
bufferusage.local_blks_hit;
|
||||
total_blks_read = bufferusage.shared_blks_read +
|
||||
bufferusage.local_blks_read;
|
||||
total_blks_dirtied = bufferusage.shared_blks_dirtied +
|
||||
bufferusage.local_blks_dirtied;
|
||||
|
||||
initStringInfo(&buf);
|
||||
if (verbose)
|
||||
{
|
||||
@ -740,18 +750,18 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
|
||||
}
|
||||
if (secs_dur > 0 || usecs_dur > 0)
|
||||
{
|
||||
read_rate = (double) BLCKSZ * (bufferusage.shared_blks_read + bufferusage.local_blks_read) /
|
||||
read_rate = (double) BLCKSZ * total_blks_read /
|
||||
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
|
||||
write_rate = (double) BLCKSZ * (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied) /
|
||||
write_rate = (double) BLCKSZ * total_blks_dirtied /
|
||||
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
|
||||
}
|
||||
appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
|
||||
read_rate, write_rate);
|
||||
appendStringInfo(&buf,
|
||||
_("buffer usage: %lld hits, %lld misses, %lld dirtied\n"),
|
||||
(long long) (bufferusage.shared_blks_hit + bufferusage.local_blks_hit),
|
||||
(long long) (bufferusage.shared_blks_read + bufferusage.local_blks_read),
|
||||
(long long) (bufferusage.shared_blks_dirtied + bufferusage.local_blks_dirtied));
|
||||
_("buffer usage: %lld hits, %lld reads, %lld dirtied\n"),
|
||||
(long long) total_blks_hit,
|
||||
(long long) total_blks_read,
|
||||
(long long) total_blks_dirtied);
|
||||
appendStringInfo(&buf,
|
||||
_("WAL usage: %lld records, %lld full page images, %llu bytes\n"),
|
||||
(long long) walusage.wal_records,
|
||||
|
@ -303,9 +303,8 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
|
||||
Oid save_userid;
|
||||
int save_sec_context;
|
||||
int save_nestlevel;
|
||||
int64 AnalyzePageHit = VacuumPageHit;
|
||||
int64 AnalyzePageMiss = VacuumPageMiss;
|
||||
int64 AnalyzePageDirty = VacuumPageDirty;
|
||||
BufferUsage startbufferusage = pgBufferUsage;
|
||||
BufferUsage bufferusage;
|
||||
PgStat_Counter startreadtime = 0;
|
||||
PgStat_Counter startwritetime = 0;
|
||||
|
||||
@ -736,15 +735,19 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
|
||||
double read_rate = 0;
|
||||
double write_rate = 0;
|
||||
StringInfoData buf;
|
||||
int64 total_blks_hit;
|
||||
int64 total_blks_read;
|
||||
int64 total_blks_dirtied;
|
||||
|
||||
/*
|
||||
* Calculate the difference in the Page Hit/Miss/Dirty that
|
||||
* happened as part of the analyze by subtracting out the
|
||||
* pre-analyze values which we saved above.
|
||||
*/
|
||||
AnalyzePageHit = VacuumPageHit - AnalyzePageHit;
|
||||
AnalyzePageMiss = VacuumPageMiss - AnalyzePageMiss;
|
||||
AnalyzePageDirty = VacuumPageDirty - AnalyzePageDirty;
|
||||
memset(&bufferusage, 0, sizeof(BufferUsage));
|
||||
BufferUsageAccumDiff(&bufferusage, &pgBufferUsage, &startbufferusage);
|
||||
|
||||
total_blks_hit = bufferusage.shared_blks_hit +
|
||||
bufferusage.local_blks_hit;
|
||||
total_blks_read = bufferusage.shared_blks_read +
|
||||
bufferusage.local_blks_read;
|
||||
total_blks_dirtied = bufferusage.shared_blks_dirtied +
|
||||
bufferusage.local_blks_dirtied;
|
||||
|
||||
/*
|
||||
* We do not expect an analyze to take > 25 days and it simplifies
|
||||
@ -770,10 +773,10 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
|
||||
|
||||
if (delay_in_ms > 0)
|
||||
{
|
||||
read_rate = (double) BLCKSZ * AnalyzePageMiss / (1024 * 1024) /
|
||||
(delay_in_ms / 1000.0);
|
||||
write_rate = (double) BLCKSZ * AnalyzePageDirty / (1024 * 1024) /
|
||||
(delay_in_ms / 1000.0);
|
||||
read_rate = (double) BLCKSZ * total_blks_read /
|
||||
(1024 * 1024) / (delay_in_ms / 1000.0);
|
||||
write_rate = (double) BLCKSZ * total_blks_dirtied /
|
||||
(1024 * 1024) / (delay_in_ms / 1000.0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -796,10 +799,10 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
|
||||
}
|
||||
appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
|
||||
read_rate, write_rate);
|
||||
appendStringInfo(&buf, _("buffer usage: %lld hits, %lld misses, %lld dirtied\n"),
|
||||
(long long) AnalyzePageHit,
|
||||
(long long) AnalyzePageMiss,
|
||||
(long long) AnalyzePageDirty);
|
||||
appendStringInfo(&buf, _("buffer usage: %lld hits, %lld reads, %lld dirtied\n"),
|
||||
(long long) total_blks_hit,
|
||||
(long long) total_blks_read,
|
||||
(long long) total_blks_dirtied);
|
||||
appendStringInfo(&buf, _("system usage: %s"), pg_rusage_show(&ru0));
|
||||
|
||||
ereport(LOG,
|
||||
|
@ -603,9 +603,6 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
|
||||
VacuumFailsafeActive = false;
|
||||
VacuumUpdateCosts();
|
||||
VacuumCostBalance = 0;
|
||||
VacuumPageHit = 0;
|
||||
VacuumPageMiss = 0;
|
||||
VacuumPageDirty = 0;
|
||||
VacuumCostBalanceLocal = 0;
|
||||
VacuumSharedCostBalance = NULL;
|
||||
VacuumActiveNWorkers = NULL;
|
||||
|
@ -1043,9 +1043,6 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
|
||||
/* Set cost-based vacuum delay */
|
||||
VacuumUpdateCosts();
|
||||
VacuumCostBalance = 0;
|
||||
VacuumPageHit = 0;
|
||||
VacuumPageMiss = 0;
|
||||
VacuumPageDirty = 0;
|
||||
VacuumCostBalanceLocal = 0;
|
||||
VacuumSharedCostBalance = &(shared->cost_balance);
|
||||
VacuumActiveNWorkers = &(shared->active_nworkers);
|
||||
|
@ -1192,7 +1192,6 @@ PinBufferForBlock(Relation rel,
|
||||
}
|
||||
if (*foundPtr)
|
||||
{
|
||||
VacuumPageHit++;
|
||||
pgstat_count_io_op(io_object, io_context, IOOP_HIT);
|
||||
if (VacuumCostActive)
|
||||
VacuumCostBalance += VacuumCostPageHit;
|
||||
@ -1588,7 +1587,6 @@ WaitReadBuffers(ReadBuffersOperation *operation)
|
||||
false);
|
||||
}
|
||||
|
||||
VacuumPageMiss += io_buffers_len;
|
||||
if (VacuumCostActive)
|
||||
VacuumCostBalance += VacuumCostPageMiss * io_buffers_len;
|
||||
}
|
||||
@ -2582,7 +2580,6 @@ MarkBufferDirty(Buffer buffer)
|
||||
*/
|
||||
if (!(old_buf_state & BM_DIRTY))
|
||||
{
|
||||
VacuumPageDirty++;
|
||||
pgBufferUsage.shared_blks_dirtied++;
|
||||
if (VacuumCostActive)
|
||||
VacuumCostBalance += VacuumCostPageDirty;
|
||||
@ -5122,7 +5119,6 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
|
||||
|
||||
if (dirtied)
|
||||
{
|
||||
VacuumPageDirty++;
|
||||
pgBufferUsage.shared_blks_dirtied++;
|
||||
if (VacuumCostActive)
|
||||
VacuumCostBalance += VacuumCostPageDirty;
|
||||
|
@ -153,10 +153,6 @@ int VacuumCostPageDirty = 20;
|
||||
int VacuumCostLimit = 200;
|
||||
double VacuumCostDelay = 0;
|
||||
|
||||
int64 VacuumPageHit = 0;
|
||||
int64 VacuumPageMiss = 0;
|
||||
int64 VacuumPageDirty = 0;
|
||||
|
||||
int VacuumCostBalance = 0; /* working state for vacuum */
|
||||
bool VacuumCostActive = false;
|
||||
|
||||
|
@ -284,10 +284,6 @@ extern PGDLLIMPORT int VacuumCostPageDirty;
|
||||
extern PGDLLIMPORT int VacuumCostLimit;
|
||||
extern PGDLLIMPORT double VacuumCostDelay;
|
||||
|
||||
extern PGDLLIMPORT int64 VacuumPageHit;
|
||||
extern PGDLLIMPORT int64 VacuumPageMiss;
|
||||
extern PGDLLIMPORT int64 VacuumPageDirty;
|
||||
|
||||
extern PGDLLIMPORT int VacuumCostBalance;
|
||||
extern PGDLLIMPORT bool VacuumCostActive;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user