Skip to content

file_scan: block-aligned block-count estimate, clearer hole names (#89 review) - #94

Merged
martinus merged 1 commit into
masterfrom
sparse-block-estimate
Jul 22, 2026
Merged

file_scan: block-aligned block-count estimate, clearer hole names (#89 review)#94
martinus merged 1 commit into
masterfrom
sparse-block-estimate

Conversation

@martinus

Copy link
Copy Markdown
Owner

Follow-up addressing @crass's review comments on #89 (sparse-hole-skip), now merged.

What

  1. Block-count estimate no longer under-counts (allocate_hashes). The old
    code 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 estimate could
    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.
    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.)

  2. Naming: hole_run_at()hole_run_length() and the local hole
    hole_length. Both name a byte length, not a position.

Not a bug fix

Correctness was never affected — add_block_hash() already grows the array
when the estimate is short, so no hash or dedupe result changes. This just
avoids the realloc churn and reads more clearly.

Testing

scripts/verify.sh green: build clean, 90 tests pass (incl. the sparse-file
suite), valgrind scan+dedupe+replay smoke clean.

🤖 Generated with Claude Code

…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
martinus force-pushed the sparse-block-estimate branch from e8124fb to af89c9b Compare July 22, 2026 10:46
@martinus
martinus merged commit 392c838 into master Jul 22, 2026
4 checks passed
@martinus
martinus deleted the sparse-block-estimate branch July 22, 2026 10:49
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