mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 09:53:47 +01:00
init: Correct coins db cache size setting
The chainstate caches are currently re-balanced on startup even in the non-assumeutxo case, leading to the database being needlessly re-opened and its cache re-allocated. Similar to `InitCoinsCache` and `m_coinstip_cache_size_bytes` the `m_coinsdb_cache_size_bytes` should be set in `InitCoinsDB`. Together with only conservatively setting the cache values when a assumeutxo chainstate is present, this allows for skipping the cache re-balance during initialization in the normal non-assumeutxo case.
This commit is contained in:
parent
e569eb8d91
commit
3a4a788ee0
@ -95,11 +95,12 @@ static ChainstateLoadResult CompleteChainstateInitialization(
|
|||||||
assert(chainman.m_total_coinstip_cache > 0);
|
assert(chainman.m_total_coinstip_cache > 0);
|
||||||
assert(chainman.m_total_coinsdb_cache > 0);
|
assert(chainman.m_total_coinsdb_cache > 0);
|
||||||
|
|
||||||
// Conservative value which is arbitrarily chosen, as it will ultimately be changed
|
// If running with multiple chainstates, limit the cache sizes with a
|
||||||
// by a call to `chainman.MaybeRebalanceCaches()`. We just need to make sure
|
// discount factor. If discounted the actual cache size will be
|
||||||
// that the sum of the two caches (40%) does not exceed the allowable amount
|
// recalculated by `chainman.MaybeRebalanceCaches()`. The discount factor
|
||||||
// during this temporary initialization state.
|
// is conservatively chosen such that the sum of the caches does not exceed
|
||||||
double init_cache_fraction = 0.2;
|
// the allowable amount during this temporary initialization state.
|
||||||
|
double init_cache_fraction = chainman.GetAll().size() > 1 ? 0.2 : 1.0;
|
||||||
|
|
||||||
// At this point we're either in reindex or we've loaded a useful
|
// At this point we're either in reindex or we've loaded a useful
|
||||||
// block tree into BlockIndex()!
|
// block tree into BlockIndex()!
|
||||||
|
@ -1972,6 +1972,8 @@ void Chainstate::InitCoinsDB(
|
|||||||
.obfuscate = true,
|
.obfuscate = true,
|
||||||
.options = m_chainman.m_options.coins_db},
|
.options = m_chainman.m_options.coins_db},
|
||||||
m_chainman.m_options.coins_view);
|
m_chainman.m_options.coins_view);
|
||||||
|
|
||||||
|
m_coinsdb_cache_size_bytes = cache_size_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chainstate::InitCoinsCache(size_t cache_size_bytes)
|
void Chainstate::InitCoinsCache(size_t cache_size_bytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user