Branch data Line data Source code
1 : : // Copyright (c) 2021-present The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #ifndef BITCOIN_NODE_CACHES_H
6 : : #define BITCOIN_NODE_CACHES_H
7 : :
8 : : #include <kernel/caches.h>
9 : : #include <util/byte_units.h>
10 : :
11 : : #include <algorithm>
12 : : #include <cstddef>
13 : : #include <cstdint>
14 : :
15 : : class ArgsManager;
16 : :
17 : : //! Reserved non-dbcache memory usage.
18 : : static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB};
19 : :
20 : : namespace node {
21 : : uint64_t GetDefaultDBCache();
22 : : struct IndexCacheSizes {
23 : : uint64_t tx_index{0};
24 : : uint64_t filter_index{0};
25 : : uint64_t txospender_index{0};
26 : : };
27 : : struct CacheSizes {
28 : : IndexCacheSizes index;
29 : : kernel::CacheSizes kernel;
30 : : };
31 : : CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
32 : 13 : constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
33 : : {
34 : 13 : const uint64_t available_ram{total_ram > DBCACHE_WARNING_RESERVED_RAM ? total_ram - DBCACHE_WARNING_RESERVED_RAM : 0};
35 [ + + ]: 7 : const uint64_t cap{std::max(DEFAULT_KERNEL_CACHE, (available_ram / 4) * 3)};
36 [ - + ]: 13 : return dbcache > cap;
[ + - + - ]
37 : : }
38 : :
39 : : void LogOversizedDbCache(const ArgsManager& args) noexcept;
40 : : } // namespace node
41 : :
42 : : #endif // BITCOIN_NODE_CACHES_H
|