Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2024-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_KERNEL_CACHES_H6#define BITCOIN_KERNEL_CACHES_H8#include <util/byte_units.h>10#include <algorithm>11#include <cstdint>12#include <limits>14//! Minimum total database cache (bytes)15inline constexpr uint64_t MIN_DBCACHE_BYTES{4_MiB};16//! Maximum total database cache on current architecture (bytes)17inline 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)19inline constexpr uint64_t DEFAULT_KERNEL_CACHE{450_MiB};20//! Default LevelDB write batch size21inline constexpr uint64_t DEFAULT_DB_CACHE_BATCH{32_MiB};23//! Max memory allocated to block tree DB specific cache (bytes)24inline constexpr uint64_t MAX_BLOCK_DB_CACHE{2_MiB};25//! Max memory allocated to coin DB specific cache (bytes)26inline constexpr uint64_t MAX_COINS_DB_CACHE{8_MiB};28namespace kernel {29struct CacheSizes {30uint64_t block_tree_db;31uint64_t coins_db;32uint64_t coins;34CacheSizes(uint64_t total_cache)35{36block_tree_db = std::min(total_cache / 8, MAX_BLOCK_DB_CACHE);37total_cache -= block_tree_db;38coins_db = std::min(total_cache / 2, MAX_COINS_DB_CACHE);39total_cache -= coins_db;40coins = total_cache; // the rest goes to the coins cache41}42};43} // namespace kernel45#endif // BITCOIN_KERNEL_CACHES_H