Skip to content

Commit 1b55e07

Browse files
committed
Make threshold for flushing more conservative.
Always leave a reasonable buffer of 50MB for usage from newly connected block (once over 50%) and increase the high water mark buffer to 200MB.
1 parent f33afd3 commit 1b55e07

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/txdb.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ class uint256;
2323

2424
//! Compensate for extra memory peak (x1.5-x1.9) at flush time.
2525
static constexpr int DB_PEAK_USAGE_FACTOR = 2;
26-
//! No need to flush if at least this much space still available.
27-
static constexpr int MAX_BLOCK_COINSDB_USAGE = 100 * DB_PEAK_USAGE_FACTOR;
26+
//! No need to periodic flush if at least this much space still available.
27+
static constexpr int MAX_BLOCK_COINSDB_USAGE = 200 * DB_PEAK_USAGE_FACTOR;
28+
//! Always periodic flush if less than this much space still available.
29+
static constexpr int MIN_BLOCK_COINSDB_USAGE = 50 * DB_PEAK_USAGE_FACTOR;
2830
//! -dbcache default (MiB)
2931
static const int64_t nDefaultDbCache = 450;
3032
//! max. -dbcache (MiB)

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,8 +2007,9 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode, int n
20072007
int64_t nMempoolSizeMax = GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
20082008
int64_t cacheSize = pcoinsTip->DynamicMemoryUsage() * DB_PEAK_USAGE_FACTOR;
20092009
int64_t nTotalSpace = nCoinCacheUsage + std::max<int64_t>(nMempoolSizeMax - nMempoolUsage, 0);
2010-
// The cache is large and we're within 10% and 100 MiB of the limit, but we have time now (not in the middle of a block processing).
2011-
bool fCacheLarge = mode == FLUSH_STATE_PERIODIC && cacheSize > std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024);
2010+
// The cache is large and we're within 10% and 200 MiB or 50% and 50MiB of the limit, but we have time now (not in the middle of a block processing).
2011+
bool fCacheLarge = mode == FLUSH_STATE_PERIODIC && cacheSize > std::min(std::max(nTotalSpace / 2, nTotalSpace - MIN_BLOCK_COINSDB_USAGE * 1024 * 1024),
2012+
std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024));
20122013
// The cache is over the limit, we have to write now.
20132014
bool fCacheCritical = mode == FLUSH_STATE_IF_NEEDED && cacheSize > nTotalSpace;
20142015
// It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash.

0 commit comments

Comments
 (0)