Files
bitcoin/src/test/caches_tests.cpp
Lőrinc d164a04342 node: smooth oversized -dbcache warnings
The oversized `-dbcache` warning currently switches from a fixed `450 MiB` threshold below `2 GiB` of RAM to `75%` of total RAM at `2 GiB`.
This creates a cliff where a small increase in RAM can raise the warning threshold to about `1536 MiB`.

Apply the `75%` factor only to RAM above a `2 GiB` reserve while keeping `DEFAULT_DB_CACHE` as the minimum threshold.
This removes the cliff: the threshold stays at the default until the percentage term exceeds it, then grows by `0.75 MiB` per additional MiB of RAM.

This also aligns better with the recently merged parallel input prevout fetcher which performs better with slightly lower dbcache memory.

Co-authored-by: Bortlesboat <Bortlesboat@users.noreply.github.com>
2026-07-09 11:11:02 -07:00

41 lines
1.3 KiB
C++

// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit.
#include <node/caches.h>
#include <util/byte_units.h>
#include <boost/test/unit_test.hpp>
#include <cstdint>
using namespace node;
namespace {
void CheckDbCacheWarnThreshold(uint64_t threshold, uint64_t total_ram)
{
BOOST_CHECK(!ShouldWarnOversizedDbCache(threshold, total_ram));
BOOST_CHECK( ShouldWarnOversizedDbCache(threshold + 1, total_ram));
}
} // namespace
BOOST_AUTO_TEST_SUITE(caches_tests)
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
{
BOOST_CHECK(!ShouldWarnOversizedDbCache(MIN_DB_CACHE, 1_GiB));
// Below DBCACHE_WARNING_RESERVED_RAM the existing fixed default dominates.
CheckDbCacheWarnThreshold(DEFAULT_DB_CACHE, 1_GiB);
CheckDbCacheWarnThreshold(DEFAULT_DB_CACHE, DBCACHE_WARNING_RESERVED_RAM);
// Above DBCACHE_WARNING_RESERVED_RAM the warning fires at 75% of the headroom.
CheckDbCacheWarnThreshold(((3_GiB - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, 3_GiB);
for (const auto total_ram : {8_GiB, 16_GiB, 32_GiB}) {
CheckDbCacheWarnThreshold(((total_ram - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, total_ram);
}
}
BOOST_AUTO_TEST_SUITE_END()