Skip to content

Commit 65cde36

Browse files
committed
kernel: Move default cache constants to caches
They are not related to the txdb, so a better place for them is the new kernel and node cache file. Re-use the default amount of kernel cache for the default node cache.
1 parent 8826cae commit 65cde36

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

src/bitcoin-chainstate.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
#include <consensus/validation.h>
2121
#include <core_io.h>
22+
#include <kernel/caches.h>
2223
#include <logging.h>
2324
#include <node/blockstorage.h>
24-
#include <node/caches.h>
2525
#include <node/chainstate.h>
2626
#include <random.h>
2727
#include <script/sigcache.h>
@@ -123,7 +123,7 @@ int main(int argc, char* argv[])
123123
util::SignalInterrupt interrupt;
124124
ChainstateManager chainman{interrupt, chainman_opts, blockman_opts};
125125

126-
kernel::CacheSizes cache_sizes{nDefaultDbCache << 20};
126+
kernel::CacheSizes cache_sizes{DEFAULT_KERNEL_CACHE << 20};
127127
node::ChainstateLoadOptions options;
128128
auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options);
129129
if (status != node::ChainstateLoadStatus::SUCCESS) {

src/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
487487
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);
488488
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
489489
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
490-
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).", nMinDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
490+
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, DEFAULT_DB_CACHE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
491491
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);
492492
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);
493493
argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);

src/kernel/caches.h

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <algorithm>
1111

12+
//! Suggested default amount of cache reserved for the kernel (MiB)
13+
static constexpr int64_t DEFAULT_KERNEL_CACHE{450};
1214
//! Max memory allocated to block tree DB specific cache (bytes)
1315
static constexpr size_t MAX_BLOCK_DB_CACHE{2_MiB};
1416
//! Max memory allocated to coin DB specific cache (bytes)

src/node/caches.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <common/args.h>
88
#include <index/txindex.h>
99
#include <kernel/caches.h>
10-
#include <txdb.h>
1110

1211
#include <algorithm>
1312
#include <string>
@@ -22,8 +21,8 @@ static constexpr int64_t MAX_FILTER_INDEX_CACHE{1024};
2221
namespace node {
2322
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
2423
{
25-
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
26-
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
24+
int64_t nTotalCache = (args.GetIntArg("-dbcache", DEFAULT_DB_CACHE) << 20);
25+
nTotalCache = std::max(nTotalCache, MIN_DB_CACHE << 20);
2726
IndexCacheSizes sizes;
2827
sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? MAX_TX_INDEX_CACHE << 20 : 0);
2928
nTotalCache -= sizes.tx_index;

src/node/caches.h

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
class ArgsManager;
1313

14+
//! min. -dbcache (MiB)
15+
static constexpr int64_t MIN_DB_CACHE{4};
16+
//! -dbcache default (MiB)
17+
static constexpr int64_t DEFAULT_DB_CACHE{DEFAULT_KERNEL_CACHE};
18+
1419
namespace node {
1520
struct IndexCacheSizes {
1621
size_t tx_index{0};

src/qt/optionsdialog.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
#include <common/system.h>
1717
#include <interfaces/node.h>
18-
#include <node/chainstatemanager_args.h>
1918
#include <netbase.h>
20-
#include <txdb.h>
19+
#include <node/caches.h>
20+
#include <node/chainstatemanager_args.h>
2121
#include <util/strencodings.h>
2222

2323
#include <chrono>
@@ -95,7 +95,7 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
9595
ui->verticalLayout->setStretchFactor(ui->tabWidget, 1);
9696

9797
/* Main elements init */
98-
ui->databaseCache->setRange(nMinDbCache, std::numeric_limits<int>::max());
98+
ui->databaseCache->setRange(MIN_DB_CACHE, std::numeric_limits<int>::max());
9999
ui->threadsScriptVerif->setMinimum(-GetNumCores());
100100
ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);
101101
ui->pruneWarning->setVisible(false);

src/qt/optionsmodel.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <mapport.h>
1616
#include <net.h>
1717
#include <netbase.h>
18+
#include <node/caches.h>
1819
#include <node/chainstatemanager_args.h>
19-
#include <txdb.h> // for -dbcache defaults
2020
#include <util/string.h>
2121
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
2222
#include <wallet/wallet.h> // For DEFAULT_SPEND_ZEROCONF_CHANGE
@@ -470,7 +470,7 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
470470
suffix.empty() ? getOption(option, "-prev") :
471471
DEFAULT_PRUNE_TARGET_GB;
472472
case DatabaseCache:
473-
return qlonglong(SettingToInt(setting(), nDefaultDbCache));
473+
return qlonglong(SettingToInt(setting(), DEFAULT_DB_CACHE));
474474
case ThreadsScriptVerif:
475475
return qlonglong(SettingToInt(setting(), DEFAULT_SCRIPTCHECK_THREADS));
476476
case Listen:
@@ -733,7 +733,7 @@ void OptionsModel::checkAndMigrate()
733733
// see https://github.com/bitcoin/bitcoin/pull/8273
734734
// force people to upgrade to the new value if they are using 100MB
735735
if (settingsVersion < 130000 && settings.contains("nDatabaseCache") && settings.value("nDatabaseCache").toLongLong() == 100)
736-
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
736+
settings.setValue("nDatabaseCache", (qint64)DEFAULT_DB_CACHE);
737737

738738
settings.setValue(strSettingsVersionKey, CLIENT_VERSION);
739739
}

src/txdb.h

-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@
2121
class COutPoint;
2222
class uint256;
2323

24-
//! -dbcache default (MiB)
25-
static const int64_t nDefaultDbCache = 450;
2624
//! -dbbatchsize default (bytes)
2725
static const int64_t nDefaultDbBatchSize = 16 << 20;
28-
//! min. -dbcache (MiB)
29-
static const int64_t nMinDbCache = 4;
3026

3127
//! User-controlled performance and debug options.
3228
struct CoinsViewOptions {

0 commit comments

Comments
 (0)