From 5b34f251847a3c66b444959800b70e9863b10bbe Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Fri, 27 Feb 2026 09:17:00 -0500 Subject: [PATCH] dbcache: bump default from 450MB -> 1024MB if enough memory If dbcache is unset, bump default from 450MB to 1024MB on 64-bit systems that have at least 4GB of detected RAM. --- src/init.cpp | 2 +- src/node/caches.cpp | 16 +++++++++++++++- src/node/caches.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index adc1dacc757..417546058d4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -503,7 +503,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc) argsman.AddArg("-conf=", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-datadir=", "Specify data directory", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS); argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", DEFAULT_DB_CACHE_BATCH), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); - argsman.AddArg("-dbcache=", strprintf("Maximum database cache size MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE >> 20, DEFAULT_DB_CACHE >> 20), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + argsman.AddArg("-dbcache=", strprintf("Maximum database cache size MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE >> 20, node::GetDefaultDBCache() >> 20), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-includeconf=", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-allowignoredconf", strprintf("For backwards compatibility, treat an unused %s file in the datadir as a warning, not an error.", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-loadblock=", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); diff --git a/src/node/caches.cpp b/src/node/caches.cpp index 5e285e8907b..cb8afbc967d 100644 --- a/src/node/caches.cpp +++ b/src/node/caches.cpp @@ -27,8 +27,22 @@ static constexpr size_t MAX_FILTER_INDEX_CACHE{1024_MiB}; static constexpr size_t MAX_TXOSPENDER_INDEX_CACHE{1024_MiB}; //! Maximum dbcache size on 32-bit systems. static constexpr size_t MAX_32BIT_DBCACHE{1024_MiB}; +//! Larger default dbcache on 64-bit systems with enough RAM. +static constexpr size_t HIGH_DEFAULT_DBCACHE{1024_MiB}; +//! Minimum detected RAM required for HIGH_DEFAULT_DBCACHE. +static constexpr uint64_t HIGH_DEFAULT_DBCACHE_MIN_TOTAL_RAM{4096ULL << 20}; namespace node { +size_t GetDefaultDBCache() +{ + if constexpr (sizeof(void*) >= 8) { + if (GetTotalRAM().value_or(0) >= HIGH_DEFAULT_DBCACHE_MIN_TOTAL_RAM) { + return HIGH_DEFAULT_DBCACHE; + } + } + return DEFAULT_DB_CACHE; +} + size_t CalculateDbCacheBytes(const ArgsManager& args) { if (auto db_cache{args.GetIntArg("-dbcache")}) { @@ -37,7 +51,7 @@ size_t CalculateDbCacheBytes(const ArgsManager& args) constexpr auto max_db_cache{sizeof(void*) == 4 ? MAX_32BIT_DBCACHE : std::numeric_limits::max()}; return std::max(MIN_DB_CACHE, std::min(db_cache_bytes, max_db_cache)); } - return DEFAULT_DB_CACHE; + return GetDefaultDBCache(); } CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) diff --git a/src/node/caches.h b/src/node/caches.h index 8ea2fbffc0b..62f097411ba 100644 --- a/src/node/caches.h +++ b/src/node/caches.h @@ -18,6 +18,7 @@ static constexpr size_t MIN_DB_CACHE{4_MiB}; static constexpr size_t DEFAULT_DB_CACHE{DEFAULT_KERNEL_CACHE}; namespace node { +size_t GetDefaultDBCache(); struct IndexCacheSizes { size_t tx_index{0}; size_t filter_index{0};