Bitcoin Core 31.99.0
P2P Digital Currency
caches.h
Go to the documentation of this file.
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
15class ArgsManager;
16
18static constexpr uint64_t MIN_DB_CACHE{4_MiB};
20static constexpr uint64_t DEFAULT_DB_CACHE{DEFAULT_KERNEL_CACHE};
22static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB};
23
24namespace node {
25uint64_t GetDefaultDBCache();
27 uint64_t tx_index{0};
28 uint64_t filter_index{0};
29 uint64_t txospender_index{0};
30};
31struct CacheSizes {
34};
35CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
36constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
37{
38 const uint64_t available_ram{total_ram > DBCACHE_WARNING_RESERVED_RAM ? total_ram - DBCACHE_WARNING_RESERVED_RAM : 0};
39 const uint64_t cap{std::max<uint64_t>(DEFAULT_DB_CACHE, (available_ram / 4) * 3)};
40 return dbcache > cap;
41}
42
43void LogOversizedDbCache(const ArgsManager& args) noexcept;
44} // namespace node
45
46#endif // BITCOIN_NODE_CACHES_H
ArgsManager & args
Definition: bitcoind.cpp:280
static constexpr uint64_t DEFAULT_KERNEL_CACHE
Suggested default amount of cache reserved for the kernel (bytes)
Definition: caches.h:14
Definition: messages.h:21
CacheSizes CalculateCacheSizes(const ArgsManager &args, size_t n_indexes)
Definition: caches.cpp:61
void LogOversizedDbCache(const ArgsManager &args) noexcept
Definition: caches.cpp:89
constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
Definition: caches.h:36
uint64_t GetDefaultDBCache()
Definition: caches.cpp:40
static constexpr uint64_t DEFAULT_DB_CACHE
-dbcache default (bytes)
Definition: caches.h:20
static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM
Reserved non-dbcache memory usage.
Definition: caches.h:22
static constexpr uint64_t MIN_DB_CACHE
min. -dbcache (bytes)
Definition: caches.h:18
IndexCacheSizes index
Definition: caches.h:32
kernel::CacheSizes kernel
Definition: caches.h:33
uint64_t txospender_index
Definition: caches.h:29
uint64_t filter_index
Definition: caches.h:28
uint64_t tx_index
Definition: caches.h:27