diff --git a/src/node/caches.h b/src/node/caches.h index 483521dfcfc..f4143bed44f 100644 --- a/src/node/caches.h +++ b/src/node/caches.h @@ -29,9 +29,9 @@ struct CacheSizes { kernel::CacheSizes kernel; }; CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0); -constexpr bool ShouldWarnOversizedDbCache(size_t dbcache, size_t total_ram) noexcept +constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept { - const size_t cap{(total_ram < 2_GiB) ? DEFAULT_DB_CACHE : (total_ram / 100) * 75}; + const uint64_t cap{(total_ram < 2_GiB) ? DEFAULT_DB_CACHE : (total_ram / 100) * 75}; return dbcache > cap; } diff --git a/src/test/caches_tests.cpp b/src/test/caches_tests.cpp index bdca1d40f82..69c42f0bbf1 100644 --- a/src/test/caches_tests.cpp +++ b/src/test/caches_tests.cpp @@ -22,23 +22,21 @@ BOOST_AUTO_TEST_CASE(oversized_dbcache_warning) BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2_GiB)); // Under cap BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2_GiB)); // Over cap - if constexpr (SIZE_MAX == UINT64_MAX) { - // 4 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4_GiB)); // Over cap + // 4 GiB RAM - cap is 75% + BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4_GiB)); // Under cap + BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4_GiB)); // Over cap - // 8 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8_GiB)); // Over cap + // 8 GiB RAM - cap is 75% + BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8_GiB)); // Under cap + BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8_GiB)); // Over cap - // 16 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10'000_MiB, /*total_ram=*/16_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15'000_MiB, /*total_ram=*/16_GiB)); // Over cap + // 16 GiB RAM - cap is 75% + BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10_GiB, /*total_ram=*/16_GiB)); // Under cap + BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15_GiB, /*total_ram=*/16_GiB)); // Over cap - // 32 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20'000_MiB, /*total_ram=*/32_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30'000_MiB, /*total_ram=*/32_GiB)); // Over cap - } + // 32 GiB RAM - cap is 75% + BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20_GiB, /*total_ram=*/32_GiB)); // Under cap + BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30_GiB, /*total_ram=*/32_GiB)); // Over cap } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/system_ram_tests.cpp b/src/test/system_ram_tests.cpp index 8ad622642f5..4eb4e1e3e52 100644 --- a/src/test/system_ram_tests.cpp +++ b/src/test/system_ram_tests.cpp @@ -21,12 +21,7 @@ BOOST_AUTO_TEST_CASE(total_ram) } BOOST_CHECK_GE(*total, 1000_MiB); - - if constexpr (SIZE_MAX == UINT64_MAX) { - // Upper bound check only on 64-bit: 32-bit systems can reasonably have max memory, - // but extremely large values on 64-bit likely indicate detection errors - BOOST_CHECK_LT(*total, 10'000'000_MiB); // >10 TiB memory is unlikely - } + BOOST_CHECK_LT(*total, 10'000_GiB); // ~10 TiB memory is unlikely } BOOST_AUTO_TEST_SUITE_END()