file_scan: block-aligned block-count estimate, clearer hole names (#89 review) - #94
Merged
Conversation
…review) Follow-up to the sparse-hole-skip work in #89, addressing crass's review comments on that PR. allocate_hashes() sized the block array from sum(fe_length)/blocksize + 1. FIEMAP extents are aligned to the filesystem block size (~4K), not to oans blocksize (128K default), so an extent can start and end mid-block and a partially-overlapped block is still read and hashed. The old estimate could therefore under-count by up to ~2 blocks per mapped extent, tripping the one-at-a-time realloc growth in add_block_hash() on fragmented files. Round each extent out to block boundaries before summing so the estimate never under-counts; adjacent extents sharing a block can over-count, but erring high only wastes a little memory once, so it is the safe bias for a preallocation. Also rename hole_run_at() -> hole_run_length() and the local `hole` -> `hole_length`: both name a byte length, not a position. No behavioural change to hashing or dedupe; verify.sh green (90 tests + valgrind smoke). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
martinus
force-pushed
the
sparse-block-estimate
branch
from
July 22, 2026 10:46
e8124fb to
af89c9b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up addressing @crass's review comments on #89 (sparse-hole-skip), now merged.
What
Block-count estimate no longer under-counts (
allocate_hashes). The oldcode sized the block array from
sum(fe_length) / blocksize + 1. FIEMAPextents are aligned to the filesystem block size (~4K), not to oans
blocksize(128K default), so an extent can start and end mid-block and apartially-overlapped block is still read and hashed. The estimate could
under-count by up to ~2 blocks per mapped extent, tripping the
one-at-a-time
reallocgrowth inadd_block_hash()on fragmented files.Each extent is now rounded out to oans-block boundaries before summing, so
the estimate never under-counts. Adjacent extents sharing a block can
over-count, but erring high only wastes a little memory once — the safe bias
for a preallocation. (crass's suggestion.)
Naming:
hole_run_at()→hole_run_length()and the localhole→hole_length. Both name a byte length, not a position.Not a bug fix
Correctness was never affected —
add_block_hash()already grows the arraywhen the estimate is short, so no hash or dedupe result changes. This just
avoids the realloc churn and reads more clearly.
Testing
scripts/verify.shgreen: build clean, 90 tests pass (incl. the sparse-filesuite), valgrind scan+dedupe+replay smoke clean.
🤖 Generated with Claude Code