Skip to content

Commit 9f8e7b0

Browse files
committed
node: cap -dbcache to 1GiB on 32-bit architectures
32-bit architecture is limited to 4GiB, so it doesn't make sense to set a too high value. Since this setting is performance critical, pick an arbitrary value higher than for -maxmempool but still reasonable.
1 parent 2c43b6a commit 9f8e7b0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
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;

0 commit comments

Comments
 (0)