Ask for continuous discard where the runtime makes an ext4 - #870
Open
MayCXC wants to merge 1 commit into
Open
Conversation
A container's root filesystem and writable layer are sparse files, and the guest never returns the blocks it frees: deleting inside the guest frees guest blocks, the host file keeps every block it has ever touched, so its real size is the high water mark of everything ever written rather than what is live. The filesystem hands freed blocks back the moment they are freed when its mount asks for discard, and the runtime forwards those discards to hole punches in the backing file. The ask belongs to the file: every ext4 the runtime creates is such a sparse file, so its mount options carry discard from the moment the mount exists, and every place the file is later mounted, container or pod, lower layer or writable, inherits the ask with the rest of the options. A read-only mount parses the option and leaves it idle, and a caller who builds a mount of their own chooses their own options, as they do for everything else. The swap area has asked for the same thing since it was added, for the same reason.
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.
Summary
A container's root filesystem and writable layer are sparse files, and the guest never returns the blocks it frees: deleting inside the guest frees guest blocks, the host file keeps every block it has ever touched, so its real size is the high water mark of everything ever written rather than what is live.
The filesystem hands freed blocks back the moment they are freed when its mount asks for discard, and the runtime forwards those discards to hole punches in the backing file. The ask belongs to the file: every ext4 the runtime creates is such a sparse file, so its mount options carry
discardfrom the moment the mount exists, and every place the file is later mounted, container or pod, lower layer or writable, inherits the ask with the rest of the options. A read-only mount parses the option and leaves it idle.Motivation and Context
This is the continuous counterpart to an explicit trim: rather than reclaiming in a sweep after the fact, the filesystem returns each block as it is freed, and the backing file stops growing to its high water mark.
Putting the option on the mount where the file is created, rather than at each place it is mounted, means a caller cannot forget it, and the two do not drift apart as more mount sites appear.
Relationship to #859
#859 adds an explicit trim that returns blocks on demand and reports how many. The two are complementary: continuous discard keeps a live filesystem from growing, while a trim reclaims what a filesystem that has been running without it already holds. Neither depends on the other, and they touch different files.
Testing
swift buildandmake checkclean.swift test: 595 tests in 82 suites passed.Type of Change