[linux-lvm] lvremove does not pass discards if volume is part of thin pool

vaLentin chernoZemski valentin at siteground.com
Mon Aug 10 08:56:03 UTC 2015


Hi folks,

I am experiencing issues with LVM thin pool and discards that should be 
passed down during lvremove but they are not.

Setup looks like this:

Sparse file -> Loop device -> PV -> VG -> Thin Pool -> LV

If we mount -o discard LV and fill it with data which is later deleted 
sparse file shrinks back ~ to the original size.

However if we directly lvremove LV, the sparse file does not shrink back 
its size so we are forced to use fallocate (which is slow).

According to the docs lvremove should issue discards to the underlying 
device but it appears that this is not the case if LV is part of thin pool

lsblk -D shows DISC-ZERO as 0 for tpool tmeta and tdata devices and all 
their childs which is strange.

[root at testbed ~]# lsblk -D | grep ^NAME ; lsblk -D | grep -A8 
$group-thingroup_tmeta
NAME                                                       DISC-ALN 
DISC-GRAN DISC-MAX DISC-ZERO
|-testgroup-thingroup_tmeta (dm-33)                               0 
    4K       4G         1
| `-testgroup-thingroup-tpool (dm-35)                             0 
   64K      64K         0
|   |-testgroup-thingroup (dm-36)                                 0 
   64K      64K         0
|   `-testgroup-testvol (dm-37)                                   0 
   64K      64K         0
`-testgroup-thingroup_tdata (dm-34)                               0 
    4K       4G         1
   `-testgroup-thingroup-tpool (dm-35)                             0 
    64K      64K         0
     |-testgroup-thingroup (dm-36)                                 0 
    64K      64K         0
     `-testgroup-testvol (dm-37)                                   0 
    64K      64K         0

Kernel version we are using is 3.12.x.

Linux 3.2 - discard support for loop devices - 
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=dfaa2ef68e80c378e610e3c8c536f1c239e8d3ef

Linux 3.4 - discard support for thin pool - 
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=104655fd4dcebd50068ef30253a001da72e3a081

/etc/lvm/lvm.conf is configured as follows

     issue_discards = 1
     thin_pool_discards = "passdown"

Here is a sample script that demonstrate the issue. Note the output 
after the second lvremove where size of "loop-block-device-file" remains 
unchanged even volume is removed.

set -e
file=/root/testfile
group=testgroup
thingroup=thingroup
volume_name=testvol
volume_size=200M

grep -i disca /etc/lvm/lvm.conf  | grep -v \#
rpm -qa | grep lvm2
uname -r

[[ -f ${file} ]] && unlink ${file}
truncate ${file} --size 10G
loopdev=$(losetup -f --show ${file})
pvcreate --metadatasize 1M ${loopdev}
vgcreate ${group} -s 1MiB ${loopdev}
pe_size=$(vgdisplay "/dev/${group}" | grep 'PE Size' | awk '{print $3}')
thin_size=$(echo "$(vgdisplay "/dev/${group}" | grep 'Free  PE' | awk 
'{print $5}')*${pe_size}-180" | bc -l)
lvcreate --ignoreactivationskip -Z n -L ${thin_size}m -T 
"/dev/${group}/${thingroup}"
lvcreate --ignoreactivationskip -V${volume_size} -T 
"${group}/${thingroup}" -n "${volume_name}"
mkfs.ext4 /dev/$group/$volume_name
sync && du -hs $file
lvs $group
lsblk -D | grep ^NAME ; lsblk -D | grep -A8 $group-thingroup_tmeta
sync && du -hs $file
mkdir -p /mnt/tmp/
mount -o discard /dev/$group/$volume_name /mnt/tmp/
dd if=/dev/zero of=/mnt/tmp/fill_file count=100 bs=1M
sync && du -hs $file
umount /mnt/tmp/
sync && du -hs $file
mount -o discard /dev/$group/$volume_name /mnt/tmp/
rm -f /mnt/tmp/fill_file
sync && du -hs $file
umount /mnt/tmp/
sync && du -hs $file
lvremove -f /dev/$group/$volume_name
lvcreate --ignoreactivationskip -V${volume_size} -T 
"${group}/${thingroup}" -n "${volume_name}"
mkfs.ext4 /dev/$group/$volume_name
lvs $group
lsblk -D | grep ^NAME ; lsblk -D | grep -A8 $group-thingroup_tmeta
sync && du -hs $file
mkdir -p /mnt/tmp/
mount -o discard /dev/$group/$volume_name /mnt/tmp/
dd if=/dev/zero of=/mnt/tmp/fill_file count=100 bs=1M
sync && du -hs $file
umount /mnt/tmp/
sync && du -hs $file
lvremove -f $group/$volume_name
echo "==== AFTER THIS LVREMOVE size should shrink but it does not ==="
sync && du -hs $file
vgchange -Kan $group
sync && du -hs $file
losetup -d $loopdev
sync && du -hs $file
echo "==== FALLOCATE does its job well but that's not the point ===="
fallocate -d $file
sync && du -hs $file

Any assistance will be highly appreciated.

Thanks,

vaLentin




More information about the linux-lvm mailing list