Skip to content

node: scale default -dbcache with system RAM - #34641

Closed
l0rinc wants to merge 9 commits into
bitcoin:masterfrom
l0rinc:l0rinc/dynamic-dbcache
Closed

l0rinc wants to merge 9 commits into
bitcoin:masterfrom
l0rinc:l0rinc/dynamic-dbcache

Conversation

@l0rinc

@l0rinc l0rinc commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

-dbcache controls how much RAM Bitcoin Core uses for the in-memory view of the UTXO set, while the authoritative chainstate remains on disk.
The default is still the fixed 450 MiB value, chosen almost a decade ago, even though chainstate size and typical hardware profiles have changed significantly since then.

In practice, a fixed 450 MiB default is often too conservative on modern systems, where larger cache sizes can reduce flush churn and disk roundtrips during validation, especially in IBD. At the same time, memory pressure remains important on smaller systems.

Historical changes

Date dbcache change PR
2016-07-06 100 -> 300 #8273: Bump -dbcache default to 300MiB
2017-04-05 300 -> 450 #10133: Clean up calculations of pcoinsTip memory usage
2026-02-27 450 -> 1024 #34692: Bump dbcache to 1 GiB

IRC

The discussion converged on avoiding a single new fixed -dbcache value and moving to RAM-aware defaults instead, balancing performance gains on modern hardware against OOM risk on lower-memory systems.

IRC log links

Node provider defaults

  • RaspiBlitz sets a higher dbcache during IBD (when no other apps are running), then lowers it afterward.
  • Start9 can set the default dynamically based on total RAM; currently creates a user task to lower dbcache after IBD if it was increased.
  • MyNode automatically adjusts based on system memory (4 GB RAM → 1 GB cache, 8 GB RAM → 2.5 GB cache, 16 GB RAM → 4 GB cache) and also scales max mempool size.
  • Umbrel used to default to 50% RAM during IBD then reduce to 200 MiB post-IBD, but removed that logic because dedicating that much RAM caused issues when users ran other apps; now ships Core defaults.

Containerization

Container memory constraints may or may not be reflected by RAM detection.
We have considered adding container-detection but decided against it. Startup logs show detected/assumed system memory so users can set -dbcache explicitly when needed.

Fix

Measuring -reindex-chainstate on different machines indicates that 450-1024-2048 jumps are all very relevant after which the effects taper off.

Replace the fixed default with a RAM-aware policy:

$$\text{default\_dbcache}=\mathrm{clamp}\left(100\,\mathrm{MiB},\ 0.25\cdot\left(\text{system RAM}-2\,\mathrm{GiB}\right),\ 2\,\mathrm{GiB}\right)$$

If system RAM cannot be determined, assume 4 GiB on 64-bit builds and 2 GiB on 32-bit builds.
Manual -dbcache values are unchanged and still override the automatic default.

Warning threshold update

Oversized -dbcache warnings are kept and aligned with the new policy.
The previous low-memory/high-memory cliff at FALLBACK_RAM_BYTESis replaced by a single monotonic rule that re-uses the same RESERVED_RAM budget the auto default already accounts for:

$$\text{warn if } \mathit{dbcache} > \max\!\left(\mathit{default\_dbcache},\ 0.75 \cdot \max\!\left(\text{system RAM} - 2\,\mathrm{GiB},\ 0\right)\right)$$

The auto default uses 25% of the post-RESERVED_RAM headroom; warning at 75% of that headroom keeps a 25% margin above RESERVED_RAM for OS / mempool variance, while ensuring the auto default never trips its own warning.

Performance measurements

reindex-chainstate

image
Machine 450 MiB 1000 MiB 1536 MiB 2000 MiB 3000 MiB
M4 Max 16c, 64Gi, SSD 5h 37m 3h 12m — 2h 17m 1h 57m
i7-7700 HDD 8c, 62Gi, HDD 13h 09m 10h 24m — 8h 42m 8h 30m
rpi5-8 4c, 7.7Gi, SSD 52h 06m — 36h 24m — —
rpi5-16 4c, 15Gi, SSD 13h 35m 12h 10m — 10h 54m 10h 45m
i9-9900K 16c, 62Gi, SSD 6h 07m 5h 28m — 5h 05m 4h 57m
Xeon E5 Win 8c, 31Gi, SSD 10h 28m 9h 30m — 8h 36m 8h 24m
umbrel N150 4c, 15Gi, SSD 9h 20m 8h 19m — 7h 52m 7h 45m

N150 (Umbrel) - 1.18x faster
for DBCACHE in 450 1000 2000 3000; do \
  COMMITS="097c18239b58a8ee03794b3ebc6e722a0da30d8d"; \
  STOP=936639; CC=gcc; CXX=g++; \
  BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | $(lsblk -no ROTA $(df --output=source $BASE_DIR | tail -1) | grep -q 1 && echo HDD || echo SSD)"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-$CC.json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "killall -9 bitcoind 2>/dev/null; rm -f ./build/bin/bitcoind; git clean -fxd; git reset --hard {COMMIT} && \
      cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_IPC=OFF && ninja -C build bitcoind -j1 && \
      ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
    --conclude "killall bitcoind || true; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'Disabling script verification at block #1' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log && grep 'Bitcoin Core version' $DATA_DIR/debug.log | grep -q "$(printf %.12s {COMMIT})"; \
                cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-$(date +%s).log" \
    "COMPILER=$CC ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
