Skip to content

Commit e05cfb8

Browse files
fanquakeTom Trevethan
authored andcommitted
Merge bitcoin/bitcoin#32530: node: cap -maxmempool and -dbcache values for 32-bit
9f8e7b0b3b787b873045a4a8194e77d0b0a2b3b6 node: cap -dbcache to 1GiB on 32-bit architectures (Antoine Poinsot) 2c43b6adebbfabb3c8dd82fe821ce0a5d6173b3b init: cap -maxmempool to 500 MB on 32-bit systems (Antoine Poinsot) Pull request description: 32-bit architecture is limited to 4GiB of RAM, so it doesn't make sense to set a too high value. A too high value could cause an OOM unbeknownst to the user a while after startup as mempool / dbcache fills. ACKs for top commit: achow101: ACK 9f8e7b0b3b787b873045a4a8194e77d0b0a2b3b6 instagibbs: utACK 9f8e7b0b3b787b873045a4a8194e77d0b0a2b3b6 dergoegge: Code review ACK 9f8e7b0b3b787b873045a4a8194e77d0b0a2b3b6 glozow: utACK 9f8e7b0b3b787b873045a4a8194e77d0b0a2b3b6 Tree-SHA512: cc7541b2c0040fc21a43916caec464dfb443af808f4e85deffa1187448ffff6edb0d69f9ebdb43915d145b8b4694d8465afe548f88da53ccebc9ce4b7c34b735
1 parent 4929fec commit e05cfb8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static const bool DEFAULT_REST_ENABLE = false;
131131
#endif
132132

133133
static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
134+
static constexpr int MAX_32BIT_MEMPOOL_MB{500};
134135

135136
/**
136137
* The PID file facilities.
@@ -976,6 +977,10 @@ bool AppInitParameterInteraction(const ArgsManager& args)
976977
int64_t nMempoolSizeMin = args.GetIntArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40;
977978
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
978979
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(nMempoolSizeMin / 1000000.0)));
980+
constexpr bool is_32bit{sizeof(void*) == 4};
981+
if (is_32bit && nMempoolSizeMax > MAX_32BIT_MEMPOOL_MB) {
982+
return InitError(strprintf(_("-maxmempool is set to %i but can't be over %i MB on 32-bit systems"), nMempoolSizeMax, MAX_32BIT_MEMPOOL_MB));
983+
}
979984
// incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool
980985
// and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
981986
if (args.IsArgSet("-incrementalrelayfee")) {

src/node/caches.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
#include <util/system.h>
99
#include <validation.h>
1010

11+
//! Maximum dbcache size on 32-bit systems.
12+
static constexpr int64_t MAX_32BIT_DBCACHE = 1ULL << 30; // 1 GiB
13+
1114
namespace node {
1215
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
1316
{
1417
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
1518
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
1619
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
20+
if (sizeof(void*) == 4) nTotalCache = std::min(nTotalCache, MAX_32BIT_DBCACHE);
1721
CacheSizes sizes;
1822
sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
1923
nTotalCache -= sizes.block_tree_db;

0 commit comments

Comments
 (0)