Merge bitcoin/bitcoin#34692: Bump dbcache to 1 GiB

4ae9a10ada95ab8c1ab01472948d348d9538f3bb doc: add release notes for dbcache bump (Andrew Toth)
c510d126efb6ce9623e0e005829c13a110f65b0e doc: update dbcache default in reduce-memory.md (Andrew Toth)
027cac852796f643e2b6036fd3652dd3ca7785a5 qt: show GetDefaultDBCache() in settings (Andrew Toth)
5b34f251847a3c66b444959800b70e9863b10bbe dbcache: bump default from 450MB -> 1024MB if enough memory (Andrew Toth)

Pull request description:

  Alternative to #34641

  This increases the default `dbcache` value from `450MiB` to `1024MiB` if:
  - `dbcache` is unset
  - The system is 64 bit
  - At least 4GiB of RAM is detected

  Otherwise fallback to previous `450MiB` default.

  This should be simple enough to get into v31. The bump to 1GiB shows significant performance increases in #34641. It also alleviates concerns of too high default for steady state, and of lowering the current dbcache for systems with less RAM.

  This change only changes bitcoind behavior, while kernel still defaults to 450 MiB.

ACKs for top commit:
  ajtowns:
    ACK 4ae9a10ada95ab8c1ab01472948d348d9538f3bb
  kevkevinpal:
    reACK [4ae9a10](4ae9a10ada)
  svanstaa:
    ACK [4ae9a10](4ae9a10ada)
  achow101:
    ACK 4ae9a10ada95ab8c1ab01472948d348d9538f3bb
  sipa:
    ACK 4ae9a10ada95ab8c1ab01472948d348d9538f3bb

Tree-SHA512: ee3acf1fb08523ac80e37ec8f0caca226ffde6667f3a75ae6f4f4f54bc905a883ebcf1bf0e8a8a15c7cfabff96c23225825b3fff4506b9ab9936bf2c0a2c2513
This commit is contained in:
Ava Chow 2026-03-06 12:07:41 -08:00
commit c7a3ea2483
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
6 changed files with 25 additions and 4 deletions

View File

@ -6,7 +6,7 @@ There are a few parameters that can be dialed down to reduce the memory usage of
The size of some in-memory caches can be reduced. As caches trade off memory usage for performance, reducing these will usually have a negative effect on performance.
- `-dbcache=<n>` - the UTXO database cache size, this defaults to `450`. The unit is MiB (1024).
- `-dbcache=<n>` - the UTXO database cache size, this defaults to `1024` (or `450` if less than `4096` MiB system RAM is detected). The unit is MiB (1024).
- The minimum value for `-dbcache` is 4.
- A lower `-dbcache` makes initial sync time much longer. After the initial sync, the effect is less pronounced for most use-cases, unless fast validation of blocks is important, such as for mining.

View File

@ -0,0 +1,6 @@
## Updated settings
- The default `-dbcache` value has been increased to `1024` MiB from `450` MiB
on systems where at least `4096` MiB of RAM is detected.
This is a performance increase, but will use more memory.
To maintain the previous behaviour, set `-dbcache=450`.

View File

@ -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);

View File

@ -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)

View File

@ -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};

View File

@ -469,7 +469,7 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
suffix.empty() ? getOption(option, "-prev") :
DEFAULT_PRUNE_TARGET_GB;
case DatabaseCache:
return qlonglong(SettingTo<int64_t>(setting(), DEFAULT_DB_CACHE >> 20));
return qlonglong(SettingTo<int64_t>(setting(), node::GetDefaultDBCache() >> 20));
case ThreadsScriptVerif:
return qlonglong(SettingTo<int64_t>(setting(), DEFAULT_SCRIPTCHECK_THREADS));
case Listen: