Why does Longhorn report higher
Actual Size for a volume than the usage reported by the filesystem, even after deleting content?
- A Kubernetes cluster with Longhorn installed
- An existing workload using a Persistent Volume (PV) of the Longhorn StorageClass (SC)
Whilst Longhorn storage is thin-provisioned, a volume cannot shrink in size after content is removed.
Per the Longhorn Documentation: "This happens because Longhorn operates on the block level, not the filesystem level, so Longhorn doesn’t know if the content has been removed by a user or not. That information is mostly kept at the filesystem level."
You can demonstrate this behaviour, by attaching a 10GB Longhorn volume to a Pod, creating 6GB of files on the volume and then deleting 4GB, as follows:
Increase the disk usage of the volume:
dd if=/dev/zero of=4gbfile bs=4G count=1 dd if=/dev/zero of=2gbfile bs=2G count=1
4gbfilefrom the mounted volume:
Check the usage reported by the filesystem, by running
du -shon the mounted volume, which will show 2GB.
Navigate to the Longhorn UI and check the
Actual Size, reported under
Volume Detailsin the Volume view, which will show 6GB of usage still.