Summary
Oversized allocations can cause out-of-memory errors or heavy swapping, grinding the system to a halt.
Fix
Added a minimal system helper to query total physical RAM on Linux/macOS/Windows (on unsupported platforms we just disable this warning completely). The added test checks if the value is roughly correct by checking if the CI platforms are returning any value and if the value is at least 1 GB (as a simple property test checking if the unit size is correct, e.g. doesn’t return megabytes).
Details
LogOversizedDbCache()
now emits a startup warning if the configured -dbcache
exceeds a cap derived from system RAM, using the same parsing/clamping as cache sizing via CalculateDbCacheBytes()
. This isn’t meant as a recommended setting, rather a likely upper limit.
Note that we’re not modifying the set value, just issuing a warning.
Also note that the 75% calculation is rounded for the last two numbers since we have to divide first before multiplying, otherwise we wouldn’t stay inside size_t
on 32-bit systems - and this was simpler than casting back and forth.
We could have chosen the remaining free memory for the warning (e.g. warn if free memory is less than 1 GiB), but this is just a heuristic, we assumed that on systems with a lot of memory, other processes are also running, while memory constrained ones run only Core.
Cap
If total RAM < 2 GiB, cap is DEFAULT_DB_CACHE
(450 MiB
), otherwise it’s 75% of total RAM.
The threshold is chosen to be close to values commonly used in raspiblitz for common setups:
Total RAM | dbcache (MiB) |
raspiblitz % | proposed cap (MiB) |
---|---|---|---|
1 GiB | 512 | 50.0% | 450* |
2 GiB | 1536 | 75.0% | 1536 |
4 GiB | 2560 | 62.5% | 3072 |
8 GiB | 4096 | 50.0% | 6144 |
16 GiB | 4096 | 25.0% | 12288 |
32 GiB | 4096 | 12.5% | 24576 |
Umbrel issues also mention 75% being the upper limit.
Reproducer
Starting bitcoind
on an 8 GiB rpi4b with a dbcache of 7 GiB:
./build/bin/bitcoind -dbcache=7000
warns now as follows:
02025-09-07T17:24:29Z [warning] A 7000 MiB dbcache may be too large for a system memory of only 7800 MiB.
12025-09-07T17:24:29Z Cache configuration:
22025-09-07T17:24:29Z * Using 2.0 MiB for block index database
32025-09-07T17:24:29Z * Using 8.0 MiB for chain state database
42025-09-07T17:24:29Z * Using 6990.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)
The warning should now be available via RPC as wel, run any of these against the running bitcoind
:
0./build/bin/bitcoin-cli -rpcwait getblockchaininfo | grep dbcache
1./build/bin/bitcoin-cli -rpcwait getnetworkinfo | grep dbcache
which should show:
“A 7000 MiB dbcache may be too large for a system memory of only 7800 MiB.”,
Manual testing
Besides the godbolt reproducers for the new total memory method, we also tested the warnings manually on:
- Apple M4 Max, macOS 15.6.1
- Intel Core i9-9900K, Ubuntu 24.04.2 LTS
- Raspberry Pi 4 Model B, Armbian Linux 6.12.22-current-bcm2711
- Intel Xeon x64, Windows 11 Home Version 24H2, OS Build 26100.4351