From 4cd08f0ef91d429586bc2c0228eaefffab91c342 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 21 Nov 2020 17:53:17 +0300 Subject: [PATCH] mdbx: add `MDBX_opt_rp_augment_limit`. More for https://github.com/erthink/libmdbx/issues/128 Change-Id: I94f3350b72ad11d0b586aaef1574f7654223bc40 --- mdbx.h | 4 ++++ src/core.c | 14 ++++++++++++-- src/internals.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mdbx.h b/mdbx.h index 19c7cec3..7fa59a4c 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1802,6 +1802,10 @@ enum MDBX_option_t { /** \brief The limit to grow a list of pre-allocated dirty pages. */ MDBX_opt_dp_reserve_limit, + + /** \brief The limit to grow a list of reclaimed pages + * for finding a sequence of contiguous pages. */ + MDBX_opt_rp_augment_limit, }; #ifndef __cplusplus /** \ingroup c_settings */ diff --git a/src/core.c b/src/core.c index 3a17245f..a5ea7ee5 100644 --- a/src/core.c +++ b/src/core.c @@ -5278,9 +5278,8 @@ skip_cache: } const unsigned gc_len = MDBX_PNL_SIZE(gc_pnl); /* TODO: provide a user-configurable threshold */ - const unsigned threshold_2_stop_gc_reclaiming = MDBX_PNL_MAX / 4; if (unlikely(gc_len + MDBX_PNL_SIZE(txn->tw.reclaimed_pglist) > - threshold_2_stop_gc_reclaiming) && + env->me_options.rp_augment_limit) && (pgno_add(txn->mt_next_pgno, num) <= txn->mt_geo.upper || gc_len + MDBX_PNL_SIZE(txn->tw.reclaimed_pglist) >= MDBX_PNL_MAX / 16 * 15)) { @@ -9234,6 +9233,7 @@ __cold int mdbx_env_create(MDBX_env **penv) { env->me_stuck_meta = -1; env->me_options.dp_reserve_limit = 1024; + env->me_options.rp_augment_limit = 1024 * 1024; int rc; const size_t os_psize = mdbx_syspagesize(); @@ -19710,6 +19710,12 @@ __cold int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, } break; + case MDBX_opt_rp_augment_limit: + if (unlikely(value > MDBX_PNL_MAX)) + return MDBX_EINVAL; + env->me_options.rp_augment_limit = (unsigned)value; + break; + default: return MDBX_EINVAL; } @@ -19752,6 +19758,10 @@ __cold int mdbx_env_get_option(const MDBX_env *env, const MDBX_option_t option, *value = env->me_options.dp_reserve_limit; break; + case MDBX_opt_rp_augment_limit: + *value = env->me_options.rp_augment_limit; + break; + default: return MDBX_EINVAL; } diff --git a/src/internals.h b/src/internals.h index 29ee6d86..2d640b85 100644 --- a/src/internals.h +++ b/src/internals.h @@ -995,6 +995,7 @@ struct MDBX_env { unsigned me_dp_reserve_len; struct { unsigned dp_reserve_limit; + unsigned rp_augment_limit; } me_options; struct { #if MDBX_LOCKING > 0