Coverage Report

Created: 2026-07-23 20:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/kernel/caches.h
Line
Count
Source
1
// Copyright (c) 2024-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_KERNEL_CACHES_H
6
#define BITCOIN_KERNEL_CACHES_H
7
8
#include <util/byte_units.h>
9
10
#include <algorithm>
11
#include <cstdint>
12
13
//! Suggested default amount of cache reserved for the kernel (bytes)
14
static constexpr uint64_t DEFAULT_KERNEL_CACHE{450_MiB};
15
//! Default LevelDB write batch size
16
static constexpr uint64_t DEFAULT_DB_CACHE_BATCH{32_MiB};
17
18
//! Max memory allocated to block tree DB specific cache (bytes)
19
static constexpr uint64_t MAX_BLOCK_DB_CACHE{2_MiB};
20
//! Max memory allocated to coin DB specific cache (bytes)
21
static constexpr uint64_t MAX_COINS_DB_CACHE{8_MiB};
22
23
namespace kernel {
24
struct CacheSizes {
25
    uint64_t block_tree_db;
26
    uint64_t coins_db;
27
    uint64_t coins;
28
29
    CacheSizes(uint64_t total_cache)
30
1.22k
    {
31
1.22k
        block_tree_db = std::min(total_cache / 8, MAX_BLOCK_DB_CACHE);
32
1.22k
        total_cache -= block_tree_db;
33
1.22k
        coins_db = std::min(total_cache / 2, MAX_COINS_DB_CACHE);
34
1.22k
        total_cache -= coins_db;
35
1.22k
        coins = total_cache; // the rest goes to the coins cache
36
1.22k
    }
37
};
38
} // namespace kernel
39
40
#endif // BITCOIN_KERNEL_CACHES_H