Bitcoin Core 31.99.0
P2P Digital Currency
caches_tests.cpp
Go to the documentation of this file.
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
13using namespace node;
14
15namespace {
16void CheckDbCacheWarnThreshold(uint64_t threshold, uint64_t total_ram)
17{
18 BOOST_CHECK(!ShouldWarnOversizedDbCache(threshold, total_ram));
19 BOOST_CHECK( ShouldWarnOversizedDbCache(threshold + 1, total_ram));
20}
21} // namespace
22
23BOOST_AUTO_TEST_SUITE(caches_tests)
24
25BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
26{
28
29 // Below DBCACHE_WARNING_RESERVED_RAM the existing fixed default dominates.
30 CheckDbCacheWarnThreshold(DEFAULT_KERNEL_CACHE, 1_GiB);
31 CheckDbCacheWarnThreshold(DEFAULT_KERNEL_CACHE, DBCACHE_WARNING_RESERVED_RAM);
32
33 // Above DBCACHE_WARNING_RESERVED_RAM the warning fires at 75% of the headroom.
34 CheckDbCacheWarnThreshold(((3_GiB - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, 3_GiB);
35
36 for (const auto total_ram : {8_GiB, 16_GiB, 32_GiB}) {
37 CheckDbCacheWarnThreshold(((total_ram - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, total_ram);
38 }
39}
40
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
BOOST_AUTO_TEST_SUITE_END()
static constexpr uint64_t DEFAULT_KERNEL_CACHE
Suggested default amount of cache reserved for the kernel (bytes)
Definition: caches.h:19
static constexpr uint64_t MIN_DBCACHE_BYTES
Minimum total database cache (bytes)
Definition: caches.h:15
Definition: messages.h:22
constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
Definition: caches.h:32
static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM
Reserved non-dbcache memory usage.
Definition: caches.h:18
#define BOOST_CHECK(expr)
Definition: object.cpp:16