mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-24 12:41:41 -05:00

This is an extraction of ArgsManager related functions from util/system into their own common file. Config file related functions are moved to common/config.cpp. The background of this commit is an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager. The ArgsManager belongs into the common library, since the kernel library should not depend on it. See doc/design/libraries.md for more information on this rationale.
34 lines
1.6 KiB
C++
34 lines
1.6 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
|
|
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
|
|
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, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
|
|
sizes.coins_db = std::min(sizes.coins_db, nMaxCoinsDBCache << 20); // cap total coins db cache
|
|
nTotalCache -= sizes.coins_db;
|
|
sizes.coins = nTotalCache; // the rest goes to in-memory cache
|
|
return sizes;
|
|
}
|
|
} // namespace node
|