Clone zeros in pieces as large as the largest chunk - #440
Merged
Merged
Conversation
The null seed cloned runs of zeros from a file one block long, so every block of zeros written over existing data was its own clone and its own extent. Size the file of zeros to the largest chunk instead, rounded up to full blocks, and clone each run in pieces of that size.
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.
When zeros are written over existing data on a filesystem that supports reflinks, the null seed clones them from a temporary file of zeros. That file was one block long, so each 4 KiB block of zeros was a separate
FICLONERANGEcall and ended up as a separate extent. Blank targets aren't affected since #439, which leaves zeros out of them, but updates over existing data are.The file of zeros is now as large as the largest chunk, rounded up to full blocks: 256 KiB with the default chunk sizes. Runs of zeros are cloned in pieces of that size, and only the last piece is shorter. The unaligned head and tail are still written as zeros, and a failed clone still falls back to writing zeros.
Measurement
These are Debian 13 cloud images (3 GiB raw, about 2 GiB of it zero chunks) on btrfs, each updated in place to 20260909 with #323 applied (
extract -k --seed old.caibx:target). There were two runs per case. Every result matched the image's md5.A plain extract over an existing image on master writes only about 65 MiB of zeros, because the rest is already in place. There, the extent count varies between 3k and 10k from run to run with either binary, so that case shows no measurable difference.
The temporary file now takes up
ChunkSizeMaxbytes instead of one block while an extract runs.