LCOV - code coverage report
Current view: top level - src/kernel - caches.h (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 100.0 % 8 8
Test Date: 2026-08-07 06:33:33 Functions: 100.0 % 1 1
Branches: 100.0 % 4 4

             Branch data     Line data    Source code
       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                 :             : #include <limits>
      13                 :             : 
      14                 :             : //! Minimum total database cache (bytes)
      15                 :             : static constexpr uint64_t MIN_DBCACHE_BYTES{4_MiB};
      16                 :             : //! Maximum total database cache on current architecture (bytes)
      17                 :             : static constexpr uint64_t MAX_DBCACHE_BYTES{sizeof(void*) == 4 ? 1_GiB : std::numeric_limits<uint64_t>::max()};
      18                 :             : //! Suggested default amount of cache reserved for the kernel (bytes)
      19                 :             : static constexpr uint64_t DEFAULT_KERNEL_CACHE{450_MiB};
      20                 :             : //! Default LevelDB write batch size
      21                 :             : static constexpr uint64_t DEFAULT_DB_CACHE_BATCH{32_MiB};
      22                 :             : 
      23                 :             : //! Max memory allocated to block tree DB specific cache (bytes)
      24                 :             : static constexpr uint64_t MAX_BLOCK_DB_CACHE{2_MiB};
      25                 :             : //! Max memory allocated to coin DB specific cache (bytes)
      26                 :             : static constexpr uint64_t MAX_COINS_DB_CACHE{8_MiB};
      27                 :             : 
      28                 :             : namespace kernel {
      29                 :             : struct CacheSizes {
      30                 :             :     uint64_t block_tree_db;
      31                 :             :     uint64_t coins_db;
      32                 :             :     uint64_t coins;
      33                 :             : 
      34                 :         190 :     CacheSizes(uint64_t total_cache)
      35                 :         190 :     {
      36         [ +  + ]:         190 :         block_tree_db = std::min(total_cache / 8, MAX_BLOCK_DB_CACHE);
      37                 :         190 :         total_cache -= block_tree_db;
      38         [ +  + ]:         179 :         coins_db = std::min(total_cache / 2, MAX_COINS_DB_CACHE);
      39                 :         190 :         total_cache -= coins_db;
      40                 :         178 :         coins = total_cache; // the rest goes to the coins cache
      41                 :         179 :     }
      42                 :             : };
      43                 :             : } // namespace kernel
      44                 :             : 
      45                 :             : #endif // BITCOIN_KERNEL_CACHES_H
        

Generated by: LCOV version 2.0-1