LCOV - code coverage report
Current view: top level - src/kernel - caches.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 8 8
Test Date: 2025-01-19 05:08:01 Functions: 100.0 % 1 1
Branches: 50.0 % 4 2

             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                 :             : 
      12                 :             : //! Suggested default amount of cache reserved for the kernel (bytes)
      13                 :             : static constexpr size_t DEFAULT_KERNEL_CACHE{450_MiB};
      14                 :             : //! Max memory allocated to block tree DB specific cache (bytes)
      15                 :             : static constexpr size_t MAX_BLOCK_DB_CACHE{2_MiB};
      16                 :             : //! Max memory allocated to coin DB specific cache (bytes)
      17                 :             : static constexpr size_t MAX_COINS_DB_CACHE{8_MiB};
      18                 :             : 
      19                 :             : namespace kernel {
      20                 :             : struct CacheSizes {
      21                 :             :     size_t block_tree_db;
      22                 :             :     size_t coins_db;
      23                 :             :     size_t coins;
      24                 :             : 
      25                 :        1112 :     CacheSizes(size_t total_cache)
      26                 :        1112 :     {
      27         [ -  + ]:        1112 :         block_tree_db = std::min(total_cache / 8, MAX_BLOCK_DB_CACHE);
      28                 :        1112 :         total_cache -= block_tree_db;
      29         [ -  + ]:        1112 :         coins_db = std::min(total_cache / 2, MAX_COINS_DB_CACHE);
      30                 :        1112 :         total_cache -= coins_db;
      31                 :        1112 :         coins = total_cache; // the rest goes to the coins cache
      32                 :        1112 :     }
      33                 :             : };
      34                 :             : } // namespace kernel
      35                 :             : 
      36                 :             : #endif // BITCOIN_KERNEL_CACHES_H
        

Generated by: LCOV version 2.0-1