[Solved] How to trim / discard on thin LVM backed KVM ?

mailinglists

Renowned Member
Mar 14, 2012
641
67
93
Hi,

Does anyone know how can one trim / discard on thin LVM backed KVM VM?

Due to a bug with live migrate (https://bugzilla.proxmox.com/show_bug.cgi?id=1242) which makes guests use all of it's space within LV, i need to know how to shrink it down. Supposedly that's why we have trim / discard for.

So i loged in to the KVM VM and issued a fstrim /. It failed with: "the discard operation is not supported".

I checked my lvm.conf if it's enabled:
Code:
# cat /etc/lvm/lvm.conf | grep issue_discard
    issue_discards = 1
it is. So I check the VM if it's enabled:
Code:
#cat /etc/pve/qemu-server/102.conf | grep disca
virtio0: local-lvm-sata:vm-102-disk-1,backup=0,cache=writeback,discard=on,size=15G
and it also is.

From the top of my head, i do not know what else to check. Can anyone help me enable fstrim inside my test KVM VM with data on local thin LVM?
 
From the top of my head, i do not know what else to check. Can anyone help me enable fstrim inside my test KVM VM with data on local thin LVM?
You need to switch disk controller from virtio to scsi to be able to pass discard instruction from the client to the disk.
 
Well. I can't seem to pinpoint the problem.
Running proxmox 5-1.46
I do have virtio scsi as controller.
Fresh installation of centos 7

My config:
Code:
bootdisk: scsi0
cores: 6
ide2: local:iso/CentOS-7-x86_64-Minimal-1708.iso,media=cdrom,size=792M
keyboard: sv
lock: backup
memory: 10000
name: mysql57
net0: virtio=B2:23:A2:B6:7B:2F,bridge=vmbr2
net1: virtio=76:49:BC:31:48:8E,bridge=vmbr4
numa: 0
onboot: 1
ostype: l26
scsi0: virt1:vm-103-disk-1,discard=on,size=5G
scsi1: virt1:vm-103-disk-2,discard=on,size=100G
scsihw: virtio-scsi-pci
smbios1: uuid=795328d7-ec2c-4b96-88ea-dde3292c1fab
sockets: 1

My lvm config:
Code:
root@el:~# cat /etc/lvm/lvm.conf  | grep issue_discards
        # Configuration option devices/issue_discards.
        issue_discards = 1

Guest view - under 2GB is used in machine.
Code:
[root@mysql57 ~]# df -h | grep sd
/dev/sda1       4.7G  1.6G  2.9G  35% /
/dev/sdb1        99G  224M   94G   1% /var/lib/mysql

First time it showed that it trimmed all free space and it shows now that everything is trimmed. So everything as expected:
Code:
[root@mysql57 ~]# fstrim  -v / ; fstrim -v /var/lib/mysql
/: 0 B (0 bytes) trimmed
/var/lib/mysql: 0 B (0 bytes) trimmed
And my backup results in ~90G of disk space using gzip:
Code:
INFO: status: 100% (112742891520/112742891520), sparse 7% (8776003584), duration 2970, read/write 33/33 MB/s
INFO: transferred 112742 MB in 2970 seconds (37 MB/s)
INFO: archive file size: 89.42GB
INFO: Finished Backup of VM 103 (00:49:31)
INFO: Backup job finished successfully
TASK OK

This server was upgraded from proxmox 3.1 and lvm was not recreated. Host os was just reinstalled and old configuration files copied over. Could it be a problem with too old lvm format?
 
  • Like
Reactions: Rocha Neto

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!