Branch data Line data Source code
1 : : // Copyright (c) The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or https://opensource.org/license/mit.
4 : :
5 : : #include <kernel/caches.h>
6 : : #include <node/caches.h>
7 : : #include <util/byte_units.h>
8 : :
9 : : #include <boost/test/unit_test.hpp>
10 : :
11 : : #include <cstdint>
12 : :
13 : : using namespace node;
14 : :
15 : : namespace {
16 : 6 : void CheckDbCacheWarnThreshold(uint64_t threshold, uint64_t total_ram)
17 : : {
18 [ + + + - ]: 14 : BOOST_CHECK(!ShouldWarnOversizedDbCache(threshold, total_ram));
19 [ + - ]: 12 : BOOST_CHECK( ShouldWarnOversizedDbCache(threshold + 1, total_ram));
20 : 6 : }
21 : : } // namespace
22 : :
23 : : BOOST_AUTO_TEST_SUITE(caches_tests)
24 : :
25 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
+ - + - -
+ + - + -
+ - + - +
- - + + -
+ - + - +
- + - - +
+ - + - +
- + - + -
- + + - +
- + - + -
+ - - + +
- ]
26 : : {
27 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(MIN_DBCACHE_BYTES, 1_GiB));
28 : :
29 : : // Below DBCACHE_WARNING_RESERVED_RAM the existing fixed default dominates.
30 : 1 : CheckDbCacheWarnThreshold(DEFAULT_KERNEL_CACHE, 1_GiB);
31 : 1 : CheckDbCacheWarnThreshold(DEFAULT_KERNEL_CACHE, DBCACHE_WARNING_RESERVED_RAM);
32 : :
33 : : // Above DBCACHE_WARNING_RESERVED_RAM the warning fires at 75% of the headroom.
34 : 1 : CheckDbCacheWarnThreshold(((3_GiB - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, 3_GiB);
35 : :
36 [ + + ]: 4 : for (const auto total_ram : {8_GiB, 16_GiB, 32_GiB}) {
37 : 3 : CheckDbCacheWarnThreshold(((total_ram - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, total_ram);
38 : : }
39 : 1 : }
40 : :
41 : : BOOST_AUTO_TEST_SUITE_END()
|