done

097c182 Merge #34385: subprocess: Fix -Wunused-private-field when building with clang-cl on Windows

2026-02-19 | reindex-chainstate | 936639 blocks | dbcache 450 | umbrel | x86_64 | Intel(R) N150 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        33619.332 s               [User: 61450.140 s, System: 5671.449 s]

2026-02-25 | reindex-chainstate | 936639 blocks | dbcache 1000 | umbrel | x86_64 | Intel(R) N150 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)

  Time (abs ≡):        29948.973 s               [User: 51470.950 s, System: 3405.477 s]

2026-02-25 | reindex-chainstate | 936639 blocks | dbcache 2000 | umbrel | x86_64 | Intel(R) N150 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        28352.766 s               [User: 46633.422 s, System: 2298.085 s]

2026-02-20 | reindex-chainstate | 936639 blocks | dbcache 3000 | umbrel | x86_64 | Intel(R) N150 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=3000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        27910.440 s               [User: 44917.351 s, System: 2090.958 s]
Rpi5 (16) - 1.24x faster
for DBCACHE in 450 1000 2000 3000; do \
  COMMITS="097c18239b58a8ee03794b3ebc6e722a0da30d8d"; \
  STOP=936639; CC=gcc; CXX=g++; \
  BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | $(lsblk -no ROTA $(df --output=source $BASE_DIR | tail -1) | grep -q 1 && echo HDD || echo SSD)"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-$CC.json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "killall -9 bitcoind 2>/dev/null; rm -f ./build/bin/bitcoind; git clean -fxd; git reset --hard {COMMIT} && \
      cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_IPC=OFF && ninja -C build bitcoind -j1 && \
      ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
    --conclude "killall bitcoind || true; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'Disabling script verification at block #1' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log && grep 'Bitcoin Core version' $DATA_DIR/debug.log | grep -q "$(printf %.12s {COMMIT})"; \
                cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-$(date +%s).log" \
    "COMPILER=$CC ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
done

097c182 Merge #34385: subprocess: Fix -Wunused-private-field when building with clang-cl on Windows

2026-02-19 | reindex-chainstate | 936639 blocks | dbcache 450 | rpi5-16-2 | aarch64 | Cortex-A76 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        48933.904 s               [User: 94560.562 s, System: 7823.574 s]

2026-02-24 | reindex-chainstate | 936639 blocks | dbcache 1000 | rpi5-16-2 | aarch64 | Cortex-A76 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        43856.539 s               [User: 78451.084 s, System: 5183.434 s]

2026-02-25 | reindex-chainstate | 936639 blocks | dbcache 2000 | rpi5-16-2 | aarch64 | Cortex-A76 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        39259.025 s               [User: 69044.492 s, System: 3227.006 s]

2026-02-26 | reindex-chainstate | 936639 blocks | dbcache 3000 | rpi5-16-2 | aarch64 | Cortex-A76 | 4 cores | 15Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=3000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        38756.884 s               [User: 65947.478 s, System: 2887.489 s]
Rpi5 (8) - 1.43x faster
for DBCACHE in 450 1000 1536 2000; do \
  COMMITS="097c18239b58a8ee03794b3ebc6e722a0da30d8d"; \
  STOP=936639; CC=gcc; CXX=g++; \
  BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | $(lsblk -no ROTA $(df --output=source $BASE_DIR | tail -1) | grep -q 1 && echo HDD || echo SSD)"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-$CC.json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "killall -9 bitcoind 2>/dev/null; rm -f ./build/bin/bitcoind; git clean -fxd; git reset --hard {COMMIT} && \
      cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_IPC=OFF && ninja -C build bitcoind -j1 && \
      ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
    --conclude "killall bitcoind || true; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'Disabling script verification at block #1' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log && grep 'Bitcoin Core version' $DATA_DIR/debug.log | grep -q "$(printf %.12s {COMMIT})"; \
                cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-$(date +%s).log" \
    "COMPILER=$CC ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
done

097c182 Merge #34385: subprocess: Fix -Wunused-private-field when building with clang-cl on Windows

2026-02-19 | reindex-chainstate | 936639 blocks | dbcache 450 | rpi5-8 | aarch64 | Cortex-A76 | 4 cores | 7.7Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        187564.724 s               [User: 98927.942 s, System: 19100.209 s]

2026-02-25 | reindex-chainstate | 936639 blocks | dbcache 1000 | rpi5-8 | aarch64 | Cortex-A76 | 4 cores | 7.7Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        132856.721 s               [User: 77471.886 s, System: 13535.639 s]

2026-02-22 | reindex-chainstate | 936639 blocks | dbcache 1536 | rpi5-8 | aarch64 | Cortex-A76 | 4 cores | 7.7Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=1536 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        131061.887 s               [User: 71355.478 s, System: 12038.086 s]

