Why Do Snapshots Increase in Size?

Status
Not open for further replies.

dakotta

Dabbler
Joined
Oct 12, 2018
Messages
42
I don't understand why snapshots increase in size.

(I'm reading through the User Guide and I'm only as far as the introduction, but it is suggesting I read the ZFS Primer -- maybe I shouldn't worry about this right now and keep on plugging away?)

Let's make this simple. Let's say my pool is 100 MB. One of the files in the pool, dakota.ods, is 10 MB.

If I create a snapshot of the pool, the data doesn't change, right? All I'm doing is creating a new set of pointers to the original data. Let's say those pointers originally take up 10 KB.

So, one month later, I modify dakota.ods so it is now 20 MB. With a COW system, this modified file gets written to disk and verified before the old data block is marked for deletion. Except that the old data block has pointers that identify it as part of a snapshot, so it won't get deleted until that snapshot is deleted.

The old snapshot pointers still exist and haven't changed. So the snapshot isn't any bigger.

Or is it?

Does the old data now become part of the snapshot? Is a snapshot more than just a set of pointers?

I know this is all pretty basic, but I'm having a hard time following along because I'm missing something very simple.

Cheers,
 

garm

Wizard
Joined
Aug 19, 2017
Messages
1,555
Snapshots aren't pointers, they are time stamps.
ZFS is a tree of blocks and each block has a set of metadata, one of which is its birth date. Any block with a birth date older than the snapshot time stamp is part of that snapshot.
What happens is something like this; your 10 MB file gets written to 79 128k blocks and you take a snapshot. You then change 5 MB of the file causing 40 new blocks to be written. Then ZFS will try and remove the outdated 40 blocks and while its doing that its checking to see if any block is part of a snapshot, leaving them alone if they are. Thus you now have a "snapshot" worth 5 MB.
 

artlessknave

Wizard
Joined
Oct 29, 2016
Messages
1,506
each snapshots size represents the data unique to that snapshot. if you have 2 snapshots with identical data to the pool, the snapshots will have 0 bytes, but each change after any snapshots instant locks those blocks until every older referencing snap is removed.
its magical but if you are keeping snapshots a long time and making large changes you can eat your pool up pretty fast as you have to reserve space for each snapshot.
if you have a 50 GB pool, take a snap at 40GB, and then delete all the files, you will have a 40GB snap, 0 "used" pool space, 40GB allocated space, and 10GB free space.
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
To throw one more explanation on here, the snapshots are reporting their "unique" bytes. In other words, the amount of data that is only held in that snapshot. Let's say you write 10 GB of data, take a snaphot, write 5 GB, take a snapshot, and delete all the data. You'll have: snapshot 1 at 0 bytes (all 10 GB is shared with "2"), snapshot 2 at 5 GB (the other 10 GB is shared with "1"), and the pool at 0 USED and 15 USEDSNAP (or CHILD or something, I forget the naming). If you delete snapshot 2, snapshot 1 will now report 10 GB because the thing that was sharing those bytes has gone away.

Reporting in this way can be confusing because you need to look at that "usedsnap" column. It does help however to see how much data can be freed by removing a snapshot.
 

kdragon75

Wizard
Joined
Aug 7, 2016
Messages
2,457
Snapshots aren't pointers, they are time stamps.
ZFS is a tree of blocks and each block has a set of metadata, one of which is its birth date. Any block with a birth date older than the snapshot time stamp is part of that snapshot.
What happens is something like this; your 10 MB file gets written to 79 128k blocks and you take a snapshot. You then change 5 MB of the file causing 40 new blocks to be written. Then ZFS will try and remove the outdated 40 blocks and while its doing that its checking to see if any block is part of a snapshot, leaving them alone if they are. Thus you now have a "snapshot" worth 5 MB.
That's a fantastic and clear explanation. thank you for sharing that.
 

dakotta

Dabbler
Joined
Oct 12, 2018
Messages
42
I know it is terribly rude to post a question and then vanish... but as soon as I posted this, all kinds of things popped up at work and I've simply had no time to visit the forum. :mad:

I just want you all to know that I appreciate your answers, especially garm, whose answer was very clear. :cool:

Cheers,
 
Status
Not open for further replies.
Top