XQLRSZ
XQLRSZ

Reputation: 140

How do BTRFS and ZFS snapshots work?

More specifically, how do they manage to look at the entire subvolume and remember everything about it (files, sizes of files, folder structure) while fitting it into such a small amount of data.

Upvotes: 1

Views: 649

Answers (1)

PythonNut
PythonNut

Reputation: 6379

Suppose I have a list of names:

Joe
Bob
Fred

You tell me to remember this list. So I go, okay:

Joe
Bob
Fred
(as of 06/01/15)

The next day, you tell me to add the name "John" to the end of the list. I then copy over the list to get:

Joe
Bob
Fred
(as of 06/01/15)

Joe
Bob
Fred
John
(current)

This is the super simple description of how a snapshot works. The filesystem leaves itself a note of when the snapshot took place, and then when changes are made, it will make a fresh copy from the snapshot and write to that instead.

Of course, the snapshot is on-demand. Only the parts of files you write to will be copied. The net effect from a high-level point of view is that BTRFS "freezes" the files and then records future changes as deltas against the frozen data. Of course, the deltas can be stacked and branched etc.

To answer your question, the act of saying "Note to self: Don't touch these files!" doesn't take much time at all.

Upvotes: 1

Related Questions