2026-02-27 | reindex-chainstate | 936639 blocks | dbcache 2000 | rpi5-8 | aarch64 | Cortex-A76 | 4 cores | 7.7Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        125837.682 s               [User: 69422.152 s, System: 11621.279 s]
Apple M4 Max - 2.46x faster
for DBCACHE in 450 1000 2000 3000; do \
  COMMITS="097c18239b58a8ee03794b3ebc6e722a0da30d8d"; \
  STOP=900000; \
  DATA_DIR="$HOME/Library/Application Support/Bitcoin"; LOG_DIR="$HOME/bitcoin-reindex-logs"; mkdir -p "$LOG_DIR"; \
  COMMA_COMMITS=${COMMITS// /,}; \
  (echo ""; for c in $(echo $COMMITS); do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(sysctl -n machdep.cpu.brand_string) | $(nproc) cores | $(printf '%.1fGiB' "$(( $(sysctl -n hw.memsize)/1024/1024/1024 ))") RAM | SSD | $(sw_vers -productName) $(sw_vers -productVersion) $(sw_vers -buildVersion) | $(xcrun clang --version | head -1)"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$LOG_DIR/rdx-$(echo "$COMMITS" | sed -E 's/([a-f0-9]{8})[a-f0-9]+ ?/\1-/g;s/-$//')-$STOP-$DBCACHE-appleclang.json" \
    --parameter-list COMMIT "$COMMA_COMMITS" \
    --prepare "killall -9 bitcoind 2>/dev/null || true; rm -f \"$DATA_DIR\"/debug.log; git checkout {COMMIT}; git reset --hard && \
      cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release && ninja -C build bitcoind -j2 && \
      ./build/bin/bitcoind -datadir=\"$DATA_DIR\" -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20" \
    --conclude "killall bitcoind 2>/dev/null || true; sleep 5; grep -q 'height=0' \"$DATA_DIR\"/debug.log && grep -q 'Disabling script verification at block #1' \"$DATA_DIR\"/debug.log && grep -q \"height=$STOP\" \"$DATA_DIR\"/debug.log || { echo 'debug.log assertions failed'; exit 1; }; \
                cp \"$DATA_DIR\"/debug.log \"$LOG_DIR\"/debug-{COMMIT}-\$(date +%s).log 2>/dev/null || true" \
    "./build/bin/bitcoind -datadir=\"$DATA_DIR\" -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
done

097c182 Merge #34385: subprocess: Fix -Wunused-private-field when building with clang-cl on Windows

2026-02-21 | reindex-chainstate | 900000 blocks | dbcache 450 | M4-Max.local | arm64 | Apple M4 Max | 16 cores | 64.0GiB RAM | SSD | macOS 26.2 25C56 | Apple clang version 17.0.0 (clang-1700.6.3.2)

Benchmark 1: ./build/bin/bitcoind -datadir="/Users/lorinc/Library/Application Support/Bitcoin" -stopatheight=900000 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        20261.315 s               [User: 18768.521 s, System: 4271.673 s]

2026-02-27 | reindex-chainstate | 900000 blocks | dbcache 1000 | M4-Max.local | arm64 | Apple M4 Max | 16 cores | 64.0GiB RAM | SSD | macOS 26.3 25D125 | Apple clang version 17.0.0 (clang-1700.6.3.2)

Benchmark 1: ./build/bin/bitcoind -datadir="/Users/lorinc/Library/Application Support/Bitcoin" -stopatheight=900000 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        11574.620 s               [User: 12147.446 s, System: 2417.914 s]

2026-02-26 | reindex-chainstate | 900000 blocks | dbcache 2000 | M4-Max.local | arm64 | Apple M4 Max | 16 cores | 64.0GiB RAM | SSD | macOS 26.3 25D125 | Apple clang version 17.0.0 (clang-1700.6.3.2)

Benchmark 1: ./build/bin/bitcoind -datadir="/Users/lorinc/Library/Application Support/Bitcoin" -stopatheight=900000 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        8226.676 s               [User: 9083.949 s, System: 1179.971 s]

2026-02-21 | reindex-chainstate | 900000 blocks | dbcache 3000 | M4-Max.local | arm64 | Apple M4 Max | 16 cores | 64.0GiB RAM | SSD | macOS 26.2 25C56 | Apple clang version 17.0.0 (clang-1700.6.3.2)

Benchmark 1: ./build/bin/bitcoind -datadir="/Users/lorinc/Library/Application Support/Bitcoin" -stopatheight=900000 -dbcache=3000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        7064.184 s               [User: 7701.391 s, System: 668.060 s]
i7 HDD - 1.51x faster
for DBCACHE in 450 1000 2000 3000; do \
  COMMITS="097c18239b58a8ee03794b3ebc6e722a0da30d8d"; \
  STOP=936639; CC=gcc; CXX=g++; \
  BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | $(lsblk -no ROTA $(df --output=source $BASE_DIR | tail -1) | grep -q 1 && echo HDD || echo SSD)"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-$CC.json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "killall -9 bitcoind 2>/dev/null; rm -f ./build/bin/bitcoind; git clean -fxd; git reset --hard {COMMIT} && \
      cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_IPC=OFF && ninja -C build bitcoind -j1 && \
      ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
    --conclude "killall bitcoind || true; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'Disabling script verification at block #1' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log && grep 'Bitcoin Core version' $DATA_DIR/debug.log | grep -q "$(printf %.12s {COMMIT})"; \
                cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-$(date +%s).log" \
    "COMPILER=$CC ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
done

097c182 Merge #34385: subprocess: Fix -Wunused-private-field when building with clang-cl on Windows

2026-02-21 | reindex-chainstate | 936639 blocks | dbcache 450 | i7-hdd | x86_64 | Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz | 8 cores | 62Gi RAM | HDD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        47384.896 s               [User: 54460.024 s, System: 3388.557 s]

2026-02-24 | reindex-chainstate | 936639 blocks | dbcache 1000 | i7-hdd | x86_64 | Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz | 8 cores | 62Gi RAM | HDD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        37486.190 s               [User: 46563.682 s, System: 2189.609 s]

2026-02-25 | reindex-chainstate | 936639 blocks | dbcache 2000 | i7-hdd | x86_64 | Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz | 8 cores | 62Gi RAM | HDD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        31379.903 s               [User: 41546.866 s, System: 1383.556 s]

2026-02-21 | reindex-chainstate | 936639 blocks | dbcache 3000 | i7-hdd | x86_64 | Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz | 8 cores | 62Gi RAM | HDD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=3000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        30633.603 s               [User: 39511.869 s, System: 1116.371 s]
Windows Xeon - 1.24x faster
for DBCACHE in 450 1000 2000 3000; do \
  COMMITS="5401e673d56198f2c0bad366581e70d5d9cd765c"; \
  STOP=933339; \
  HOST=x86_64-w64-mingw32; \
  XPACK="/home/win/xpack-mingw-w64-gcc-15.2.0-2"; \
  BASE_DIR="/mnt/c/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
  WIN_DATA_DIR='C:\\my_storage\\BitcoinData'; \
  export PATH="$XPACK/bin:$PATH"; \
  mkdir -p "$LOG_DIR"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | win64-gcc15"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-win64.json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "taskkill.exe /IM bitcoind.exe /F 2>/dev/null; rm -f ./build/bin/bitcoind.exe; rm -f $DATA_DIR/debug.log; git clean -fxd -e depends/built -e depends/sources -e depends/$HOST; git reset --hard {COMMIT} && \
      make -C depends HOST=$HOST NO_QT=1 NO_ZMQ=1 CC=\"$XPACK/bin/x86_64-w64-mingw32-gcc\" CXX=\"$XPACK/bin/x86_64-w64-mingw32-g++\" -j\$(nproc) && \
      cmake -B build -G Ninja --toolchain depends/$HOST/toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_GUI=OFF -DWITH_ZMQ=OFF -DBUILD_TESTS=OFF -DBUILD_BENCH=OFF && \
      ninja -C build bitcoind -j\$(nproc) && \
      ./build/bin/bitcoind.exe -datadir=\"$WIN_DATA_DIR\" -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
    --conclude "taskkill.exe /IM bitcoind.exe /F 2>/dev/null; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log && grep 'Bitcoin Core version' $DATA_DIR/debug.log | grep -q "$(printf %.12s {COMMIT})"; \
      cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-\$(date +%s).log" \
    "./build/bin/bitcoind.exe -datadir=\"$WIN_DATA_DIR\" -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0"; \
done

5401e67 Merge #33604: p2p: Allow block downloads from peers without snapshot block after assumeutxo validation

2026-02-10 | reindex-chainstate | 933339 blocks | dbcache 450 | WIN-A2EHOAU4JET | x86_64 | Intel(R) Xeon(R) CPU E5-2637 v2 @ 3.50GHz | 8 cores | 31Gi RAM | win64-gcc15

Benchmark 1: ./build/bin/bitcoind.exe -datadir="C:\\my_storage\\BitcoinData" -stopatheight=933339 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 5401e673d56198f2c0bad366581e70d5d9cd765c)
  Time (abs ≡):        37691.648 s               [User: 0.000 s, System: 0.001 s]

2026-02-24 | reindex-chainstate | 933339 blocks | dbcache 1000 | WIN-A2EHOAU4JET | x86_64 | Intel(R) Xeon(R) CPU E5-2637 v2 @ 3.50GHz | 8 cores | 31Gi RAM | win64-gcc15

Benchmark 1: ./build/bin/bitcoind.exe -datadir="C:\\my_storage\\BitcoinData" -stopatheight=933339 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 5401e673d56198f2c0bad366581e70d5d9cd765c)
  Time (abs ≡):        34250.996 s               [User: 0.002 s, System: 0.000 s]

