Skip to content

Commit c43cc48

Browse files
committed
Merge bitcoin/bitcoin#32530: node: cap -maxmempool and -dbcache values for 32-bit
9f8e7b0 node: cap -dbcache to 1GiB on 32-bit architectures (Antoine Poinsot) 2c43b6a 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 9f8e7b0 instagibbs: utACK 9f8e7b0 dergoegge: Code review ACK 9f8e7b0 glozow: utACK 9f8e7b0 Tree-SHA512: cc7541b2c0040fc21a43916caec464dfb443af808f4e85deffa1187448ffff6edb0d69f9ebdb43915d145b8b4694d8465afe548f88da53ccebc9ce4b7c34b735
2 parents 4145a94 + 9f8e7b0 commit c43cc48

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/node/caches.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
static constexpr size_t MAX_TX_INDEX_CACHE{1024_MiB};
2020
//! Max memory allocated to all block filter index caches combined in bytes.
2121
static constexpr size_t MAX_FILTER_INDEX_CACHE{1024_MiB};
22+
//! Maximum dbcache size on 32-bit systems.
23+
static constexpr size_t MAX_32BIT_DBCACHE{1024_MiB};
2224

2325
namespace node {
2426
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
@@ -28,7 +30,8 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
2830
if (std::optional<int64_t> db_cache = args.GetIntArg("-dbcache")) {
2931
if (*db_cache < 0) db_cache = 0;
3032
uint64_t db_cache_bytes = SaturatingLeftShift<uint64_t>(*db_cache, 20);
31-
total_cache = std::max<size_t>(MIN_DB_CACHE, std::min<uint64_t>(db_cache_bytes, std::numeric_limits<size_t>::max()));
33+
constexpr auto max_db_cache{sizeof(void*) == 4 ? MAX_32BIT_DBCACHE : std::numeric_limits<size_t>::max()};
34+
total_cache = std::max<size_t>(MIN_DB_CACHE, std::min<uint64_t>(db_cache_bytes, max_db_cache));
3235
}
3336

3437
IndexCacheSizes index_sizes;

src/node/mempool_args.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ using common::AmountErrMsg;
2525
using kernel::MemPoolLimits;
2626
using kernel::MemPoolOptions;
2727

28+
//! Maximum mempool size on 32-bit systems.
29+
static constexpr int MAX_32BIT_MEMPOOL_MB{500};
30+
2831
namespace {
2932
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
3033
{
@@ -42,7 +45,13 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
4245
{
4346
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
4447

45-
if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
48+
if (auto mb = argsman.GetIntArg("-maxmempool")) {
49+
constexpr bool is_32bit{sizeof(void*) == 4};
50+
if (is_32bit && *mb > MAX_32BIT_MEMPOOL_MB) {
51+
return util::Error{Untranslated(strprintf("-maxmempool is set to %i but can't be over %i MB on 32-bit systems", *mb, MAX_32BIT_MEMPOOL_MB))};
52+
}
53+
mempool_opts.max_size_bytes = *mb * 1'000'000;
54+
}
4655

4756
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
4857

0 commit comments

Comments
 (0)