Repository navigation
A Writer no longer holds every name it ever removed: 300,000 names made and removed keep under 8 MiB instead of 89 to 270 - #305
Open
closer-claudio wants to merge 1 commit into
Conversation
…g of it A name removed from a Writer stayed in its directory's list of children, marked removed, for the Writer's life: nothing took it out, and every reader of the list stepped over it. A name made and removed over and over grew the Writer by an entry each time (300,000 rounds: about 90 MiB), and every pass over the directory walked them all. Now an entry knows its place among its parent's children and leaves the list when its name is removed: the last child takes its place, the list's order being no one's (ReadDir and Close sort). A children list holds no removed entry, so the readers that stepped over them no longer look. Two walks remove entries of the list they are walking, where taking one out would move the last child under the walk. They drop the names and settle the list themselves once done: RemoveAll and a directory that a copy turns into a file empty it; a marker of a merged layer sifts out what it removed and gives the entries it spared their new places. An entry written over in place by a later copy, and the name that takes over a removed first name's file, are copies of another entry: each keeps its own place. The list of a file's other names keeps a removed name until the file's last other name goes or a handover passes over it, and was then all that held the entry: it drops the removed once they outnumber the live, at a cost each removal has paid for. What is not given back: the capacity a map and a list keep of the most they held at once (300,000 names made and then removed: 16 MiB, where the names themselves were 108). Removal costs what it did: BenchmarkPerfRemoveLinkedNames and BenchmarkPerfRemoveNamesOfOneInode on the commit before and here, two runs each, alternated: every pair of ranges overlaps (16,000 linked files 1.2 to 1.4 ms and 1.1 to 2.0 ms; 80,000 names of one file removed one at a time 7.1 to 10.1 ms and 9.9 to 11.5 ms). Tests, in contract_writer_removal_test.go. TestContractWriterHoldsNothingOfARemovedName: the heap in use after 300,000 rounds of a directory made and removed, of a file's other name made and removed beside one that stays, of a directory removed with what it holds, each under 8 MiB, and after 300,000 names made and then each removed, under 32. All four fail before the change (89, 92, 270 and 108 MiB). TestContractWriterLeavesWhatItsCallsLeave: 600 random sequences of Create, Mkdir, Link, Remove and RemoveAll against a model of the tree: the image holds the model's names, each file's content, one inode for the names that share one, the link counts that follow. It passes before the change: the behaviour is the same. TestContractRemovingWhatACopyPlaced: a name removed after a copy wrote over it, after its layer's opaque marker spared it, a spared directory whose earlier entries the marker took, and a name that stopped being a directory. Broken twelve ways, each fails a test: the heir or the overwritten entry losing its place, the moved sibling keeping its old one, no new place after the sift, no sift, a removed directory keeping its list, no detach, a new child without a place, the freed slot not cleared, the alias list unbounded, a marker dropping its own layer, a directory with entries removed. For #297 Signed-off-by: closer-claudio <claudio@farcloser.world> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
closer-claudio
enabled auto-merge
November 23, 2026 09:33
Author
|
Reviewed at 9a924e8 |
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.
The defect
A name removed from a Writer stayed in its directory's list of children, marked removed, for the Writer's life: nothing took it out, and every reader of the list stepped over it. A name made and removed over and over grew the Writer by one entry each time, and every pass over the directory walked them all.
The change
An entry knows its place among its parent's children and leaves the list when its name is removed: the last child takes its place. The list's order is observed by no one (the Writer's
ReadDirandCloseboth sort). A children list now holds no removed entry, so the readers that stepped over them no longer look.RemoveAll, and a directory that a copy turns into a file, empty it; a marker of a merged layer sifts out what it removed and gives the entries it spared their new places.What a consumer sees
The same images, byte for byte, and the same answers from every call. A long-lived Writer, or one that merges many layers with whiteouts, no longer grows with every name it removed.
What is not given back, in the last row: the capacity a map and a list keep of the most they held at once.
Removal costs what it did:
BenchmarkPerfRemoveLinkedNamesandBenchmarkPerfRemoveNamesOfOneInode, before and after, alternated: the ranges of every shape overlap (16,000 linked files 1.2 to 1.4 ms beside 1.1 to 2.0 ms; 80,000 names of one file removed one at a time 7.1 to 10.1 ms beside 9.9 to 11.5 ms).Evidence
In
contract_writer_removal_test.go:TestContractWriterHoldsNothingOfARemovedName: the heap in use after the four shapes above, the first three under 8 MiB and the last under 32. All four fail before the change.TestContractWriterLeavesWhatItsCallsLeave: 600 random sequences ofCreate,Mkdir,Link,RemoveandRemoveAllagainst a model of the tree: the image holds the model's names, each file's content, one inode for the names that share one, and the link counts that follow. It passes before the change, the behaviour being the same.TestContractRemovingWhatACopyPlaced: a name removed after a copy wrote over it, after its layer's opaque marker spared it, a spared directory whose earlier entries the marker took, and a name that stopped being a directory.Broken twelve ways, each fails a test: the heir or the overwritten entry losing its place, the moved sibling keeping its old one, no new place after the sift, no sift, a removed directory keeping its list, no detach, a new child without a place, the freed slot not cleared, the alias list unbounded, a marker dropping its own layer, a directory with entries removed.
just lintandjust testpass.For #297
Not changed here: removing every name of one file one at a time, the holding name first, still costs the square of their number: #296.