2026-02-26 | reindex-chainstate | 933339 blocks | dbcache 2000 | WIN-A2EHOAU4JET | x86_64 | Intel(R) Xeon(R) CPU E5-2637 v2 @ 3.50GHz | 8 cores | 31Gi RAM | win64-gcc15

Benchmark 1: ./build/bin/bitcoind.exe -datadir="C:\\my_storage\\BitcoinData" -stopatheight=933339 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 5401e673d56198f2c0bad366581e70d5d9cd765c)
  Time (abs ≡):        31001.091 s               [User: 0.000 s, System: 0.002 s]

2026-02-21 | reindex-chainstate | 933339 blocks | dbcache 3000 | WIN-A2EHOAU4JET | x86_64 | Intel(R) Xeon(R) CPU E5-2637 v2 @ 3.50GHz | 8 cores | 31Gi RAM | win64-gcc15

Benchmark 2: ./build/bin/bitcoind.exe -datadir="C:\\my_storage\\BitcoinData" -stopatheight=933339 -dbcache=3000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 5401e673d56198f2c0bad366581e70d5d9cd765c)
  Time (abs ≡):        30276.311 s               [User: 0.001 s, System: 0.000 s]
i9 - 1.20x faster
for DBCACHE in 450 1000 2000 3000; do \
  COMMITS="097c18239b58a8ee03794b3ebc6e722a0da30d8d"; \
  STOP=936639; CC=gcc; CXX=g++; \
  BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
  (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | $(lsblk -no ROTA $(df --output=source $BASE_DIR | tail -1) | grep -q 1 && echo HDD || echo SSD)"; echo "") && \
  hyperfine \
    --sort command \
    --runs 1 \
    --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-$CC.json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "killall -9 bitcoind 2>/dev/null; rm -f ./build/bin/bitcoind; git clean -fxd; git reset --hard {COMMIT} && \
      cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_IPC=OFF && ninja -C build bitcoind -j1 && \
      ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
    --conclude "killall bitcoind || true; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'Disabling script verification at block #1' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log && grep 'Bitcoin Core version' $DATA_DIR/debug.log | grep -q "$(printf %.12s {COMMIT})"; \
                cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-$(date +%s).log" \
    "COMPILER=$CC ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
done

5401e67 Merge #33604: p2p: Allow block downloads from peers without snapshot block after assumeutxo validation

2026-02-26 | reindex-chainstate | 936639 blocks | dbcache 450 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=450 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        22076.658 s               [User: 53940.221 s, System: 3111.267 s]

2026-02-26 | reindex-chainstate | 936639 blocks | dbcache 1000 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=1000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        19724.533 s               [User: 45709.253 s, System: 2066.725 s]

2026-02-26 | reindex-chainstate | 936639 blocks | dbcache 2000 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=2000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        18302.184 s               [User: 40157.899 s, System: 1250.246 s]

2026-02-27 | reindex-chainstate | 936639 blocks | dbcache 3000 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=936639 -dbcache=3000 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 097c18239b58a8ee03794b3ebc6e722a0da30d8d)
  Time (abs ≡):        17858.670 s               [User: 38277.112 s, System: 1008.751 s]

