Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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 <common/args.h>
8#include <index/txindex.h>
9#include <txdb.h>
10
11namespace node {
14 (args.GetIntArg("-dbcache", DEFAULT_DB_CACHE_MB) << 20);
15 // total cache cannot be less than MIN_DB_CACHE_MB
16 nTotalCache = std::max(nTotalCache, MIN_DB_CACHE_MB << 20);
17 // total cache cannot be greater than MAX_DB_CACHE_MB
18 nTotalCache = std::min(nTotalCache, MAX_DB_CACHE_MB << 20);
19
22 std::min(nTotalCache / 8, MAX_BLOCK_DB_CACHE_MB << 20);
23 nTotalCache -= sizes.block_tree_db;
24 sizes.tx_index =
25 std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX)
27 : 0);
28 nTotalCache -= sizes.tx_index;
29 sizes.filter_index = 0;
30
31 if (n_indexes > 0) {
33 std::min(nTotalCache / 8, MAX_FILTER_INDEX_CACHE_MB << 20);
34 sizes.filter_index = max_cache / n_indexes;
35 nTotalCache -= sizes.filter_index * n_indexes;
36 }
37
38 // use 25%-50% of the remainder for disk cache
39 sizes.coins_db = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23));
40 // cap total coins db cache
41 sizes.coins_db = std::min(sizes.coins_db, MAX_COINS_DB_CACHE_MB << 20);
42 nTotalCache -= sizes.coins_db;
43 // the rest goes to in-memory cache
44 sizes.coins = nTotalCache;
45
46 return sizes;
47}
48} // namespace node
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition args.cpp:526
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition args.cpp:556
Definition init.h:28
CacheSizes CalculateCacheSizes(const ArgsManager &args, size_t n_indexes)
Definition caches.cpp:12
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
int64_t block_tree_db
Definition caches.h:15
static constexpr int64_t MAX_TX_INDEX_CACHE_MB
Max memory allocated to block tree DB specific cache, if -txindex (MiB)
Definition txdb.h:49
static constexpr int64_t MAX_DB_CACHE_MB
max. -dbcache (MiB)
Definition txdb.h:38
static constexpr int64_t MAX_BLOCK_DB_CACHE_MB
Max memory allocated to block tree DB specific cache, if no -txindex (MiB)
Definition txdb.h:44
static constexpr int64_t MIN_DB_CACHE_MB
min. -dbcache (MiB)
Definition txdb.h:36
static constexpr int64_t MAX_COINS_DB_CACHE_MB
Max memory allocated to coin DB specific cache (MiB)
Definition txdb.h:53
static constexpr int64_t DEFAULT_DB_CACHE_MB
-dbcache default (MiB)
Definition txdb.h:40
static constexpr int64_t MAX_FILTER_INDEX_CACHE_MB
Max memory allocated to all block filter index caches combined in MiB.
Definition txdb.h:51
static constexpr bool DEFAULT_TXINDEX
Definition txindex.h:15