Skip to content

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
mainfrom
claudio/20261123-removed-entries
Open

closer-claudio wants to merge 1 commit into
mainfrom
claudio/20261123-removed-entries

Conversation

@closer-claudio

Copy link
Copy Markdown

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 ReadDir and Close both sort). A children list now 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 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 ones once they outnumber the live.

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.

300,000 times Heap held before After
a directory made and removed 89 MiB under 8 MiB
a file's other name made and removed 92 MiB under 8 MiB
a directory removed with what it holds 270 MiB under 8 MiB
300,000 names made, then each removed 108 MiB 16 MiB

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: BenchmarkPerfRemoveLinkedNames and BenchmarkPerfRemoveNamesOfOneInode, 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 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, 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 lint and just test pass.

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.

…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

Copy link
Copy Markdown
Author

Reviewed at 9a924e8

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