Skip to content

Commit b0260ee

Browse files
committed
Cache tweak and logging improvements
1 parent 9693d7e commit b0260ee

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/init.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,18 +1052,20 @@ bool AppInit2(boost::thread_group& threadGroup)
10521052
}
10531053

10541054
// cache size calculations
1055-
size_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
1056-
if (nTotalCache < (nMinDbCache << 20))
1057-
nTotalCache = (nMinDbCache << 20); // total cache cannot be less than nMinDbCache
1058-
else if (nTotalCache > (nMaxDbCache << 20))
1059-
nTotalCache = (nMaxDbCache << 20); // total cache cannot be greater than nMaxDbCache
1060-
size_t nBlockTreeDBCache = nTotalCache / 8;
1055+
int64_t nTotalCache = (GetArg("-dbcache", nDefaultDbCache) << 20);
1056+
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
1057+
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greated than nMaxDbcache
1058+
int64_t nBlockTreeDBCache = nTotalCache / 8;
10611059
if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false))
10621060
nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB
10631061
nTotalCache -= nBlockTreeDBCache;
1064-
size_t nCoinDBCache = nTotalCache / 2; // use half of the remaining cache for coindb cache
1062+
int64_t nCoinDBCache = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
10651063
nTotalCache -= nCoinDBCache;
1066-
nCoinCacheUsage = nTotalCache;
1064+
nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
1065+
LogPrintf("Cache configuration:\n");
1066+
LogPrintf("* Using %.1fMiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
1067+
LogPrintf("* Using %.1fMiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
1068+
LogPrintf("* Using %.1fMiB for in-memory UTXO set\n", nCoinCacheUsage * (1.0 / 1024 / 1024));
10671069

10681070
bool fLoaded = false;
10691071
while (!fLoaded) {

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,10 +1961,10 @@ void static UpdateTip(CBlockIndex *pindexNew) {
19611961
nTimeBestReceived = GetTime();
19621962
mempool.AddTransactionsUpdated(1);
19631963

1964-
LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%u\n", __func__,
1964+
LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__,
19651965
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx,
19661966
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
1967-
Checkpoints::GuessVerificationProgress(chainActive.Tip()), (unsigned int)pcoinsTip->GetCacheSize());
1967+
Checkpoints::GuessVerificationProgress(chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
19681968

19691969
cvBlockChange.notify_all();
19701970

src/txdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class uint256;
2222
//! -dbcache default (MiB)
2323
static const int64_t nDefaultDbCache = 100;
2424
//! max. -dbcache in (MiB)
25-
static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 4096 : 1024;
25+
static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
2626
//! min. -dbcache in (MiB)
2727
static const int64_t nMinDbCache = 4;
2828

0 commit comments

Comments
 (0)