Repository navigation
perf(alloc): free uncounted blocks under the bitmap lock alone, once per operation - #135
Merged
Merged
Conversation
…per operation Deletes took the global refcount lock for every file, even for blocks no snapshot or clone ever shared, and the bitmap lock once per block. With four nodes deleting, two thirds of their time went to the refcount lock. A block whose refcount reads 0 under the bitmap lock now goes straight back to the bitmap. Share is the only runtime code that raises a count, and it now does so under the bitmap lock too, skipping blocks already freed, so a zero count cannot change under a free. Counted blocks still go through Release under the refcount lock, after the bitmap lock is dropped, since Share takes refcount before bitmap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Say what the guard really proves: a zero count read under the bitmap lock stays zero while the block is freed, not that an allocated block is owned. Document that Increment, IncrementBatch, Set and SetFlags skip the guard. HoldAllocated now rejects a block past the end of the volume, so a corrupt extent fails with EIO instead of retrying, and freeing an already free block warns again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 14, 2026
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.
PR 2 of the per-node block reserve work. In the baseline probe on main with #130, deleting with 4 nodes spent 65–67% of node time waiting for the global refcount lock. Every delete took it, even though none of those files were ever shared.
A free now reads each block's count under the bitmap lock, which it takes anyway. A block with count 0 goes straight back to the bitmap, and all of an operation's blocks are freed in one hold. Share is the only runtime code that raises a count, and it now does so under the bitmap lock as well, skipping blocks already freed. So a zero count can't change under a free. Without that guard, a snapshot racing a truncate could leave count 1 on a free block, which fsck reports as an error.
TestShareWaitsForUncountedFreefails if the guard is removed. Counted blocks still go through Release, after the bitmap lock is dropped.TestCountedFreesAndSharesAcrossNodesfails if Release moves inside the bitmap hold.TestFsckRepairReclaimsLeakedBlocksmade its leaks by holding only the refcount lock. It now holds the bitmap lock too, since that's what a free waits on first.🤖 Generated with Claude Code