Skip to content

ibd: prefetch next-batch parent body ranges (needs Linux measurement) - #1299

Closed
Hero-Gamer wants to merge 5 commits into
reardencode:masterfrom
Hero-Gamer:ibd/prefetch-next-batch-parent-ranges
Closed

Hero-Gamer wants to merge 5 commits into
reardencode:masterfrom
Hero-Gamer:ibd/prefetch-next-batch-parent-ranges

Conversation

@Hero-Gamer

Copy link
Copy Markdown
Contributor

Idea (from Grok)

Prefetch next-batch parent body ranges while current batch is in scripts/write stage, to reduce load_cold_range_body_ms stall.

Overlaps kernel readahead of N+1 batch with load(N) || scripts(N-1) || write(N-2).

Impl (85 insertions, 42 behavior)

  • file.rs: advise_will_need - Linux posix_fadvise(WILLNEED) wrapper, trace on failure, no-op on Mac
  • lookup.rs: body_ranges_iter() + prefetch_parent_body_ranges()
    • Gate: skip if total <1MiB (avoid fadvise overhead)
    • Calls advise_tx_body_will_need for each range in parent_pin
    • Records prefetch_bytes, prefetch_ns
  • confirm_stats.rs + perf_log.rs: counters wired to ibd:perf JSON
  • var_table.rs/tx_table/store.rs: plumbing

Linux-only, no behavior change on Mac.

Status

  • ✅ Clippy clean: cargo clippy -p rbitcoin-query -p rbitcoin-store -p rbitcoin-ibd --lib -- -D warnings
  • ✅ Logic tested on Mac M4: gate works (>1MiB prefetch, <1MiB skip)
  • ❌ NOT measured on Linux yet - I only have Mac Mini M4, WILLNEED is no-op here

Needs

Linux signet IBD measurement, two runs with RUST_LOG=ibd:perf=debug:

  1. Baseline: ee66131a (fix/peerhub-single-clock-v2)
  2. With prefetch: this branch

Compare load_cold_range_body_ms when load_pin_new>0 vs prefetch_bytes/prefetch_ns. Expect 5-10% win.

Can someone with Linux box run this and share ibd:perf logs?

Diff

git diff ee66131a..HEAD --stat = 7 files, 85 insertions
Behavior commit: 42 lines

- PeerHub::new(clock: Arc<NodeClock>) where NodeClock::new()->Arc<Self>
- Remove mock_now/set_mock_now second battery from PeerHub
- Add on_clock_jump() that requests tx INVs, runs heartbeat, queues self-announce
- service.rs: share hub.clock.clone() so setmocktime reaches peers via same Arc
- mine.rs: setmocktime writes ChainHub clock once, then peers.on_clock_jump()
- Migrate journey tests: hub.clock.set_mock(x) + on_clock_jump()
Fixes second mock battery noted in reardencode#821 Step 2.
No prod behavior change: clock jump now triggers same INV + heartbeat as before,
but via single NodeClock source.
Tested: 660 rbitcoin-net journey tests pass, fmt + clippy clean.
Add WILLNEED wrapper next to existing DONTNEED, for
prefetching next-batch parent body ranges during IBD.
Linux only, no-op elsewhere, trace on failure.
No behavior change yet.
- store: add advise_will_need (WILLNEED) next to DONTNEED
- query: add ParentPinStamp::body_ranges_iter() for next-batch prefetch

No behavior change yet, helpers for gated prefetch.
- query ConfirmWindow: prefetch_bytes, prefetch_ns via confirm_window! macro
- ibd perf_log: prefetch_bytes, prefetch_ns fields + mapping from window

No behavior yet, just counters to measure Grok's prefetch idea. Gated
prefetch will populate these when pin_new !=0 and batch >1MiB.
…ripts/write

- store: TableFile::advise_will_need (WILLNEED wrapper), VarTable/TxTable/Store wrappers
- query: ParentPinStamp::body_ranges_iter helper + prefetch_parent_body_ranges()
  Gated: total_bytes > 1MiB to avoid fadvise overhead on small batches
  Records prefetch_bytes/ns into ConfirmStats, exposed as ibd:perf prefetch_bytes/ns
- ibd: perf_log mapping for new counters
- No behavior change on non-Linux (no-op), trace on fadvise failure
- Expected win: 5-10% less cold_range_body stall when pin_new!=0, overlaps
  kernel readahead of N+1 parent bodies with scripts(N) / write(N-1)

Implements Grok's prefetch idea, 1st behavior commit. Keep under 150 lines.
@Hero-Gamer

Copy link
Copy Markdown
Contributor Author

Superseded by #1300 clean scoped PR (7 files 106 ins, coalesced, gated). Closing.

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.

1 participant