Fstrim with unmap does not reclaim disk space

Hello
I’m struggling with fstrim: does not reclaim disk space
I have a OpenNebula 5.12.0.1 installation on CentOS 8.
Here’s my KVM VM template:

    DISK = [
  ALLOW_ORPHANS = "NO",
  CACHE = "none",
  CLONE = "YES",
  CLONE_TARGET = "SYSTEM",
  CLUSTER_ID = "0,100,101,102",
  DATASTORE = "default",
  DATASTORE_ID = "1",
  DEV_PREFIX = "sd",
  DISCARD = "unmap",
  DISK_ID = "0",
  DISK_SNAPSHOT_TOTAL_SIZE = "0",
  DISK_TYPE = "FILE",
  DRIVER = "qcow2",
  IMAGE = "Centos 8 clean",
  IMAGE_ID = "1",
  IMAGE_STATE = "2",
  IO = "native",
  LN_TARGET = "SYSTEM",
  ORIGINAL_SIZE = "4096",
  READONLY = "NO",
  SAVE = "NO",
  SIZE = "4096",
  SOURCE = "/var/lib/one//datastores/1/70e28680532aed554240192b8a1c56ea",
  TARGET = "sda",
  TM_MAD = "ssh",
  TYPE = "FILE" ]

I have created a file with random data in it.
I saw the disk.0 size increase from 480Mb to 1.4Gb
I deleted the generated file. The disk space in the guest VM decreased.
Then i run fstrim:

[root@VM-208 ~]# fstrim -av
/: 3.2 GiB (3390345216 bytes) trimmed

the size of disk.0 in the host always 1.4Gb

-rw-r--r-- 1 oneadmin oneadmin 1,4G 20 ago 11.45 disk.0

I have tried both “SCSI/SATA” and “VIRTIO” bus type – apart a change in the disk device from sda to vda, the result is the same.

What am I missing?

Any thoughts on this?
Does anybody faced an issue like this?

Thanks in advance

You shou;d look for the allocated file size because the image is sparse.
So you should use du or ls -s

Hope this helps.

Best Regards,
Anton Todorov

2 Likes

Thank you @atodorov_storpool
You’ve made my day!

I verified that using “ls -s” the size actually decreased after “fstrim -av”
All right - Thanks again for your help

Marco