From dd679142594916044314304a15a9d3b523b3e712 Mon Sep 17 00:00:00 2001 From: Peter Shugalev Date: Mon, 15 Apr 2024 10:17:16 +0200 Subject: [PATCH] Optimize loading block index guts if low on memory (Linux only) --- src/txdb.cpp | 14 +++++++++++++- src/txdb.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index e554c15de0..acb6463381 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -17,6 +17,10 @@ #include +#ifdef __linux__ +#include +#endif + static const char DB_COIN = 'C'; static const char DB_COINS = 'c'; static const char DB_BLOCK_FILES = 'f'; @@ -365,6 +369,14 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::functionValid()) { boost::this_thread::interruption_point(); @@ -423,7 +435,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::functionnHeight >= firstInLastNBlocksHeight) { lastNBlocks.insert(std::pair(pindexNew->nHeight, pindexNew)); - if (lastNBlocks.size() > DEFAULT_BLOCKINDEX_NUMBER_OF_BLOCKS_TO_CHECK) { + if (lastNBlocks.size() > nBlocksToCheck) { // pop the first element from the map auto firstElement = lastNBlocks.begin(); auto elementToPop = firstElement++; diff --git a/src/txdb.h b/src/txdb.h index 591a4e9987..fb35aa4c9f 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -47,6 +47,8 @@ static const int64_t nMaxCoinsDBCache = 8; static const bool DEFAULT_FULL_BLOCKINDEX_CHECK = false; //! If not doing full check of block index, check only N of the latest blocks static const int DEFAULT_BLOCKINDEX_NUMBER_OF_BLOCKS_TO_CHECK = 10000; +//! Check fewer blocks if low on memory +static const int DEFAULT_BLOCKINDEX_LOWMEM_NUMBER_OF_BLOCKS_TO_CHECK = 50; struct CDiskTxPos : public CDiskBlockPos {