From 136e4080c22eeb3b5b67ddb81b1cd814156a8190 Mon Sep 17 00:00:00 2001 From: TheCharlatan Date: Fri, 22 Nov 2024 22:44:17 +0100 Subject: [PATCH] kernel: Move non-kernel db cache size constants These have nothing to do with the txdb, so move them out and into the node caches. --- src/node/caches.cpp | 11 +++++++++-- src/txdb.h | 6 ------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/node/caches.cpp b/src/node/caches.cpp index d930f38605..a771af46fc 100644 --- a/src/node/caches.cpp +++ b/src/node/caches.cpp @@ -12,17 +12,24 @@ #include #include +// Unlike for the UTXO database, for the txindex scenario the leveldb cache make +// a meaningful difference: https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991 +//! Max memory allocated to tx index DB specific cache in MiB. +static constexpr int64_t MAX_TX_INDEX_CACHE{1024}; +//! Max memory allocated to all block filter index caches combined in MiB. +static constexpr int64_t MAX_FILTER_INDEX_CACHE{1024}; + 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 IndexCacheSizes sizes; - sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0); + sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE << 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); + 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; } diff --git a/src/txdb.h b/src/txdb.h index 671cbd1286..a92f19631c 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -29,12 +29,6 @@ static const int64_t nDefaultDbBatchSize = 16 << 20; static const int64_t nMinDbCache = 4; //! Max memory allocated to block tree DB specific cache (MiB) static const int64_t nMaxBlockDBCache = 2; -// Unlike for the UTXO database, for the txindex scenario the leveldb cache make -// a meaningful difference: https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991 -//! Max memory allocated to tx index DB specific cache in MiB. -static const int64_t nMaxTxIndexCache = 1024; -//! Max memory allocated to all block filter index caches combined in MiB. -static const int64_t max_filter_index_cache = 1024; //! Max memory allocated to coin DB specific cache (MiB) static const int64_t nMaxCoinsDBCache = 8;