@@ -1056,18 +1056,20 @@ bool AppInit2(boost::thread_group& threadGroup)
1056
1056
}
1057
1057
1058
1058
// cache size calculations
1059
- size_t nTotalCache = (GetArg (" -dbcache" , nDefaultDbCache) << 20 );
1060
- if (nTotalCache < (nMinDbCache << 20 ))
1061
- nTotalCache = (nMinDbCache << 20 ); // total cache cannot be less than nMinDbCache
1062
- else if (nTotalCache > (nMaxDbCache << 20 ))
1063
- nTotalCache = (nMaxDbCache << 20 ); // total cache cannot be greater than nMaxDbCache
1064
- size_t nBlockTreeDBCache = nTotalCache / 8 ;
1059
+ int64_t nTotalCache = (GetArg (" -dbcache" , nDefaultDbCache) << 20 );
1060
+ nTotalCache = std::max (nTotalCache, nMinDbCache << 20 ); // total cache cannot be less than nMinDbCache
1061
+ nTotalCache = std::min (nTotalCache, nMaxDbCache << 20 ); // total cache cannot be greated than nMaxDbcache
1062
+ int64_t nBlockTreeDBCache = nTotalCache / 8 ;
1065
1063
if (nBlockTreeDBCache > (1 << 21 ) && !GetBoolArg (" -txindex" , false ))
1066
1064
nBlockTreeDBCache = (1 << 21 ); // block tree db cache shouldn't be larger than 2 MiB
1067
1065
nTotalCache -= nBlockTreeDBCache;
1068
- size_t nCoinDBCache = nTotalCache / 2 ; // use half of the remaining cache for coindb cache
1066
+ int64_t nCoinDBCache = std::min ( nTotalCache / 2 , (nTotalCache / 4 ) + ( 1 << 23 )) ; // use 25%-50% of the remainder for disk cache
1069
1067
nTotalCache -= nCoinDBCache;
1070
- nCoinCacheUsage = nTotalCache;
1068
+ nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
1069
+ LogPrintf (" Cache configuration:\n " );
1070
+ LogPrintf (" * Using %.1fMiB for block index database\n " , nBlockTreeDBCache * (1.0 / 1024 / 1024 ));
1071
+ LogPrintf (" * Using %.1fMiB for chain state database\n " , nCoinDBCache * (1.0 / 1024 / 1024 ));
1072
+ LogPrintf (" * Using %.1fMiB for in-memory UTXO set\n " , nCoinCacheUsage * (1.0 / 1024 / 1024 ));
1071
1073
1072
1074
bool fLoaded = false ;
1073
1075
while (!fLoaded ) {
0 commit comments