Default/Warning quick reference

System RAM Auto-default (64 / 32) Warning fires above (64 / 32)
1 GiB 100 MiB 100 MiB
2 GiB 100 MiB 100 MiB
3 GiB 256 MiB 768 MiB
4 GiB 512 MiB 1536 / 1024 MiB
8 GiB 1536 / — MiB 4608 / — MiB
16 GiB 2048 / — MiB 10752 / — MiB
32 GiB 2048 / — MiB 23040 / — MiB
image

@DrahtBot

DrahtBot commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept NACK willcl-ark, darosior
Concept ACK andrewtoth, openoms
Stale ACK Bortlesboat, optout21

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34995 (ci, iwyu: Fix warnings in src/common and treat them as errors by hebasto)
  • #34806 (refactor: logging: Various API improvements by ajtowns)
  • #32427 ((RFC) kernel: Replace leveldb-based BlockTreeDB with flat-file based store by sedited)
  • #28690 (build: Introduce internal kernel library by sedited)
  • #26022 (Add util::ResultPtr class by ryanofsky)
  • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
  • #25665 (refactor: Add util::Result failure types and ability to merge result values by ryanofsky)
  • #17783 (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
  • #17581 (refactor: Remove settings merge reverse precedence code by ryanofsky)
  • #17580 (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
  • #17493 (util: Forbid ambiguous multiple assignments in config file by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@l0rinc
l0rinc force-pushed the l0rinc/dynamic-dbcache branch 3 times, most recently from 30bfcdf to 0f93881 Compare February 21, 2026 08:59
@l0rinc
l0rinc marked this pull request as ready for review February 21, 2026 13:20
@l0rinc

l0rinc commented Feb 21, 2026

Copy link
Copy Markdown
Contributor Author

It took a few rounds to tame (I had a Kernel Panic myself when I saw missing <PLATFORM_ID:Windows>:ws2_32 errors), but it's ready for review.
I will add new measurements to the PR description after I have more instances.
If someone could benchmark it on 8 and 4 GB machines, I'd appreciate it.
For the record, the bitcoind startup looks like this now:

2026-02-21T13:24:38Z * Using 2.0 MiB for block index database
2026-02-21T13:24:38Z * Using 8.0 MiB for chain state database
2026-02-21T13:24:38Z * Using 2990.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)

