dbcache: bump default from 450MB -> 1024MB if enough memory
What changed, and why it matters
This change simply raises the default database cache size for Bitcoin Core from 450 MB to 1,024 MB on 64-bit computers that have at least 4 GB of RAM. It is a performance tuning change, not a security fix. There is no indication it addresses a vulnerability or was triggered by a security report.
No security action required. Treat as a routine performance/configuration change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces node::GetDefaultDBCache(), which returns 1024 MiB on 64-bit systems with >=4 GB total RAM, otherwise falls back to the existing DEFAULT_DB_CACHE (450 MiB). It updates the -dbcache help text and CalculateDbCacheBytes() to use the new dynamic default. No bounds checks, memory allocation paths, or cryptographic code are modified.
Changed components
src/node/caches.cppsrc/node/caches.hsrc/init.cppInspect captured patch +17 / −2
diff --git a/src/init.cpp b/src/init.cpp
index adc1dacc..41754605 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -503,7 +503,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-conf=<file>", 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=<dir>", "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=<n>", strprintf("Maximum database cache size <n> 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=<n>", strprintf("Maximum database cache size <n> 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=<file>", "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=<file>", "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 5e285e89..cb8afbc9 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<size_t>::max()};
return std::max<size_t>(MIN_DB_CACHE, std::min<uint64_t>(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 8ea2fbff..62f09741 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};
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.