I was just toying around with one of my LXD containers that has a loopback zfs volume. One strange thing I noticed is this:
I had 1.5GB of data stored in my container “test”. And then I deleted 300mb data. I was left with 1.2GB of data inside but then when I came back to host to check the size of my loopback volume file, it was still 1.5GB.
For the second test I duplicated 300mb twice inside the container. Thus I had now 1.8GB of data inside. Then I came back on host to check the loopback file size and it was 1.8GB.
The strange part is that size of loopback file is increasing on data addition but not decreasing on data deletion.
Is this normal behaviour or is something wrong with my setup?
This is expected behavior, and is related to how sparse files work.
When you first create the loopback file, it does not allocate all the space that you have specified.
Here is my just-created loopback file,
$ lxc storage create myloopback zfs size=3GB
Storage pool myloopback created
$ sudo du -h /var/snap/lxd/common/lxd/disks/myloopback.img
2,4M /var/snap/lxd/common/lxd/disks/myloopback.img
$
As you are using LXD and creating containers, the reported size of the myloopback.img will only increase, until it reaches the allocated size.