Why longhorn volume still shows more space than the actual size after deleting the content?

Follow
Table of Contents

Question

Why does Longhorn report higher Actual Size for a volume than the usage reported by the filesystem, even after deleting content?

Pre-requisites

  • A Kubernetes cluster with Longhorn installed
  • An existing workload using a Persistent Volume (PV) of the Longhorn StorageClass (SC)

Answer

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:

  1. 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
  2. Remove the 4gbfile from the mounted volume:

    rm 4gbfile
  3. Check the usage reported by the filesystem, by running du -sh on the mounted volume, which will show 2GB.

  4. Navigate to the Longhorn UI and check the Actual Size, reported under Volume Details in the Volume view, which will show 6GB of usage still.

Further Reading

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.