diff --git a/src/common/system.cpp b/src/common/system.cpp index ca7b857d983..1b1bff171cb 100644 --- a/src/common/system.cpp +++ b/src/common/system.cpp @@ -111,7 +111,7 @@ int GetNumCores() return std::thread::hardware_concurrency(); } -std::optional GetTotalRAM() +std::optional TryGetTotalRam() { [[maybe_unused]] auto clamp{[](uint64_t v) { return size_t(std::min(v, uint64_t{std::numeric_limits::max()})); }}; #ifdef WIN32 diff --git a/src/common/system.h b/src/common/system.h index a3100fecbc1..e0d1b917671 100644 --- a/src/common/system.h +++ b/src/common/system.h @@ -35,6 +35,6 @@ int GetNumCores(); /** * Return the total RAM available on the current system, if detectable. */ -std::optional GetTotalRAM(); +std::optional TryGetTotalRam(); #endif // BITCOIN_COMMON_SYSTEM_H diff --git a/src/node/caches.cpp b/src/node/caches.cpp index fc13b8a295c..ea69c717760 100644 --- a/src/node/caches.cpp +++ b/src/node/caches.cpp @@ -40,7 +40,7 @@ namespace node { uint64_t GetDefaultDBCache() { if constexpr (sizeof(void*) >= 8) { - if (GetTotalRAM().value_or(0) >= HIGH_DEFAULT_DBCACHE_MIN_TOTAL_RAM) { + if (TryGetTotalRam().value_or(0) >= HIGH_DEFAULT_DBCACHE_MIN_TOTAL_RAM) { return HIGH_DEFAULT_DBCACHE; } } @@ -88,7 +88,7 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) void LogOversizedDbCache(const ArgsManager& args) noexcept { - if (const auto total_ram{GetTotalRAM()}) { + if (const auto total_ram{TryGetTotalRam()}) { const uint64_t db_cache{CalculateDbCacheBytes(args)}; if (ShouldWarnOversizedDbCache(db_cache, *total_ram)) { InitWarning(bilingual_str{tfm::format(_("A %zu MiB dbcache may be too large for a system memory of only %zu MiB."), diff --git a/src/test/system_ram_tests.cpp b/src/test/system_ram_tests.cpp index 4eb4e1e3e52..79e4ebfbeb6 100644 --- a/src/test/system_ram_tests.cpp +++ b/src/test/system_ram_tests.cpp @@ -14,7 +14,7 @@ BOOST_AUTO_TEST_SUITE(system_ram_tests) BOOST_AUTO_TEST_CASE(total_ram) { - const auto total{GetTotalRAM()}; + const auto total{TryGetTotalRam()}; if (!total) { BOOST_WARN_MESSAGE(false, "skipping total_ram: total RAM unknown"); return;