-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin/bitcoin#31483: kernel: Move kernel-related cache consta…
…nts to kernel cache 2a92702 init: Use size_t consistently for cache sizes (TheCharlatan) 65cde36 kernel: Move default cache constants to caches (TheCharlatan) 8826cae kernel: Move non-kernel db cache size constants (TheCharlatan) e758b26 kernel: Move kernel-specific cache size options to kernel (TheCharlatan) d5e2c4a fuzz: Add fuzz test for checked and saturating add and left shift (TheCharlatan) c03a279 util: Add integer left shift helpers (TheCharlatan) 8bd5f8a [refactor] init: Simplify coinsdb cache calculation (TheCharlatan) 5db7d4d doc: Correct docstring describing max block tree db cache (TheCharlatan) Pull request description: Carrying non-kernel related fields in the cache sizes for the indexes is confusing for kernel library users. The cache sizes are set currently with magic numbers in bitcoin-chainstate. The comments for the cache size calculations are not completely clear. The constants for the cache sizes are also currently in `txdb.h`, which is not an ideal place for holding all cache size related constants. Solve these things by moving the kernel-specific cache size fields to their own struct and moving the constants to either the node or the kernel cache sizes. This slightly changes the way the cache is allocated if (and only if) the txindex and/or blockfilterindex is used. Since they are now given precedence over the block tree db cache, this results in a bit less cache being allocated to the block tree db, coinsdb and coins caches. The effect is negligible though, i.e. cache sizes with default dbcache reported through the logs are: master: ``` Cache configuration: * Using 2.0 MiB for block index database * Using 56.0 MiB for transaction index database * Using 49.0 MiB for basic block filter index database * Using 8.0 MiB for chain state database * Using 335.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space) ``` this PR: ``` Cache configuration: * Using 2.0 MiB for block index database * Using 56.2 MiB for transaction index database * Using 49.2 MiB for basic block filter index database * Using 8.0 MiB for chain state database * Using 334.5 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space) ``` --- This PR is part of the [libbitcoinkernel project](bitcoin/bitcoin#27587). ACKs for top commit: stickies-v: re-ACK 2a92702 ryanofsky: Code review ACK 2a92702. Changes since last review are fixing size options to use size_t instead of int64_t again, simplifying CheckedLeftShift more, and making other minor suggested cleanups hodlinator: re-ACK 2a92702 Tree-SHA512: 98376eaa0660b1b8c096a5ce1f3e7c8c30e7cd6644de36856c2d3e573108cfc9473c93ebb3952b7881047b5ae6c85c5b096e6726f30f35be58b98eca07c8c785
- Loading branch information
Showing
18 changed files
with
321 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024-present The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_KERNEL_CACHES_H | ||
#define BITCOIN_KERNEL_CACHES_H | ||
|
||
#include <util/byte_units.h> | ||
|
||
#include <algorithm> | ||
|
||
//! Suggested default amount of cache reserved for the kernel (bytes) | ||
static constexpr size_t DEFAULT_KERNEL_CACHE{450_MiB}; | ||
//! Max memory allocated to block tree DB specific cache (bytes) | ||
static constexpr size_t MAX_BLOCK_DB_CACHE{2_MiB}; | ||
//! Max memory allocated to coin DB specific cache (bytes) | ||
static constexpr size_t MAX_COINS_DB_CACHE{8_MiB}; | ||
|
||
namespace kernel { | ||
struct CacheSizes { | ||
size_t block_tree_db; | ||
size_t coins_db; | ||
size_t coins; | ||
|
||
CacheSizes(size_t total_cache) | ||
{ | ||
block_tree_db = std::min(total_cache / 8, MAX_BLOCK_DB_CACHE); | ||
total_cache -= block_tree_db; | ||
coins_db = std::min(total_cache / 2, MAX_COINS_DB_CACHE); | ||
total_cache -= coins_db; | ||
coins = total_cache; // the rest goes to the coins cache | ||
} | ||
}; | ||
} // namespace kernel | ||
|
||
#endif // BITCOIN_KERNEL_CACHES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.