Skip to content

leveldb: move unused block-cache budget to write buffers - #35620

Closed
l0rinc wants to merge 2 commits into
bitcoin:masterfrom
l0rinc:l0rinc/leveldb-block-cache-write-buffer
Closed

l0rinc wants to merge 2 commits into
bitcoin:masterfrom
l0rinc:l0rinc/leveldb-block-cache-write-buffer

Conversation

@l0rinc

@l0rinc l0rinc commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem: CDBWrapper reserves 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 to write_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-chainstate to 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
for 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 1 \
    --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 | ssd-ryzen | x86_64 | AMD Ryzen 7 3700X 8-Core Processor | 16 threads | 62Gi RAM | SSD

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 (abs ≡):        15597.417 s               [User: 28075.099 s, System: 1965.047 s]
 
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 (abs ≡):        15573.304 s               [User: 28109.013 s, System: 1961.319 s]
 
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 (abs ≡):        15664.809 s               [User: 28159.343 s, System: 1962.872 s]
 
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.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 = ecb530c63dab1802dc756d14180730dc7e15e15b)
        1.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)
reindex-chainstate | 954459 blocks | dbcache 1024 | rpi5-16-3 | aarch64 | Cortex-A76 | 4 threads | 15Gi RAM | SSD
for DBCACHE in 1024; do \
    COMMITS="0e95e1abdb47adbc3342a2123f9f1be43d9a4f55 69a953f70dc9a4f322a6c99d0e66acb548609e3b"; \
    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 1 \
    --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

0e95e1abdb Merge bitcoin/bitcoin#35437: migrate: Handle HD chains that have identical seeds but different IDs
69a953f70d db: disable block cache on 64-bit

2026-06-25 | reindex-chainstate | 954459 blocks | dbcache 1024 | rpi5-16-3 | aarch64 | Cortex-A76 | 4 threads | 15Gi RAM | SSD

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 = 0e95e1abdb47adbc3342a2123f9f1be43d9a4f55)
  Time (abs ≡):        42596.443 s               [User: 62966.911 s, System: 3139.874 s]

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 = 69a953f70dc9a4f322a6c99d0e66acb548609e3b)
  Time (abs ≡):        41961.797 s               [User: 61711.896 s, System: 3097.761 s]

Relative speed comparison
        1.02          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 = 0e95e1abdb47adbc3342a2123f9f1be43d9a4f55)
        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 = 69a953f70dc9a4f322a6c99d0e66acb548609e3b)
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
for DBCACHE in 1024 10000; 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 1 \
    --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-29 | reindex-chainstate | 954459 blocks | dbcache 1024 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 threads | 62Gi RAM | SSD

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 (abs ≡):        20098.397 s               [User: 34707.701 s, System: 1066.261 s]
 
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 (abs ≡):        19834.950 s               [User: 34606.900 s, System: 1092.158 s]
 
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 (abs ≡):        19844.219 s               [User: 34655.128 s, System: 1080.368 s]
 
Relative speed comparison
        1.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 = 3c76bd435681ee2ebaa1f407ac23736d9c3b331b)
        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 = ecb530c63dab1802dc756d14180730dc7e15e15b)
        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 = a479f8a071a6719b5ff6f389af3c3f4c0cf40c36)

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 10000 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 threads | 62Gi RAM | SSD

Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=10000 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = 3c76bd435681ee2ebaa1f407ac23736d9c3b331b)
  Time (abs ≡):        17918.808 s               [User: 28933.064 s, System: 695.944 s]
 
Benchmark 2: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=10000 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = ecb530c63dab1802dc756d14180730dc7e15e15b)
  Time (abs ≡):        18161.775 s               [User: 29001.097 s, System: 683.110 s]
 
Benchmark 3: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=10000 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = a479f8a071a6719b5ff6f389af3c3f4c0cf40c36)
  Time (abs ≡):        18055.186 s               [User: 28973.671 s, System: 691.071 s]
 
Relative speed comparison
        1.00          COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=10000 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = 3c76bd435681ee2ebaa1f407ac23736d9c3b331b)
        1.01          COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=10000 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = ecb530c63dab1802dc756d14180730dc7e15e15b)
        1.01          COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=954459 -dbcache=10000 -reindex-chainstate -blocksonly -disablewallet -connect=0 -listen=0 -dnsseed=0 -printtoconsole=0 (COMMIT = a479f8a071a6719b5ff6f389af3c3f4c0cf40c36)

l0rinc and others added 2 commits June 29, 2026 10:44
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]>
@DrahtBot

DrahtBot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35620.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35568 (txospenderindex: disable bloom filters to optimize disk usage by andrewtoth)

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.

@sedited

sedited commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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.

@fanquake

fanquake commented Jul 1, 2026

Copy link
Copy Markdown
Member

#32375 also relevant. Not sure how much new code we should be adding for 32bit systems.

@l0rinc

l0rinc commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

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.
Would it be cleaner if I just disabled it regardless of the architecture?

@sedited

sedited commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Fully agree, but 32 bit builds don't have mmaped builds so they still need the cache.
Would it be cleaner if I just disabled it regardless of the architecture?

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?

@l0rinc

l0rinc commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

most of the cache allocation code, were removed

That's a bigger change, but it fits here, and the end result will be a lot cleaner.
I'll push it here and see what other reviewers think.

Do you see any benefit to giving the indexes more than the default amount of write buffer?

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.

@l0rinc
l0rinc marked this pull request as draft July 1, 2026 22:49
@l0rinc

l0rinc commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

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 | HDD
for 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.

@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@l0rinc

l0rinc commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants