online fstrim in ext4 for local qcow2 image

ddio

New Member
Nov 9, 2015
2
0
1
Hi,
I want to get fstrim working with no luck so far.
What I did so far:
1. Switched from virtio-blk to virtio-scsi (changed the disc to scsi0 and changed the emulated scsi-controller to VIRTIO)
2. Switched discard=on as parameter for the disk
3. mounted the ext4 filesystem with discard
It is working so far, that I can do fstrim -v /, and there is nothing to be trimmed, but the qcow2 file is increasing (double the size of the occupancy rate of the filesystem).

I got it only working with shutting down the vm and converting the disk as stated in Shrink_Qcow2_Disk_Files#Linux_Guest_Preparation in pve wiki (sry I am not allowed to post an link), but for that the vm has to be shutdown...
Am I missing sth?
Thanks!
 
Last edited:
Hi,
it is not necessary to activate trim inside a Vm if you use a image.
It is enough if you enable it on the host.
The effective io on the ssd will managed by the host kernel and not by the vm kernel.

here a good information on linux and ssd for the host

https://wiki.archlinux.org/index.php/Solid_State_Drives
 
Hi,
it is not necessary to activate trim inside a Vm if you use a image.
It is enough if you enable it on the host.
The effective io on the ssd will managed by the host kernel and not by the vm kernel.

here a good information on linux and ssd for the host


I have no trim support on the host (it has normal hdds), but I want to save disk space with trim (already overprovisioned).

Does this mean this is only possible if you have trim support for the storage on the hypervisor?
 
TRIM inside the vm will overwrite the unused parts with zeroes, but you will have to compact the qcow2 image from outside (by creating a copy for example), it does not shrink by itself.
 
Note that you don't need to mount your fs with discard=on, to use fstrim.

if you use discard=on, trim will be done at each delete in your filesystem, and this can be quite slow.

It's better to simply add a cron, daily for example, which launch fstrim. (without any discard=on)
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!