fix [#163]: uses reflinking on CoW filesystems like btrfs #164
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.
TL;DR:
Current behavior:
This PR (only on btrfs and other CoW filesystems):
Details:
Currently, ABRoot just copies the entire root from the mounted image to a new folder in the future partition called /.system.new
This can be improved on CoW filesystems like btrfs by using reflink copying.
In this implementation, the /part-future/.system.new folder is reflink copied from the /part-future/.system folder. Rsync will then make the changes needed to mirror the image.
This means that most of the data can be reflinked instead of copied which has a couple of important benefits:
Currently, during an abroot operation, the copied .system.new will take up roughly as much space as each of the .system folders in a and b.
With this approach, the .system.new folder will just take up space for the needed changes.
Since only the changes are copied there are way less disk write operations which is especially important on SSD drives which have limited write cycles.
I made a quick (but very unscientific) comparison in a VM: (cloned to be identical across tests)
5 min 10 sec
2 min 24 sec
52 sec
(This was the time it took to run abroot pkg apply with netris as a new package)
The whole thing has one minor caveat: Files which have exactly the same modification time and size will not be synced, since this is the default behavior of rsync. I can not think about a realistic scenario in which that would happen tho.
If this tiny risk is unacceptable tho then I would still prefer using this approch but with the -c (checksum) rsync flag. Files will be compared by their checksum. This requires all files to be read to compute their checksum before copying tho so it takes a lot longer (in my tests still less then with the current approach on small changes)
I want to mention a couple of things:
A version to test can be downloaded here: https://github.com/taukakao/ABRoot/releases/tag/reflink-system-fast
(All bugs that I've encountered are present in the current abroot as well)