forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaches.h
More file actions
42 lines (34 loc) · 1.23 KB
/
Copy pathcaches.h
File metadata and controls
42 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2021-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_NODE_CACHES_H
#define BITCOIN_NODE_CACHES_H
#include <kernel/caches.h>
#include <util/byte_units.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
class ArgsManager;
//! Reserved non-dbcache memory usage.
static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB};
namespace node {
uint64_t GetDefaultDBCache();
struct IndexCacheSizes {
uint64_t tx_index{0};
uint64_t filter_index{0};
uint64_t txospender_index{0};
};
struct CacheSizes {
IndexCacheSizes index;
kernel::CacheSizes kernel;
};
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
{
const uint64_t available_ram{total_ram > DBCACHE_WARNING_RESERVED_RAM ? total_ram - DBCACHE_WARNING_RESERVED_RAM : 0};
const uint64_t cap{std::max(DEFAULT_KERNEL_CACHE, (available_ram / 4) * 3)};
return dbcache > cap;
}
void LogOversizedDbCache(const ArgsManager& args) noexcept;
} // namespace node
#endif // BITCOIN_NODE_CACHES_H