mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-22 23:04:09 +02:00
(total_cache / 4) + (1 << 23) is at least 8 MiB and nMaxCoinsDBCache is also 8 MiB, so the minimum between the two will always be nMaxCoinsDBCache. This is just a simplification and not changing the result of the calculation. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
33 lines
1.3 KiB
C++
33 lines
1.3 KiB
C++
// Copyright (c) 2021-2022 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <node/caches.h>
|
|
|
|
#include <common/args.h>
|
|
#include <index/txindex.h>
|
|
#include <txdb.h>
|
|
|
|
namespace node {
|
|
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
|
|
{
|
|
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
|
|
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
|
|
CacheSizes sizes;
|
|
sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
|
|
nTotalCache -= sizes.block_tree_db;
|
|
sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
|
|
nTotalCache -= sizes.tx_index;
|
|
sizes.filter_index = 0;
|
|
if (n_indexes > 0) {
|
|
int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
|
|
sizes.filter_index = max_cache / n_indexes;
|
|
nTotalCache -= sizes.filter_index * n_indexes;
|
|
}
|
|
sizes.coins_db = std::min(nTotalCache / 2, nMaxCoinsDBCache << 20);
|
|
nTotalCache -= sizes.coins_db;
|
|
sizes.coins = nTotalCache; // the rest goes to in-memory cache
|
|
return sizes;
|
|
}
|
|
} // namespace node
|