LCOV - code coverage report
Current view: top level - src/node - caches.h Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 4 4
Test Date: 2026-07-19 08:02:30 Functions: - 0 0
Branches: 75.0 % 8 6

             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                 :             : //! min. -dbcache (bytes)
      18                 :             : static constexpr uint64_t MIN_DB_CACHE{4_MiB};
      19                 :             : //! -dbcache default (bytes)
      20                 :             : static constexpr uint64_t DEFAULT_DB_CACHE{DEFAULT_KERNEL_CACHE};
      21                 :             : //! Reserved non-dbcache memory usage.
      22                 :             : static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB};
      23                 :             : 
      24                 :             : namespace node {
      25                 :             : uint64_t GetDefaultDBCache();
      26                 :             : struct IndexCacheSizes {
      27                 :             :     uint64_t tx_index{0};
      28                 :             :     uint64_t filter_index{0};
      29                 :             :     uint64_t txospender_index{0};
      30                 :             : };
      31                 :             : struct CacheSizes {
      32                 :             :     IndexCacheSizes index;
      33                 :             :     kernel::CacheSizes kernel;
      34                 :             : };
      35                 :             : CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
      36                 :        1113 : constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
      37                 :             : {
      38                 :        1113 :     const uint64_t available_ram{total_ram > DBCACHE_WARNING_RESERVED_RAM ? total_ram - DBCACHE_WARNING_RESERVED_RAM : 0};
      39         [ +  + ]:        1107 :     const uint64_t cap{std::max<uint64_t>(DEFAULT_DB_CACHE, (available_ram / 4) * 3)};
      40   [ +  +  +  - ]:        1113 :     return dbcache > cap;
                 [ -  + ]
      41                 :             : }
      42                 :             : 
      43                 :             : void LogOversizedDbCache(const ArgsManager& args) noexcept;
      44                 :             : } // namespace node
      45                 :             : 
      46                 :             : #endif // BITCOIN_NODE_CACHES_H
        

Generated by: LCOV version 2.0-1