MCPcopy Create free account
hub / github.com/ElementsProject/elements / CalculateCacheSizes

Function CalculateCacheSizes

src/node/caches.cpp:15–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14namespace node {
15CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
16{
17 int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
18 nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
19 nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
20 if (sizeof(void*) == 4) nTotalCache = std::min(nTotalCache, MAX_32BIT_DBCACHE);
21 CacheSizes sizes;
22 sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
23 nTotalCache -= sizes.block_tree_db;
24 sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
25 nTotalCache -= sizes.tx_index;
26 sizes.filter_index = 0;
27 if (n_indexes > 0) {
28 int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
29 sizes.filter_index = max_cache / n_indexes;
30 nTotalCache -= sizes.filter_index * n_indexes;
31 }
32 sizes.coins_db = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
33 sizes.coins_db = std::min(sizes.coins_db, nMaxCoinsDBCache << 20); // cap total coins db cache
34 nTotalCache -= sizes.coins_db;
35 sizes.coins = nTotalCache; // the rest goes to in-memory cache
36 return sizes;
37}
38} // namespace node

Callers 2

AppInitMainFunction · 0.85
ChainTestingSetupMethod · 0.85

Calls 2

GetIntArgMethod · 0.80
GetBoolArgMethod · 0.80

Tested by 1

ChainTestingSetupMethod · 0.68