Files
bitcoin/src/node/caches.h
Lőrinc d164a04342 node: smooth oversized -dbcache warnings
The oversized `-dbcache` warning currently switches from a fixed `450 MiB` threshold below `2 GiB` of RAM to `75%` of total RAM at `2 GiB`.
This creates a cliff where a small increase in RAM can raise the warning threshold to about `1536 MiB`.

Apply the `75%` factor only to RAM above a `2 GiB` reserve while keeping `DEFAULT_DB_CACHE` as the minimum threshold.
This removes the cliff: the threshold stays at the default until the percentage term exceeds it, then grows by `0.75 MiB` per additional MiB of RAM.

This also aligns better with the recently merged parallel input prevout fetcher which performs better with slightly lower dbcache memory.

Co-authored-by: Bortlesboat <Bortlesboat@users.noreply.github.com>
2026-07-09 11:11:02 -07:00

47 lines
1.4 KiB
C++

// Copyright (c) 2021-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_NODE_CACHES_H
#define BITCOIN_NODE_CACHES_H
#include <kernel/caches.h>
#include <util/byte_units.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
class ArgsManager;
//! min. -dbcache (bytes)
static constexpr uint64_t MIN_DB_CACHE{4_MiB};
//! -dbcache default (bytes)
static constexpr uint64_t DEFAULT_DB_CACHE{DEFAULT_KERNEL_CACHE};
//! Reserved non-dbcache memory usage.
static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM{2_GiB};
namespace node {
uint64_t GetDefaultDBCache();
struct IndexCacheSizes {
uint64_t tx_index{0};
uint64_t filter_index{0};
uint64_t txospender_index{0};
};
struct CacheSizes {
IndexCacheSizes index;
kernel::CacheSizes kernel;
};
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
{
const uint64_t available_ram{total_ram > DBCACHE_WARNING_RESERVED_RAM ? total_ram - DBCACHE_WARNING_RESERVED_RAM : 0};
const uint64_t cap{std::max<uint64_t>(DEFAULT_DB_CACHE, (available_ram / 4) * 3)};
return dbcache > cap;
}
void LogOversizedDbCache(const ArgsManager& args) noexcept;
} // namespace node
#endif // BITCOIN_NODE_CACHES_H