4

I know that modern filesystem snapshots take very little space until they start to diverge by changes in files. However, I have been unable to identify at which granularity btrfs manages the changes. In other words, will a small change in a file cause the entire reallocation of the file in the changed snapshot, or only a subset of the file will be reallocated?

The reason is to know what to expect when working with snapshots of very large files.

Álex
  • 193
  • 1
  • 6

1 Answers1

3

Yes, btrfs does share parts of files in snapshots. It does not reallocate the entire file.

Snapshots work the same as other COW operations, according to the official wiki. The original blocks are pointed to in the snapshot, and if the file is changed in the snapshot, COW makes a new extent. COW does this whether there is none, one, or a hundred prior snapshots with the file.

Btrfs keeps track of the file data in lists of blocks called extents. When a block is updated, btrfs may copy the entire extent if it is small, or it may break the extent into pieces, keeping unchanged sections of the file as smaller extents called "bookends", plus the new changed section. These new smaller bookend extents are just new pointers to the original data blocks, so the unchanged data is not copied. See Wikipedia extent description.

So snapshots will share the unchanged blocks in a large file.

(Note that you can turn off COW on a large file, but then you can't snapshot it, from what I have read.)

Grunthos
  • 339
  • 1
  • 6