Solved Does fstrim work on linux with bhyve?

bokutin

New Member


Messages: 5

# fstrim /home
fstrim: /home: the discard operation is not supported


This is the case if it doesn't work.

I tried all of the below but it didn't work.

bhyve emu: virtio-blk virtio-scsi ahci ahci-hd nvme
os: centos7
linux lvm: lvm or no lvm
linux fs: ext4

I'm glad if fstrim works, I can reduce zfs REFER.

zefofree is not a use case as it does not work during rw mount.
 

sebhtml

New Member

Reaction score: 2
Messages: 8

I am running BHYVE on a FreeBSD 12.1-RELEASE host.
My guest is running Debian 10.3.

Guest configuration:

Code:
root@atlantis:~ # grep disk0 /tank/vm-bhyve/capside/capside.conf
disk0_type="ahci-hd"
disk0_name="disk0"
disk0_dev="zvol"

Corresponding ZVOL:

Code:
root@atlantis:~ # zfs list tank/vm-bhyve/capside/disk0
NAME                          USED  AVAIL  REFER  MOUNTPOINT
tank/vm-bhyve/capside/disk0   132G  5.17T  4.13G  -
Inside the guest:

Code:
root@capside:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   128G  0 disk
├─sda1   8:1    0 127.5G  0 part /
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0   510M  0 part [SWAP]
sdb      8:16   0    20G  0 disk
Code:
root@capside:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       125G  1.1G  118G   1% /
Let's create a 1GB file.

Code:
root@capside:~# dd if=/dev/zero of=big bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 3.09703 s, 347 MB/s

Used changed from 1.1G to 2.1G.

Code:
root@capside:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       125G  2.1G  117G   2% /


Now in the hypervisor, the REFER value has increased from 4.13G to 5.13G.

Code:
root@atlantis:~ # zfs list tank/vm-bhyve/capside/disk0
NAME                          USED  AVAIL  REFER  MOUNTPOINT
tank/vm-bhyve/capside/disk0   132G  5.17T  5.13G  -

If we remove the big 1GB file, the BHYVE guest will release the capacity.

Code:
root@capside:~# rm big
Code:
root@capside:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       125G  1.1G  118G   1% /
Code:
root@capside:~# /sbin/fstrim /

Now the REFER value has decreased from 5.13G to 4.13G, like we wanted:

Code:
root@atlantis:~ # zfs list tank/vm-bhyve/capside/disk0
NAME                          USED  AVAIL  REFER  MOUNTPOINT
tank/vm-bhyve/capside/disk0   132G  5.17T  4.13G  -
 
OP
bokutin

bokutin

New Member


Messages: 5

Thanks for the very detailed response!

It was very helpful.

For some reason, I need to run it on CentOS7 and it worked.

man vm
Code:
-t type         For disk devices, this specifies the type of
                    disk device to create.  Valid options for this
                    are zvol, sparse-zvol and file.  If not
                    specified, this defaults to file.


I needed to set the type to zvol or sparse-zvol.

Here are the cases where fstrim doesn't work and when it does.
In both cases, the default for CentOS-7-x86_64-Minimal-2003.iso Installation.

fstrim did not work
Code:
    # vm.conf
    disk0_type="ahci-hd"
    disk0_name="disk0.img"
    # vm-bhyve.log 
    Jun 16 10:35:57: [bhyve devices: -s 0,hostbridge -s 31,lpc -s 4:0,ahci-hd,/vm2/centos7_img/disk0.img -s 5:0,virtio-net,tap5,mac=58:9c:fc:08:a9:7e -s 6:0,fbuf,tcp=0.0.0.0:5901 -s 7:0,xhci,tablet]
fstrim worked
Code:
    # vm.conf
    disk0_type="ahci-hd"
    disk0_dev="sparse-zvol"
    disk0_name="disk0"
    # vm-bhyve.log 
    Jun 16 10:27:21:  [bhyve devices: -s 0,hostbridge -s 31,lpc -s 4:0,ahci-hd,/dev/zvol/zroot4/vm/centos7_lvm/disk0 -s 5:0,virtio-net,tap6,mac=58:9c:fc:07:06:2e -s 6:0,fbuf,tcp=0.0.0.0:5902 -s 7:0,xhci,tablet]
We were able to solve the problem. Thank you!
 
Top