Repository navigation
Conversation
We store LevelDB table files uncompressed. On 64-bit builds, LevelDB normally serves table blocks directly from mmap-backed files and marks those blocks non-cachable, leaving the configured block cache empty in the common read path. Use a zero-capacity block cache on 64-bit builds. Keep the existing cache on 32-bit builds, where mmap is disabled. This avoids reserving cache budget for a cache that is normally unused on 64-bit systems and may save a small amount of cache bookkeeping memory. Co-authored-by: Pieter Wuille <[email protected]>
On 64-bit builds the block-cache share is normally unused because mmap-backed uncompressed table blocks bypass it. Move that half of the DB cache budget to LevelDB's write buffer on 64-bit builds. Keep 32-bit unchanged, where mmap is disabled and the block cache can still be used. Because LevelDB may keep two write buffers, this preserves the existing total DB-cache accounting: 64-bit can now use up to the whole budget for write buffers. 32-bit still keeps half for block cache and up to half for write buffers. Co-authored-by: Andrew Toth <[email protected]>
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35620. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Is the extra case for 32bit systems really worthwhile? Seems like a lot of infrastructure for something that only pays off on a single architecture. AFAICT for the indexes it seems sufficient to just allocate the default 8MiB of write buffer. |
|
#32375 also relevant. Not sure how much new code we should be adding for 32bit systems. |
Fully agree, but 32 bit builds don't have mmaped builds so they still need the cache. |
I think I would prefer if it, and with it most of the cache allocation code, were removed. Do you see any benefit to giving the indexes more than the default amount of write buffer? |
That's a bigger change, but it fits here, and the end result will be a lot cleaner.
I'm still running the tests on HDD, will draft the change until they finish. Will also need to recheck every index after these changes. |
|
I did a few more measurements on HDD which are giving me mixed results so far: reindex-chainstate | 954459 blocks | dbcache 1024 | i7-hdd | x86_64 | Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz | 8 threads | 62Gi RAM | HDDfor DBCACHE in 1024; do \
COMMITS="3c76bd435681ee2ebaa1f407ac23736d9c3b331b ecb530c63dab1802dc756d14180730dc7e15e15b a479f8a071a6719b5ff6f389af3c3f4c0cf40c36"; \
STOP=954459; 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" 2>/dev/null || true; 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) threads | $(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 2 \
--export-json "$BASE_DIR/rdx-$(sed -E 's/([a-f0-9]{8})[a-f0-9]* ?/\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} && \
CC=$CC CXX=$CXX cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release && ninja -C build bitcoind -j1 && \
./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -printtoconsole=0 && sleep 20 && rm -f $DATA_DIR/debug.log && rm -rfd $DATA_DIR/indexes" \
--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 \"\$(git rev-parse --short=12 {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 -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0"; \
done
3c76bd4356 Merge bitcoin/bitcoin#35603: build: QRencode cleanups
ecb530c63d db: avoid unused LevelDB block cache on 64-bit
a479f8a071 db: move unused block cache to write buffer
2026-06-30 | reindex-chainstate | 954459 blocks | dbcache 1024 | i7-hdd | x86_64 | Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz | 8 threads | 62Gi RAM | HDD
Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=1024 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = 3c76bd435681ee2ebaa1f407ac23736d9c3b331b)
Time (mean ± σ): 30825.620 s ± 217.655 s [User: 36503.667 s, System: 1358.245 s]
Range (min … max): 30671.715 s … 30979.525 s 2 runs
Benchmark 2: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=1024 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = ecb530c63dab1802dc756d14180730dc7e15e15b)
Time (mean ± σ): 31831.237 s ± 370.410 s [User: 36560.906 s, System: 1349.523 s]
Range (min … max): 31569.318 s … 32093.156 s 2 runs
Benchmark 3: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=1024 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = a479f8a071a6719b5ff6f389af3c3f4c0cf40c36)
Time (mean ± σ): 31335.954 s ± 256.770 s [User: 36564.447 s, System: 1341.683 s]
Range (min … max): 31154.391 s … 31517.518 s 2 runs
Relative speed comparison
1.00 COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=1024 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = 3c76bd435681ee2ebaa1f407ac23736d9c3b331b)
1.03 ± 0.01 COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=1024 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = ecb530c63dab1802dc756d14180730dc7e15e15b)
1.02 ± 0.01 COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=1024 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = a479f8a071a6719b5ff6f389af3c3f4c0cf40c36)I will need to investigate if there's any path that's still affected by the block cache or the write buffers - leaving as draft in the meantime. |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
Closing this because multiple indexes can exhaust the reduced, process-wide mmap allowance, making the block cache useful even on 64-bit builds. We could raise the allowance back to 4096, but given the recent reduction, I'll leave the cache settings unchanged. |
Problem:
CDBWrapperreserves half of each DB cache budget for LevelDB's block cache, which only helps when table-block contents are cacheable.On 64-bit builds LevelDB uses mmap reads and, for our uncompressed table files, marks mmap-backed contents non-cacheable.
LevelDB only inserts cacheable blocks, so the normal 64-bit path does not populate it.
Discussion: This came up in Sipa's leveldb-subtree#63 resource-limit notes, the follow-up note on #34636, and the IRC discussion. The IRC thread also suggested moving that budget to
write_buffer_size, where #34636 still controls useful per-DB cache budgets; the block cache still matters on 32-bit or non-mmap fallback paths.Fix: Use a zero-capacity LevelDB block cache on 64-bit builds (instead of
nullptr, which defaults to 8 MiB) and move the freed half of the DB cache budget towrite_buffer_size, following Andrew's IRC suggestion.Keep the existing block-cache/write-buffer split on 32-bit builds, where mmap is disabled and the block cache can still be used.
Benchmarks: Both commits were benchmarked with
reindex-chainstateto height 954459 and showed no meaningful runtime change.Measurements
reindex-chainstate | 954459 blocks | dbcache 1024 | ssd-ryzen | x86_64 | AMD Ryzen 7 3700X 8-Core Processor | 16 threads | 62Gi RAM | SSD
reindex-chainstate | 954459 blocks | dbcache 1024 | rpi5-16-3 | aarch64 | Cortex-A76 | 4 threads | 15Gi RAM | SSD
reindex-chainstate | 954459 blocks | dbcache 1024/10000 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 threads | 62Gi RAM | SSD