From 4f6b92248d8ed2adf19e173b6e4824186a57ebe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Tue, 7 Jun 2022 21:20:35 +0300 Subject: [PATCH] mdbx: add `pgop_stat.gcrtime` for collect the time spent loading and searching inside GC. --- mdbx.h | 3 +++ src/core.c | 23 +++++++++++++++++++++++ src/internals.h | 3 +++ 3 files changed, 29 insertions(+) diff --git a/mdbx.h b/mdbx.h index 80eb7325..d67525cb 100644 --- a/mdbx.h +++ b/mdbx.h @@ -2491,6 +2491,9 @@ struct MDBX_envinfo { uint64_t unspill; /**< Quantity of unspilled/reloaded pages */ uint64_t wops; /**< Number of explicit write operations (not a pages) to a disk */ + uint64_t + gcrtime_seconds16dot16; /**< Time spent loading and searching inside + GC (aka FreeDB) in 1/65536 of second. */ } mi_pgop_stat; }; #ifndef __cplusplus diff --git a/src/core.c b/src/core.c index e150c878..efcc160c 100644 --- a/src/core.c +++ b/src/core.c @@ -6602,6 +6602,9 @@ page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, int flags) { unsigned re_len = MDBX_PNL_SIZE(re_list); pgno_t *range = nullptr; txnid_t oldest = 0, last = 0; +#if MDBX_ENABLE_PGOP_STAT + uint64_t timestamp = 0; +#endif /* MDBX_ENABLE_PGOP_STAT */ while (true) { /* hsr-kick retry loop */ MDBX_cursor_couple recur; @@ -6632,6 +6635,10 @@ page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, int flags) { ? mdbx_find_oldest(txn) : atomic_load64(&env->me_lck->mti_oldest_reader, mo_AcquireRelease); +#if MDBX_ENABLE_PGOP_STAT + if (likely(timestamp == 0)) + timestamp = mdbx_osal_monotime(); +#endif /* MDBX_ENABLE_PGOP_STAT */ ret.err = mdbx_cursor_init(&recur.outer, txn, FREE_DBI); if (unlikely(ret.err != MDBX_SUCCESS)) goto fail; @@ -6804,6 +6811,11 @@ page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, int flags) { /* Done for a kick-reclaim mode, actually no page needed */ if (unlikely(flags & MDBX_ALLOC_SLOT)) { mdbx_debug("early-return NULL-page for %s mode", "MDBX_ALLOC_SLOT"); +#if MDBX_ENABLE_PGOP_STAT + mdbx_assert(env, timestamp != 0); + env->me_lck->mti_pgop_stat.gcrtime.weak += + mdbx_osal_monotime() - timestamp; +#endif /* MDBX_ENABLE_PGOP_STAT */ ret.err = MDBX_SUCCESS; ret.page = NULL; return ret; @@ -6942,6 +6954,11 @@ page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, int flags) { } fail: +#if MDBX_ENABLE_PGOP_STAT + if (timestamp) + env->me_lck->mti_pgop_stat.gcrtime.weak += + mdbx_osal_monotime() - timestamp; +#endif /* MDBX_ENABLE_PGOP_STAT */ mdbx_assert(env, mdbx_pnl_check4assert(txn->tw.reclaimed_pglist, txn->mt_next_pgno - MDBX_ENABLE_REFUND)); @@ -6968,6 +6985,10 @@ page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, int flags) { done: mdbx_assert(env, !(flags & MDBX_ALLOC_SLOT)); mdbx_ensure(env, pgno >= NUM_METAS); +#if MDBX_ENABLE_PGOP_STAT + if (likely(timestamp)) + env->me_lck->mti_pgop_stat.gcrtime.weak += mdbx_osal_monotime() - timestamp; +#endif /* MDBX_ENABLE_PGOP_STAT */ if (unlikely(flags & MDBX_ALLOC_FAKE)) { mdbx_debug("return NULL-page for %u pages %s allocation", num, "gc-slot/backlog"); @@ -20410,6 +20431,8 @@ __cold static int fetch_envinfo_ex(const MDBX_env *env, const MDBX_txn *txn, atomic_load64(&lck->mti_pgop_stat.unspill, mo_Relaxed); arg->mi_pgop_stat.wops = atomic_load64(&lck->mti_pgop_stat.wops, mo_Relaxed); + arg->mi_pgop_stat.gcrtime_seconds16dot16 = mdbx_osal_monotime_to_16dot16( + atomic_load64(&lck->mti_pgop_stat.gcrtime, mo_Relaxed)); #else memset(&arg->mi_pgop_stat, 0, sizeof(arg->mi_pgop_stat)); #endif /* MDBX_ENABLE_PGOP_STAT*/ diff --git a/src/internals.h b/src/internals.h index 21a88711..309d3113 100644 --- a/src/internals.h +++ b/src/internals.h @@ -561,6 +561,9 @@ typedef struct { MDBX_atomic_uint64_t unspill; /* Quantity of unspilled/reloaded pages */ MDBX_atomic_uint64_t wops; /* Number of explicit write operations (not a pages) to a disk */ + MDBX_atomic_uint64_t + gcrtime; /* Time spending for reading/searching GC (aka FreeDB). The + unit/scale is platform-depended, see mdbx_osal_monotime(). */ } MDBX_pgop_stat_t; #endif /* MDBX_ENABLE_PGOP_STAT */