mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx: add MDBX_opt_spill_parent4child_denominator
runtime option.
More for https://github.com/erthink/libmdbx/issues/128 Change-Id: If1549c3855eb59c107eb115e6dbca515e81644f9
This commit is contained in:
parent
56aaad03bc
commit
b82d1d5063
23
mdbx.h
23
mdbx.h
@ -1917,6 +1917,29 @@ enum MDBX_option_t {
|
|||||||
* bottom. Default is 8, i.e. at least the 1/8 of the current dirty pages
|
* bottom. Default is 8, i.e. at least the 1/8 of the current dirty pages
|
||||||
* should be spilled when reached the condition described above. */
|
* should be spilled when reached the condition described above. */
|
||||||
MDBX_opt_spill_min_denominator,
|
MDBX_opt_spill_min_denominator,
|
||||||
|
|
||||||
|
/** \brief Controls the in-process how part of the parent transaction dirty
|
||||||
|
* pages will be spilled while start each child transaction.
|
||||||
|
*
|
||||||
|
* \details The `MDBX_opt_spill_parent4child_denominator` defines the
|
||||||
|
* denominator to determine how part of parent transaction dirty pages will be
|
||||||
|
* spilled explicitly while start each child transaction.
|
||||||
|
* Exactly `pages_to_spill = dirty_pages / N`,
|
||||||
|
* where `N` is the value set by `MDBX_opt_spill_parent4child_denominator`.
|
||||||
|
*
|
||||||
|
* For a stack of nested transactions each dirty page could be spilled only
|
||||||
|
* once, and parent's dirty pages couldn't be spilled while child
|
||||||
|
* transaction(s) are running. Therefore a child transaction could reach
|
||||||
|
* \ref MDBX_TXN_FULL when parent(s) transaction has spilled too less (and
|
||||||
|
* child reach the limit of dirty pages), either when parent(s) has spilled
|
||||||
|
* too more (since child can't spill already spilled pages). So there is no
|
||||||
|
* universal golden ratio.
|
||||||
|
*
|
||||||
|
* Should be in the range 0..255, where zero means no explicit spilling will
|
||||||
|
* be performed during starting nested transactions.
|
||||||
|
* Default is 0, i.e. by default no spilling performed during starting nested
|
||||||
|
* transactions, that correspond historically behaviour. */
|
||||||
|
MDBX_opt_spill_parent4child_denominator,
|
||||||
};
|
};
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
/** \ingroup c_settings */
|
/** \ingroup c_settings */
|
||||||
|
18
src/core.c
18
src/core.c
@ -6893,6 +6893,15 @@ int mdbx_txn_begin_ex(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags,
|
|||||||
MDBX_TXN_RDONLY | MDBX_WRITEMAP | MDBX_TXN_BLOCKED);
|
MDBX_TXN_RDONLY | MDBX_WRITEMAP | MDBX_TXN_BLOCKED);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
if (env->me_options.spill_parent4child_denominator) {
|
||||||
|
/* Spill dirty-pages of parent to provide dirtyroom for child txn */
|
||||||
|
rc = mdbx_txn_spill(parent, nullptr,
|
||||||
|
parent->tw.dirtylist->length /
|
||||||
|
env->me_options.spill_parent4child_denominator);
|
||||||
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
mdbx_tassert(parent, mdbx_audit_ex(parent, 0, false) == 0);
|
mdbx_tassert(parent, mdbx_audit_ex(parent, 0, false) == 0);
|
||||||
|
|
||||||
flags |= parent->mt_flags & (MDBX_TXN_RW_BEGIN_FLAGS | MDBX_TXN_SPILLS);
|
flags |= parent->mt_flags & (MDBX_TXN_RW_BEGIN_FLAGS | MDBX_TXN_SPILLS);
|
||||||
@ -9922,6 +9931,7 @@ __cold int mdbx_env_create(MDBX_env **penv) {
|
|||||||
env->me_options.dp_initial = env->me_options.dp_limit;
|
env->me_options.dp_initial = env->me_options.dp_limit;
|
||||||
env->me_options.spill_max_denominator = 8;
|
env->me_options.spill_max_denominator = 8;
|
||||||
env->me_options.spill_min_denominator = 8;
|
env->me_options.spill_min_denominator = 8;
|
||||||
|
env->me_options.spill_parent4child_denominator = 0;
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
const size_t os_psize = mdbx_syspagesize();
|
const size_t os_psize = mdbx_syspagesize();
|
||||||
@ -20462,6 +20472,11 @@ __cold int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option,
|
|||||||
return MDBX_EINVAL;
|
return MDBX_EINVAL;
|
||||||
env->me_options.spill_min_denominator = (uint8_t)value;
|
env->me_options.spill_min_denominator = (uint8_t)value;
|
||||||
break;
|
break;
|
||||||
|
case MDBX_opt_spill_parent4child_denominator:
|
||||||
|
if (unlikely(value > 255))
|
||||||
|
return MDBX_EINVAL;
|
||||||
|
env->me_options.spill_parent4child_denominator = (uint8_t)value;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return MDBX_EINVAL;
|
return MDBX_EINVAL;
|
||||||
@ -20522,6 +20537,9 @@ __cold int mdbx_env_get_option(const MDBX_env *env, const MDBX_option_t option,
|
|||||||
case MDBX_opt_spill_min_denominator:
|
case MDBX_opt_spill_min_denominator:
|
||||||
*value = env->me_options.spill_min_denominator;
|
*value = env->me_options.spill_min_denominator;
|
||||||
break;
|
break;
|
||||||
|
case MDBX_opt_spill_parent4child_denominator:
|
||||||
|
*value = env->me_options.spill_parent4child_denominator;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return MDBX_EINVAL;
|
return MDBX_EINVAL;
|
||||||
|
@ -985,6 +985,7 @@ struct MDBX_env {
|
|||||||
unsigned dp_initial;
|
unsigned dp_initial;
|
||||||
uint8_t spill_max_denominator;
|
uint8_t spill_max_denominator;
|
||||||
uint8_t spill_min_denominator;
|
uint8_t spill_min_denominator;
|
||||||
|
uint8_t spill_parent4child_denominator;
|
||||||
} me_options;
|
} me_options;
|
||||||
struct {
|
struct {
|
||||||
#if MDBX_LOCKING > 0
|
#if MDBX_LOCKING > 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user