From 8bbb7b8bf8e3b2b6465f318ec102cc5275e5bf8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Wed, 27 Aug 2025 21:20:35 -0700 Subject: [PATCH 1/2] refactor: Extract default batch size into kernel The constant for the default batch size is moved to `kernel/caches.h` to consolidate kernel-related cache constants. --- src/init.cpp | 2 +- src/kernel/caches.h | 3 +++ src/txdb.h | 11 ++++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index b6b52e2cea5..b29a2634b25 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -496,7 +496,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc) argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); 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)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, 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("-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); diff --git a/src/kernel/caches.h b/src/kernel/caches.h index 33ae604772b..63bb44c54b5 100644 --- a/src/kernel/caches.h +++ b/src/kernel/caches.h @@ -11,6 +11,9 @@ //! Suggested default amount of cache reserved for the kernel (bytes) static constexpr size_t DEFAULT_KERNEL_CACHE{450_MiB}; +//! Default LevelDB write batch size +static constexpr size_t DEFAULT_DB_CACHE_BATCH{16_MiB}; + //! Max memory allocated to block tree DB specific cache (bytes) static constexpr size_t MAX_BLOCK_DB_CACHE{2_MiB}; //! Max memory allocated to coin DB specific cache (bytes) diff --git a/src/txdb.h b/src/txdb.h index 968b7c27810..ea0cf9d77e5 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -21,16 +22,12 @@ class COutPoint; class uint256; -//! -dbbatchsize default (bytes) -static const int64_t nDefaultDbBatchSize = 16 << 20; - //! User-controlled performance and debug options. struct CoinsViewOptions { //! Maximum database write batch size in bytes. - size_t batch_write_bytes = nDefaultDbBatchSize; - //! If non-zero, randomly exit when the database is flushed with (1/ratio) - //! probability. - int simulate_crash_ratio = 0; + size_t batch_write_bytes{DEFAULT_DB_CACHE_BATCH}; + //! If non-zero, randomly exit when the database is flushed with (1/ratio) probability. + int simulate_crash_ratio{0}; }; /** CCoinsView backed by the coin database (chainstate/) */ From b6f8c48946cbfceb066de660c485ae1bd2c27cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Wed, 27 Aug 2025 21:24:51 -0700 Subject: [PATCH 2/2] coins: increase default `dbbatchsize` to 32 MiB The default database write batch size is increased from 16 MiB to 32 MiB to improve I/O efficiency and performance during UTXO flushes, particularly during Initial Block Download and `assumeutxo` loads. On systems with slower I/O, a larger batch size reduces overhead from numerous small writes. Measurements show this change provides a modest performance improvement on most hardware during a critical section, with a minimal peak memory increase (approx. 75 MiB on default settings). --- src/kernel/caches.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/caches.h b/src/kernel/caches.h index 63bb44c54b5..aa3214e5df7 100644 --- a/src/kernel/caches.h +++ b/src/kernel/caches.h @@ -12,7 +12,7 @@ //! Suggested default amount of cache reserved for the kernel (bytes) static constexpr size_t DEFAULT_KERNEL_CACHE{450_MiB}; //! Default LevelDB write batch size -static constexpr size_t DEFAULT_DB_CACHE_BATCH{16_MiB}; +static constexpr size_t DEFAULT_DB_CACHE_BATCH{32_MiB}; //! Max memory allocated to block tree DB specific cache (bytes) static constexpr size_t MAX_BLOCK_DB_CACHE{2_MiB};