Thinly provisioned virtual disk doesn't reuse empty space

Latest response

I have a thinly provisioned 100GB data disk created with RHEVM 3.0.  I can see the allocated storage grow as I create a 50GB file.  After deleting the 50GB file and confirming it's gone with a "df -k" on the VM, I create a new 50GB file.  Rather than re-using the previously allocated 50GB, another 47GB is allocated for a total of 97GB allocated even though I never actually had more than 50GB on the virtual disk.

 

I'm using FC SAN.

Responses

Just like in a physical machine, the space allocated by the file was not really deleted - only the 'pointers' to it (inodes in Linux, entries in MFT on Windows). Therefore, from QEMU/KVM point of view, it has no idea the space was reclaimed.

Both qcow2 and raw formats are operating at the block level, thus they can only reduce the size of zeroed out blocks

 

Try the following, I'm creating here two files, one with real data the other all zeros:

 

# sudo dd if=/dev/sda of=ttt bs=128k count=1024
# ll -h ttt*
--> -rw-r--r-- 1 root   root   128M Nov 19 11:02 ttt
# sudo dd if=/dev/zero of=ttt.0 bs=128k count=1024
--> -rw-r--r-- 1 root   root   128M Nov 19 11:03 ttt.0
 

Now let's use qemu-img to convert to qcow2

# qemu-img convert ttt -O qcow2 ttt.new
# qemu-img convert ttt.0 -O qcow2 ttt.new.0
# ll -h ttt*
--> -rw-r--r-- 1 root   root   128M Nov 19 11:02 ttt
--> -rw-r--r-- 1 root   root   128M Nov 19 11:03 ttt.0
--> -rw-r--r-- 1 simong simong 120M Nov 19 11:06 ttt.new
--> -rw-r--r-- 1 simong simong  16K Nov 19 11:07 ttt.new.0

Like you can see, only the zero blocks are reduced.

It does not mean the problem is unsolvable and it's on the road map, with the introduction of libguestfs for example, it is possible to be file system aware and try to reclaim blocks. It does however require a change to many components to do this live, a bit less to do this offline.

If you are willing to do this offline (IE periodic maintenance) I can think of some probable methods to achieve that using API scripting and may be hooks.
Please tell me if you are interested and I'll try these and update here.

I'm not interested in an offline solution right now but thanks for the offer.