Skip to content

Commit 32cab91

Browse files
committed
Bump -dbcache default to 300MiB
Also cap the allocation for the leveldb-specific cache for the UTXO set to 8MiB. This avoids that the extra cache memory goes to the much less effective leveldb cache instead of our application-level cache.
1 parent 1922e5a commit 32cab91

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,10 +1216,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
12161216
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
12171217
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greated than nMaxDbcache
12181218
int64_t nBlockTreeDBCache = nTotalCache / 8;
1219-
if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", DEFAULT_TXINDEX))
1220-
nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB
1219+
nBlockTreeDBCache = std::min(nBlockTreeDBCache, (GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxBlockDBAndTxIndexCache : nMaxBlockDBCache) << 20);
12211220
nTotalCache -= nBlockTreeDBCache;
12221221
int64_t nCoinDBCache = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
1222+
nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); // cap total coins db cache
12231223
nTotalCache -= nCoinDBCache;
12241224
nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
12251225
LogPrintf("Cache configuration:\n");

src/txdb.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ class CCoinsViewDBCursor;
2222
class uint256;
2323

2424
//! -dbcache default (MiB)
25-
static const int64_t nDefaultDbCache = 100;
26-
//! max. -dbcache in (MiB)
25+
static const int64_t nDefaultDbCache = 300;
26+
//! max. -dbcache (MiB)
2727
static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
28-
//! min. -dbcache in (MiB)
28+
//! min. -dbcache (MiB)
2929
static const int64_t nMinDbCache = 4;
30+
//! Max memory allocated to block tree DB specific cache, if no -txindex (MiB)
31+
static const int64_t nMaxBlockDBCache = 2;
32+
//! Max memory allocated to block tree DB specific cache, if -txindex (MiB)
33+
// Unlike for the UTXO database, for the txindex scenario the leveldb cache make
34+
// a meaningful difference: https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991
35+
static const int64_t nMaxBlockDBAndTxIndexCache = 1024;
36+
//! Max memory allocated to coin DB specific cache (MiB)
37+
static const int64_t nMaxCoinsDBCache = 8;
3038

3139
struct CDiskTxPos : public CDiskBlockPos
3240
{

0 commit comments

Comments
 (0)