dbcache.h raw

   1  // Copyright (c) The Limenka 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 LIMENKA_NODE_DBCACHE_H
   6  #define LIMENKA_NODE_DBCACHE_H
   7  
   8  #include <util/byte_units.h>
   9  
  10  #include <cstdint>
  11  #include <limits>
  12  #include <optional>
  13  
  14  //! min. -dbcache (bytes)
  15  static constexpr uint64_t MIN_DBCACHE_BYTES{4_MiB};
  16  //! Automatic -dbcache floor (bytes)
  17  static constexpr uint64_t MIN_DEFAULT_DBCACHE{100_MiB};
  18  //! Automatic -dbcache cap (bytes)
  19  static constexpr uint64_t MAX_DEFAULT_DBCACHE{2_GiB};
  20  //! Assumed total RAM when we cannot determine it.
  21  static constexpr uint64_t FALLBACK_RAM_BYTES{SIZE_MAX > UINT32_MAX ? 4_GiB : 2_GiB};
  22  //! Reserved non-dbcache memory usage.
  23  static constexpr uint64_t RESERVED_RAM{2_GiB};
  24  //! Maximum dbcache size on current architecture.
  25  static constexpr uint64_t MAX_DBCACHE_BYTES{SIZE_MAX > UINT32_MAX ? std::numeric_limits<uint64_t>::max() : 1_GiB};
  26  
  27  namespace node {
  28  size_t GetTotalRam() noexcept;
  29  size_t GetDefaultDBCache(std::optional<uint64_t> total_ram = {}) noexcept;
  30  
  31  bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept;
  32  } // namespace node
  33  
  34  #endif // LIMENKA_NODE_DBCACHE_H
  35