From dc39ecfb9fc153b33063c3de1009aad3757f471c 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: Sun, 24 Jul 2022 21:20:22 +0300 Subject: [PATCH] mdbx: auto-coalesce of GC's records with less overhead. --- src/core.c | 20 +++++++------------- src/internals.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/core.c b/src/core.c index 65f1369c..991141a0 100644 --- a/src/core.c +++ b/src/core.c @@ -6645,19 +6645,18 @@ __hot static pgno_t *scan4range(const MDBX_PNL pnl, const unsigned len, #define MDBX_ALLOC_NOLOG 32 #define MDBX_ALLOC_ALL (MDBX_ALLOC_GC | MDBX_ALLOC_NEW) -__cold static pgr_t page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, - int flags) { +static pgr_t page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, int flags) { pgr_t ret; MDBX_txn *const txn = mc->mc_txn; MDBX_env *const env = txn->mt_env; mdbx_assert(env, num == 0 || !(flags & MDBX_ALLOC_SLOT)); mdbx_assert(env, num > 0 || !(flags & MDBX_ALLOC_NEW)); - const unsigned coalesce_threshold = - env->me_maxgc_ov1page - env->me_maxgc_ov1page / 4; + const unsigned coalesce_threshold = env->me_maxgc_ov1page >> 2; if (likely(flags & MDBX_ALLOC_GC)) { flags |= env->me_flags & MDBX_LIFORECLAIM; - if (MDBX_PNL_SIZE(txn->tw.reclaimed_pglist) < coalesce_threshold) + if (txn->mt_dbs[FREE_DBI].md_branch_pages && + MDBX_PNL_SIZE(txn->tw.reclaimed_pglist) < coalesce_threshold) flags |= MDBX_ALLOC_COALESCE; if (unlikely( /* If mc is updating the GC, then the retired-list cannot play @@ -6858,7 +6857,6 @@ __cold static pgr_t page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, } /* Merge in descending sorted order */ - const unsigned prev_re_len = MDBX_PNL_SIZE(re_list); pnl_merge(re_list, gc_pnl); if (mdbx_audit_enabled() && unlikely(!mdbx_pnl_check(re_list, txn->mt_next_pgno))) { @@ -6891,15 +6889,11 @@ __cold static pgr_t page_alloc_slowpath(MDBX_cursor *mc, const pgno_t num, } /* Don't try to coalesce too much. */ - if (flags & MDBX_ALLOC_COALESCE) { - if (re_len /* current size */ > coalesce_threshold || - (re_len > prev_re_len && - re_len - prev_re_len /* delta from prev */ >= - coalesce_threshold / 2)) { + if (re_len /* current size */ > coalesce_threshold) { + if (flags & MDBX_ALLOC_COALESCE) mdbx_trace("clear %s %s", "MDBX_ALLOC_COALESCE", "since got threshold"); - flags &= ~MDBX_ALLOC_COALESCE; - } + flags &= ~MDBX_ALLOC_COALESCE; } } diff --git a/src/internals.h b/src/internals.h index dff6b216..cc2a578a 100644 --- a/src/internals.h +++ b/src/internals.h @@ -1109,7 +1109,7 @@ struct MDBX_env { #define MDBX_ENV_TXKEY UINT32_C(0x10000000) /* Legacy MDBX_MAPASYNC (prior v0.9) */ #define MDBX_DEPRECATED_MAPASYNC UINT32_C(0x100000) - /* Legacy MDBX_MAPASYNC (prior v0.12) */ + /* Legacy MDBX_COALESCE (prior v0.12) */ #define MDBX_DEPRECATED_COALESCE UINT32_C(0x2000000) #define ENV_INTERNAL_FLAGS (MDBX_FATAL_ERROR | MDBX_ENV_ACTIVE | MDBX_ENV_TXKEY) uint32_t me_flags;