Skip to content

perf(alloc): free uncounted blocks under the bitmap lock alone, once per operation - #135

Merged
mattmattox merged 3 commits into
mainfrom
perf/free-path
Nov 14, 2026
Merged

mattmattox merged 3 commits into
mainfrom
perf/free-path

Conversation

@mattmattox

Copy link
Copy Markdown
Contributor

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. TestShareWaitsForUncountedFree fails if the guard is removed. Counted blocks still go through Release, after the bitmap lock is dropped. TestCountedFreesAndSharesAcrossNodes fails if Release moves inside the bitmap hold.

TestFsckRepairReclaimsLeakedBlocks made 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

mattmattox and others added 3 commits November 13, 2026 23:02
…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>
@mattmattox
mattmattox merged commit b5d1825 into main Nov 14, 2026
17 checks passed
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