Bitcoin Core  22.99.0
P2P Digital Currency
caches.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <node/caches.h>
6 
7 #include <txdb.h>
8 #include <util/system.h>
9 #include <validation.h>
10 
11 namespace node {
13 {
14  int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
15  nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
16  nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
17  CacheSizes sizes;
18  sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
19  nTotalCache -= sizes.block_tree_db;
20  sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
21  nTotalCache -= sizes.tx_index;
22  sizes.filter_index = 0;
23  if (n_indexes > 0) {
24  int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
25  sizes.filter_index = max_cache / n_indexes;
26  nTotalCache -= sizes.filter_index * n_indexes;
27  }
28  sizes.coins_db = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
29  sizes.coins_db = std::min(sizes.coins_db, nMaxCoinsDBCache << 20); // cap total coins db cache
30  nTotalCache -= sizes.coins_db;
31  sizes.coins = nTotalCache; // the rest goes to in-memory cache
32  return sizes;
33 }
34 } // namespace node
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:597
node::CacheSizes
Definition: caches.h:14
node::CacheSizes::coins
int64_t coins
Definition: caches.h:17
nMaxDbCache
static const int64_t nMaxDbCache
max. -dbcache (MiB)
Definition: txdb.h:31
nMaxTxIndexCache
static const int64_t nMaxTxIndexCache
Max memory allocated to block tree DB specific cache, if -txindex (MiB)
Definition: txdb.h:39
nDefaultDbCache
static const int64_t nDefaultDbCache
-dbcache default (MiB)
Definition: txdb.h:27
node::CalculateCacheSizes
CacheSizes CalculateCacheSizes(const ArgsManager &args, size_t n_indexes)
Definition: caches.cpp:12
nMinDbCache
static const int64_t nMinDbCache
min. -dbcache (MiB)
Definition: txdb.h:33
max_filter_index_cache
static const int64_t max_filter_index_cache
Max memory allocated to all block filter index caches combined in MiB.
Definition: txdb.h:41
node::CacheSizes::block_tree_db
int64_t block_tree_db
Definition: caches.h:15
nMaxCoinsDBCache
static const int64_t nMaxCoinsDBCache
Max memory allocated to coin DB specific cache (MiB)
Definition: txdb.h:43
node::CacheSizes::filter_index
int64_t filter_index
Definition: caches.h:19
system.h
ArgsManager
Definition: system.h:158
node::CacheSizes::tx_index
int64_t tx_index
Definition: caches.h:18
node
Definition: init.h:22
caches.h
DEFAULT_TXINDEX
static const bool DEFAULT_TXINDEX
Definition: validation.h:83
node::CacheSizes::coins_db
int64_t coins_db
Definition: caches.h:16
nMaxBlockDBCache
static const int64_t nMaxBlockDBCache
Max memory allocated to block tree DB specific cache, if no -txindex (MiB)
Definition: txdb.h:35
ArgsManager::GetIntArg
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: system.cpp:591
txdb.h
args
ArgsManager args
Definition: notifications.cpp:36