From ce56548c63404877f8e3bcc21764bd23fb063887 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Fri, 19 Sep 2025 13:29:24 +0200 Subject: [PATCH] system: improve handling around GetTotalRAM() This patch achieves two things: 1. Fix unused variable warning (https://github.com/bitcoin/bitcoin/pull/33333#discussion_r2362493046) 2. Enable GetTotalRAM() on other platforms where it was tested to work. Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Github-Pull: #33435 Rebased-From: 337a6e738616781f81504275bac8ed7bcf8068df --- src/common/system.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/system.cpp b/src/common/system.cpp index cf032adfced..35a6f4415bc 100644 --- a/src/common/system.cpp +++ b/src/common/system.cpp @@ -113,10 +113,15 @@ int GetNumCores() std::optional GetTotalRAM() { - auto clamp{[](uint64_t v) { return size_t(std::min(v, uint64_t{std::numeric_limits::max()})); }}; + [[maybe_unused]] auto clamp{[](uint64_t v) { return size_t(std::min(v, uint64_t{std::numeric_limits::max()})); }}; #ifdef WIN32 if (MEMORYSTATUSEX m{}; (m.dwLength = sizeof(m), GlobalMemoryStatusEx(&m))) return clamp(m.ullTotalPhys); -#elif defined(__linux__) || defined(__APPLE__) +#elif defined(__APPLE__) || \ + defined(__FreeBSD__) || \ + defined(__NetBSD__) || \ + defined(__OpenBSD__) || \ + defined(__illumos__) || \ + defined(__linux__) if (long p{sysconf(_SC_PHYS_PAGES)}, s{sysconf(_SC_PAGESIZE)}; p > 0 && s > 0) return clamp(1ULL * p * s); #endif return std::nullopt;