2

In Proxmox we use LVM to create discs (logical volumes) for our VMs (LVM thin provisioning).

Recently we found out our volume group is almost full even when all VM discs are almost empty.

Problem is that some LVM partitions show much bigger mapped size that real size of data stored on VM disk as reported by df.

For example we have VM with 100 GB logical volume. Disc usage inside VM shows only 3.2 GB of space is used:

#> df
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/pve-vm--3011--disk--1   99G  3.2G   91G   4% /
...

but logical volume on host shows it use 39.8 GB:

  #> lvdisplay
  --- Logical volume ---
  LV Path                /dev/pve/vm-3011-disk-1
  LV Name                vm-3011-disk-1
  VG Name                pve
  LV UUID                oleKd5-O2o4-c4CE-5vzn-bXRC-TXwF-lzApmW
  LV Write Access        read/write
  LV Creation host, time carol, 2016-08-16 09:03:54 +0200
  LV Pool name           vm-hdd
  LV Status              available
  # open                 1
  LV Size                100.00 GiB
  Mapped size            39.83%
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:28
  ...

So in fact more than ten times more space is used than really needed.

Any idea what is the reason? I suspects that LVM keeps allocated all extents ever touched by filesystem in VM. Is there any way to prevent this or to claim unused space back?

1 Answers1

5

Figured it out. You have to use fstrim.

I was able to reclaim unused space by running this inside VM:

    fstrim -v /

Based on solution described in section Using fstrim to increase free space in a thin pool LV here: http://man7.org/linux/man-pages/man7/lvmthin.7.html

  • You do not need to zero-fill the volume. Simply issue `fstrim` – shodanshok Jul 29 '17 at 19:52
  • You are right. I fixed my answer. – Martin Mystik Jonáš Jul 29 '17 at 20:05
  • Something of note, LVM does not pass discards by default in most distributions. This essentially means that anything underneath the LVM won't be sparsified when you run the fstrim command, which would be frustrating on thinly provisioned VM images or thinly provisioned SANs (they simply won't be changed). In /etc/lvm/lvm.conf, look at the following line: "issue_discards = 0". Change that 0 to 1 in order to enable this functionality. And of course if you want 0, keep 0. – Spooler Jul 31 '17 at 07:35
  • But this solution does not work for me in proxmox 5.1, the means, `fstrim` works well, But the unused space is not back. – Nabi K.A.Z. Jul 07 '18 at 12:56
  • Sorry, It's work if use SCSI disk with `discard=on` flag. But it was very good if he could do it from inside the host. – Nabi K.A.Z. Jul 07 '18 at 13:47