@andrewtoth andrewtoth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Comment thread doc/reduce-memory.md Resolved
Comment thread doc/reduce-memory.md Outdated
- `-dbcache=<n>` - the UTXO database cache size, this defaults to `450`. The unit is MiB (1024).
- The minimum value for `-dbcache` is 4.
- A lower `-dbcache` makes initial sync time much longer. After the initial sync, the effect is less pronounced for most use-cases, unless fast validation of blocks is important, such as for mining.
- `-dbcache=<n>` - UTXO database cache size in MiB (minimum `4`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing this so much?
I think we should just remove this defaults to 450`` from this line, and add the below point:
- Automatic default scales with system RAM and can be as high as 1000` MiB.`
Then keep the rest the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, simplified, thanks.

Comment thread doc/release-notes-34641.md Outdated
----------------------------------

- When `-dbcache` is not set explicitly, Bitcoin Core now chooses a RAM-aware default that can be as high as `3000` MiB.
Explicit `-dbcache` values continue to override the automatic default. (#34641)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also say something like:
"To maintain the same behavior of previous releases, set dbcache to 450."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/node/caches.h Outdated
//! Automatic -dbcache floor (bytes)
static constexpr size_t MIN_DEFAULT_DBCACHE{100_MiB};
//! Automatic -dbcache cap (bytes)
static constexpr size_t MAX_DEFAULT_DBCACHE{3000_MiB};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be more conservative and set this to 1GB as discussed in the IRC meeting. Such a large bump in memory might be unexpected, especially when running bitcoind alongside other applications and not a dedicated node machine.

Suggested change
static constexpr size_t MAX_DEFAULT_DBCACHE{3000_MiB};
static constexpr size_t MAX_DEFAULT_DBCACHE{1000_MiB};

@l0rinc l0rinc Feb 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1 GB limit was a suggestion for a constant dbcache, which I opposed because it was too high for cheaper nodes (and too low for performant ones).
But since we can scale with total memory now, it makes sense to go higher, especially since 3-4 GB already achieves most of the speedup we saw.
This way, we have a simple formula instead of custom values for each memory.

System RAM Automatic default
1 GiB 100 MiB
2 GiB 100 MiB
4 GiB 512 MiB
8 GiB 1536 MiB
16 GiB 3000 MiB

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too worried about this, because I suspect that most low-memory systems have explicit configurations anyway (either because they need it already, or because they're managed by node-in-a-box / distributions). And we should have loud and clear release notes for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really about low memory systems. We don't clear the cache anymore, so if we sync and then go to steady state the node will use lots of cache for pretty much its lifetime. For instance it finishes IBD at 2GB, it will take maybe a year to fill up to 3GB and finally clear. That's just being a bad OS citizen using that much memory when we don't need it.

@sipa sipa Feb 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that sort of calls for a dbcache value that is different between IBD and later, which I guess makes sense if you're planning to run other things post-IBD. But on the other hand, a 1 GiB difference seems tiny for sufficiently large systems (which I suspect most non-dedicated setups are).

Assuming we don't want to do that in this PR, reducing to 2 GiB or 1 GiB default makes sense perhaps, but that reduces the benefit too.

@andrewtoth andrewtoth Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference in benefit? I think more than doubling the default (450->1000) is a pretty big speedup. What's going from 1->2->3?

I would think the initial bump would have the lions share of speedup. Could be wrong though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be right. I haven't actually used a dbcache setting below 8 GiB or so in years, so 🤷‍♂️.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm measuring with 1 and 2 cap so that we can compare.
Other that that, does the formula make sense?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There still looks like a substantial benefit to bumping to 1GB.

Another user posted the same concern as I https://x.com/lukechilds/status/2026875795080359955.

Perhaps it's worth doing a conservative bump for now, and work on a separate steady state dbcache value for v32. We could even have a lower general steady state value than 450MB, so running normally uses less RAM. Then we can bump to 3GB or more for IBD in v32.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now that a few more measurements have come in, it's clear that the 2 GiB to 3 GiB speedup is negligible.
The 1 GiB to 2 GiB is still very much relevant - and affect 16 GiB machines only, 8 GiB machines were already capped at 1536. Changed the upper cap to 2 GiB for now.

I will push the steady state dbcache change after this change, separately, it makes more sense to restrict that once your parallelization PR lands and we don't need so much memory anyway.

Comment thread src/node/caches.h Resolved
Comment thread src/common/system.cpp Resolved
Comment thread src/init.cpp Resolved
@l0rinc
l0rinc force-pushed the l0rinc/dynamic-dbcache branch from 4e68c80 to b67bb06 Compare February 25, 2026 10:03
@l0rinc

l0rinc commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

Q: Now that the total memory is needed for more than just the warning, should we mandate that this method works for the whole CI infra (cc: @hebasto), see

if (!total) {
BOOST_WARN_MESSAGE(false, "skipping total_ram: total RAM unknown");
return;
}

I have addresses a few nits, I'm still measuring 1 and 2 GB dbcache values for comparison, added a few ones already to the PR description. The difference between 1 and 3 still seems relevant. I don't think a 16 GB machine should be surprised by that amount and an 8 GB is already capped at 1536 MB. Let's see the results and we can decide.

@hebasto

hebasto commented Feb 25, 2026

Copy link
Copy Markdown
Member

Q: Now that the total memory is needed for more than just the warning, should we mandate that this method works for the whole CI infra...

A related discussion happened here: #33435 (review).

We could make the test mandatory. If it fails in an unsupported environment, users can still explicitly disable it.

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the new source files common/system_ram.cpp and node/dbcache.cpp be added to FILES_WITH_ENFORCED_IWYU?

@willcl-ark willcl-ark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Seems like a reasonable first step towards something more like #8437, which I've wanted to see for a long time... In the case that never happens, this seems perfectly worthwhile on it's own, too.

Just one comment so far, re. handling the implementation-defined truncation, but mostly LGTM.

Comment thread src/node/caches.h Resolved
@l0rinc
l0rinc force-pushed the l0rinc/dynamic-dbcache branch from b67bb06 to 7385c5b Compare February 25, 2026 12:05
@l0rinc

l0rinc commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @hebasto & @willcl-ark, addressed your concerns, added both as coauthor.

@hebasto

hebasto commented Feb 25, 2026

Copy link
Copy Markdown
Member

Could the new source files common/system_ram.cpp and node/dbcache.cpp be added to FILES_WITH_ENFORCED_IWYU?

The IWYU warnings in the CI seem to be legit.

@l0rinc
l0rinc force-pushed the l0rinc/dynamic-dbcache branch from 7385c5b to 0348bda Compare February 25, 2026 12:20
@l0rinc
l0rinc force-pushed the l0rinc/dynamic-dbcache branch from 0348bda to c4077b3 Compare February 25, 2026 12:27
Comment thread src/node/caches.h Outdated
//! -dbcache default (bytes)
static constexpr size_t DEFAULT_DB_CACHE{DEFAULT_KERNEL_CACHE};
//! Automatic -dbcache floor (bytes)
static constexpr size_t MIN_DEFAULT_DBCACHE{100_MiB};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure about reducing the default dbcache. The project has defaulted to 450 for nearly a decade. Looking through the issue tracker, I have not found too many users complaining about bitcoind oom-ing on low-RAM devices. Even the most popular raspberry pi installation guide bumps cache to 2GB: https://raspibolt.org/guide/bitcoin/bitcoin-client.html#configuration (I realize though that they are targeting devices with 4+GB of RAM). Do we really need to change this on the minimum side?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not found too many users complaining about bitcoind oom-ing on low-RAM devices

I have tried it and we can't do it with 2 GB total memory currently with default dbcache. The memory usage grows with threads, with mempool, with sigcache, connection count, memory buffers, etc.
With 4 GB ram we're already increasing the dbcache in this PR, so reduction only happens for extremely constrained machines. A 2 GB machine can barely finish an IBD and only if we explicitly reduce the dbcache to 100 (and even this OOM-ed on some flushes). That's what we're doing here automatically now.
A 2 GB machine can't even compile the source code without explicit swapping, so it makes sense to make these more realistic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the same reasoning apply to virtualizations where e.g. 2GB are allocated to running bitcoind in a jail? Reading through some of the issues in the tracker that seems a likely deployment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running nodes in 2GB AWS EC2 instances just fine. Although mempool is fairly empty. I don't think IBD in such an instance is feasible though, with or without dbcache. Reducing this for steady state seems fine. I doubt users will notice.
Not sure why anyone would want to build on such an instance either.

Comment thread src/common/system_ram.cpp Outdated
#ifdef WIN32
if (MEMORYSTATUSEX m{}; (m.dwLength = sizeof(m), GlobalMemoryStatusEx(&m))) return clamp(m.ullTotalPhys);
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__illumos__) || defined(__linux__)
if (long p{sysconf(_SC_PHYS_PAGES)}, s{sysconf(_SC_PAGESIZE)}; p > 0 && s > 0) return clamp(1ULL * p * s);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will work correctly in a containerized environment. E.g. what happens if you create a docker container with bounded memory? From what I am gathering it will attempt to measure the hosts memory, not whatever the system administrator allocated for the container. I'm not sure if we can account for all these scenarios, meaning this change is likely to break a few deployments. A log message on init indicating what was measured and how much db cache allocation was scaled up would already go a ways to at least make this a bit more transparent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this was exactly what I was working on after talking to @openoms.

We could extend the total memory calculator to take cgroups and BSD jails into consideration, but for now (to avoid bikeshedding here), I only added a warning if /sys/fs/cgroup exists.
That extra warning also made me realize that we are not displaying the cache sizes in a uniform way, and there is no point in pretending we care about decimals for MiB, but we do for GiB. Since GiB is now the expected unit for -dbcache, I unified the display of the cache units.

Total RAM is also cached now so that we can call it multiple times, and it was renamed to TryGetTotalRam to differentiate it from the alternative that falls back to the default value.

Also made GetDefaultCache more testable by reverting to system ran if the optional parameter is not provided.

And lastly I regrouped the tests (data separated from logic) to simplify the RAM-aware commit diff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted many of these based on followup reviews

@optout21

Copy link
Copy Markdown
Contributor

That said, I think there is very valuable work in this thread, specifically the benchmarking on which values work better on different types of machines.

I would add that more informative/meaningful warnings in cases where the specified cache size value seems sub-optimal are also valuable, even if the default is not changed (though my vote goes with the RAM-aware default).

@darosior darosior left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, as previously discussed in #34692 (1, 2), i am also Concept NACK on having moving defaults.

@l0rinc

l0rinc commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews, I'll investigate later how to move forward, moving to draft in the meantime

@l0rinc
l0rinc marked this pull request as draft April 28, 2026 19:16
l0rinc and others added 8 commits April 29, 2026 11:18
Replace bare `>> 20` shifts in dbcache-related MiB conversions with `/ 1_MiB`, so the unit is visible at the call site before the dbcache helpers are split out.
Also switch a touched Qt settings migration cast to the local functional-cast style.
Move the OS-dependent total RAM query out of `common/system.cpp` into a dedicated `common/system_ram.cpp` translation unit and declare it in `common/system_ram.h`.

Co-authored-by: sipa <[email protected]>
-BEGIN VERIFY SCRIPT-
git grep -l 'GetTotalRAM' -- src | xargs perl -pi -e 's/\bGetTotalRAM\b/TryGetTotalRam/g'
-END VERIFY SCRIPT-
The dbcache default and oversized-warning paths can both query total RAM during startup.
Cache the OS query result in a function-local static, so callers can use `TryGetTotalRam()` without repeating the underlying `sysconf` or `GlobalMemoryStatusEx` call.
Move the `dbcache`-specific declarations and definitions out of `node/caches.{h,cpp}` into a dedicated `node/dbcache` translation unit.

Co-authored-by: Luke Dashjr <[email protected]>
PR bitcoin#34692 made node startup and Qt settings use `node::GetDefaultDBCache()`, but `bitcoinkernel` still used the fixed `DEFAULT_KERNEL_CACHE` value.

Use the shared helper in the two kernel initialization paths, so kernel users get the same `450 MiB` or `1024 MiB` default as the node path.
Also align the Qt settings migration default with the same helper now that `DEFAULT_KERNEL_CACHE` is removed.
Drop `DEFAULT_KERNEL_CACHE` now that the node helper is the single default source.
The oversized dbcache warning still switches from a fixed `450 MiB` cap below `2 GiB` RAM to `75%` of total RAM at `2 GiB`.
That creates a discontinuity where adding one MiB of RAM can raise the warning threshold from `450 MiB` to `1536 MiB`.

Use a single monotonic rule based on a `2 GiB` reserved-memory budget instead:

  warn if dbcache > max(DEFAULT_DB_CACHE, 0.75 * (total_ram - RESERVED_RAM))

Above `RESERVED_RAM`, the threshold grows linearly at `0.75 MiB` per MiB of additional RAM.
This keeps a `25%` margin above the reserve for OS and mempool variance while avoiding the cliff.

Move the implementation out of the header because it is no longer constexpr.
Update the warning string in the same commit so the format specifiers match the byte-unit result types after switching these conversions away from `size_t`-specific shifts.

Co-authored-by: Bortlesboat <[email protected]>
Co-authored-by: optout <[email protected]>
Express the manual `-dbcache` cap once as `MAX_DBCACHE_BYTES` instead of hard-wiring the 32-bit branch at the clamp site.

The effective cap is unchanged: 1 GiB on 32-bit builds and the full `uint64_t` range on 64-bit builds.

Keep parsed `-dbcache` bytes in `uint64_t`, matching the byte-unit literals, and cast back only while the surrounding cache split types still use `size_t`.
Use the `_BYTES` suffix for `MIN_DBCACHE_BYTES`, `DEFAULT_DBCACHE_BYTES`, and `MAX_DBCACHE_BYTES` so the units are obvious and the dbcache bounds/default read as one group.

-BEGIN VERIFY SCRIPT-
git grep -l -w \
    -e 'MIN_DB_CACHE' \
    -e 'DEFAULT_DB_CACHE' \
    -- src test | \
    xargs perl -pi \
        -e 's/\bMIN_DB_CACHE\b/MIN_DBCACHE_BYTES/g;' \
        -e 's/\bDEFAULT_DB_CACHE\b/DEFAULT_DBCACHE_BYTES/g;'
-END VERIFY SCRIPT-

Co-authored-by: optout <[email protected]>
@l0rinc
l0rinc force-pushed the l0rinc/dynamic-dbcache branch from c75a1c9 to 3c627bb Compare April 29, 2026 10:00
@l0rinc

l0rinc commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

I'll push a separate PR instead with only the shared dbcache defaults and the warning smoothing.

@l0rinc l0rinc closed this Apr 29, 2026
@l0rinc
l0rinc deleted the l0rinc/dynamic-dbcache branch April 29, 2026 10:11
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 3, 2026
…ersions

Replace bare `>> 20` shifts that will be touched later with `/ 1_MiB`, so the unit is visible at the call site instead of relying on the reader to recognize the magic shift width.

Github-Pull: bitcoin#34641
Rebased-From: 4a5cd1748f944f405225c276aa1590d002d5ada0
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 3, 2026
Move the OS-dependent total RAM query out of `common/system.cpp` into a dedicated `common/system_ram.cpp` translation unit and declare it in `common/system_ram.h`.

Co-authored-by: sipa <[email protected]>

Github-Pull: bitcoin#34641
Rebased-From: 89730e159fc391819558841a0a9fdbb77e97980a
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 3, 2026
-BEGIN VERIFY SCRIPT-
git grep -l 'GetTotalRAM' -- src | xargs perl -pi -e 's/\bGetTotalRAM\b/TryGetTotalRam/g'
-END VERIFY SCRIPT-

Github-Pull: bitcoin#34641
Rebased-From: 3b2f7b472d1dd75c8197b577ca976d90c09ec409
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 3, 2026
Wrap the OS query in a static immediately-invoked lambda so the underlying `sysconf`/`GlobalMemoryStatusEx` call only happens once per process.
Subsequent calls return the cached `std::optional<size_t>`, letting call sites use the helper freely without worrying about repeated syscalls.

Github-Pull: bitcoin#34641
Rebased-From: 7832b674ae1e5a2f137037eed707314ed970509a
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 3, 2026
Move the `dbcache`-specific declarations and definitions out of `node/caches.{h,cpp}` into a dedicated `node/dbcache` translation unit.

Co-authored-by: Luke Dashjr <[email protected]>

Github-Pull: bitcoin#34641
Rebased-From: 7cb69c71166af21c14b90082556d03e7f1f61e57
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request May 3, 2026
Drop the fixed `DEFAULT_KERNEL_CACHE` constant and have the two `bitcoinkernel` initialisation sites pick up the same default the node startup path uses (`node::GetDefaultDBCache()`).
That helper already chooses between `450 MiB` and `1024 MiB` based on detected RAM, so kernel consumers on 64-bit systems with at least 4 GiB RAM now get the same `1024 MiB` default instead of the previous fixed `450 MiB`.

Github-Pull: bitcoin#34641
Rebased-From: dbd8897dbed3303d09752d39c869f0e50d682745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.