Removing files on ZFS does not free disc-space

disk-spacesolariszfs

I'm trying to free space on a ZFS by removing files. They are large (>1GB) so it should show in the numbers. Unfortunately, after unlinking the files, df does not show any increase in available space. It seems as if the removed files have hardlinks somewhere (but ls shows hardlink counters of 1 for all files unless I create a hardlink manually (which I tested)).

The script removing the files opens, reads, and closes these files (I checked that), so there are no open file handles. Afterwards it uses unlink() to remove the files. ls also does not show them anymore. Just the available disk space does not increase.

We are using the ZFS feature of snapshots. Maybe this is a reason why nothing is freed?

Any ideas or hints to documentation concerning my problem are welcome.

Best Answer

According to Oracle's zfs documentation,

A snapshot is a read-only copy of a file system or volume. Snapshots can be created almost instantly, and they initially consume no additional disk space within the pool. However, as data within the active dataset changes, the snapshot consumes disk space by continuing to reference the old data, thus preventing the disk space from being freed.

If you want the disk space to be freed, you will have to clear out the snapshots referencing that file. You may also want to read up on copy-on-write, which is how zfs works.

I don't actually have any experience with zfs, but I make use of btrfs. btrfs does snapshots in a similar manner to zfs and the exact same 'issue' appears there. Of course, as I do not want a deleted file in the current working set to be removed from a snapshot, I would certainly expect that the available disk space would remain constant when removing a file. After all, the file isn't actually removed until all references (across all snapshots) are removed.

Related Question