1

I have a Centos7 system with zfs pool that I took a snapshot with sudo zfs snapshot -r data-pool/Samba@backup_r. After taking the snapshot I copied few gigabytes of files from my Windows pc to that pool (it is mapped as samba share). After copying I took a snapshot with sudo zfs snapshot -r data-pool/Samba@backup_r2.

I was suprised that zfs list -o space -r data-pool reports 0 as a size for both of these snapshots in USED and USEDSNAP fields of the output.

Why is the size of both of these snapshot reported as 0? If I have understood correctly the snapshots in ZFS filesystems are incremental so I assumed the latter snapshot should have reported size of that amount of data that I copied to the samba share.

2 Answers 2

3

A snapshot will only increase in size if you change or delete files which were present in the data set at the time the snapshot was taken.

ZFS is using copy-on-write snapshots, meaning that if a data block is about to be changed, a new copy of the block including the changes is being written to a different location in the storage pool and references in the relevant data set / volume are updated.

Snapshots have a size of zero if none of the blocks that were used by the data set at the time of the snapshot have been modified, thus the snapshot only differs from the current version of the data set in metadata only.

1
  • Is it possible to remove size 0 snapshots from zfs list?
    – Sawtaytoes
    Apr 7, 2023 at 5:55
1

It is important do understand that USED only counts the unique data contained in that specific snapshot. From the man page:

The used space of a snapshot (see the Snapshots section of zfsconcepts(7)) is space that is referenced exclusively by this snapshot. If this snapshot is destroyed, the amount of used space will be freed. Space that is shared by multiple snapshots isn't accounted for in this metric.

In other words, it is possible to have multiple snapshots with USED == 0 but which collectively use much space. As an example, take a look at this test pool:

# write some data
root@localhost:~/test# dd if=/dev/zero of=/tank/test bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB, 128 MiB) copied, 3.58123 s, 37.5 MB/s

# current pool usage
root@localhost:~/test# zfs list -t all -o space
NAME  AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
tank   704M   128M        0B    128M             0B       178K

# create a snapshot and check used space - no surprises here
root@localhost:~/test# zfs snapshot tank@snap1
root@localhost:~/test# zfs list -t all -o space
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
tank         704M   128M        0B    128M             0B       174K
tank@snap1      -     0B         -       -              -          -

# create a second snapshot and check uses space - again, no surprises
root@localhost:~/test# zfs snapshot tank@snap2
root@localhost:~/test# zfs list -t all -o space
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
tank         704M   128M        0B    128M             0B       170K
tank@snap1      -     0B         -       -              -          -
tank@snap2      -     0B         -       -              -          -

# now overwrite some data
root@localhost:~/test# dd if=/dev/zero of=/tank/test bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB, 128 MiB) copied, 3.58123 s, 37.5 MB/s

# As both snapshots reference the same overwritten data, both report 0 bytes USED
# however USEDSNAP shows 128M are really used
root@localhost:~/test# zfs list -t all -o space
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
tank         577M   255M      128M    127M             0B       200K
tank@snap1      -     0B         -       -              -          -
tank@snap2      -     0B         -       -              -          -

# WRITTEN shows the true story
root@localhost:~/test# zfs list -t all -o space,written
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD  WRITTEN
tank         576M   256M      128M    128M             0B       207K     128M
tank@snap1      -     0B         -       -              -          -     128M
tank@snap2      -     0B         -       -              -          -        0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .