Project

General

Profile

Actions

Feature #15616

closed

Add DISCARD/TRIM support to lofi(4D)

Added by Andy Fiddaman about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
driver - device drivers
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

lofi devices, labelled or otherwise, are often used to underpin zfs pools for such things as constructing distribution images.They are also sometimes used as a means of adding a layer of encryption to an existing device.

It would be convenient to be able to trim these pools and have that cascade down to the underlying file or device.

Actions #1

Updated by Electric Monk about 1 year ago

  • Gerrit CR set to 2824
Actions #2

Updated by Andy Fiddaman about 1 year ago

Testing notes

First, checking the basic functionality of DKIOC_HASFREE:

bloody# zfs create -sV 50G rpool/test
bloody# mkfile 10G /lofitest
bloody# lofiadm -a /lofitest
/dev/lofi/1
bloody# lofiadm -a /dev/zvol/rdsk/rpool/test
/dev/lofi/2

bloody# /opt/zfs-tests/bin/has_unmap /dev/lofi/1
ioctl failed /dev/lofi/1: Inappropriate ioctl for device
bloody# /opt/zfs-tests/bin/has_unmap /dev/lofi/2
ioctl failed /dev/lofi/2: Inappropriate ioctl for device

bloody# /opt/zfs-tests/bin/has_unmap /dev/rlofi/1
bloody# /opt/zfs-tests/bin/has_unmap /dev/rlofi/2

bloody# lofiadm -d /dev/lofi/1
bloody# lofiadm -d /dev/lofi/2

bloody# lofiadm -l -a /lofitest
/dev/dsk/c1t1d0p0
bloody# lofiadm -l -a /dev/zvol/rdsk/rpool/test
/dev/dsk/c1t2d0p0
bloody# /opt/zfs-tests/bin/has_unmap /dev/rdsk/c1t1d0p0
bloody# /opt/zfs-tests/bin/has_unmap /dev/rdsk/c1t2d0p0

Test unlabelled device trim with backing file:

bloody# mkfile 10G /lofitest
bloody# lofiadm -a /lofitest
/dev/lofi/1
bloody# zpool create test /dev/lofi/1
bloody# zfs list -o space test
NAME  AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
test  9.20G   102K         0     24K              0        78K
bloody# du -hs /lofitest
320K    /lofitest
bloody# rsync -a /build/arm64-gate/illumos-gate /test/illumos-gate/
bloody# zfs list -o space test
NAME  AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
test  5.66G  3.55G         0   3.55G              0       588K
bloody# du -hs /lofitest
1.74G   /lofitest

bloody# rm -rf /test/illumos-gate

bloody# zfs list -o space test
NAME  AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
test  9.20G   868K         0     24K              0       844K
bloody# du -hs /lofitest
1.74G   /lofitest

bloody# zpool trim test
bloody# zpool status -t test
 NAME           STATE     READ WRITE CKSUM
 test           ONLINE       0     0     0
   /dev/lofi/1  ONLINE       0     0     0  (31% trimmed, started at Wed May  3 11:17:40 2023)

bloody# du -hs /lofitest
34.2M   /lofitest

bloody# zpool scrub test
bloody# zpool status test | grep scan:
  scan: scrub repaired 0 in 0 days 00:00:00 with 0 errors on Wed May  3 11:18:13 2023

Repeating with a labelled lofi device, and creating the ZFS pool with an EFI system partition so that the pool is on GPT partition 1, which exercises the cmlb paths.

bloody# lofiadm -l -a /lofitest
/dev/dsk/c1t1d0p0
bloody# zpool create -B test /dev/dsk/c1t1d0
bloody# prtvtoc -s /dev/dsk/c1t1d0
*                            First       Sector      Last
* Partition  Tag  Flags      Sector       Count      Sector  Mount Directory
       0     12    00          256      524288      524543
       1      4    00       524544    20430559    20955102
       8     11    00     20955103       16384    20971486

bloody# rsync -a /build/arm64-gate/illumos-gate /test/illumos-gate/

bloody# zfs list -o space test
NAME  AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
test  5.66G  3.55G         0   3.55G              0       210K
bloody# du -hs /lofitest
1.76G   /lofitest

bloody# rm -rf /test/illumos-gate

bloody# du -hs /lofitest
1.77G   /lofitest
bloody# zpool trim test
bloody# du -hs /lofitest
31.5M   /lofitest

bloody# zpool scrub test
bloody# zpool status test | grep scan:
  scan: scrub repaired 0 in 0 days 00:00:00 with 0 errors on Wed May  3 11:24:28 2023

Using a lofi device atop a sparse ZVOL

bloody# zfs create -sV 50G rpool/test
bloody# lofiadm -a /dev/zvol/rdsk/rpool/test
/dev/lofi/1
bloody# zpool create test /dev/lofi/1

bloody# rsync -a /build/arm64-gate/illumos-gate /test/illumos-gate/
bloody# rm -rf /test/illumos-gate

bloody# zfs list -o space test rpool/test
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
rpool/test  87.5G  3.30G         0   3.30G              0          0
test        48.0G   345K         0     24K              0       321K

bloody# zpool trim test

bloody# zfs list -o space test rpool/test
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
rpool/test  90.7G  72.1M         0   72.1M              0          0
test        47.9G  14.3M         0     24K              0      14.3M

and again, labelled:

bloody# lofiadm -l -a /dev/zvol/rdsk/rpool/test
/dev/dsk/c1t1d0p0
bloody# zpool create -B test c1t1d0

bloody# rsync -a /build/arm64-gate/illumos-gate /test/illumos-gate/
bloody# rm -rf /test/illumos-gate

bloody# zfs list -o space test rpool/test
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
rpool/test  87.4G  3.37G         0   3.37G              0          0
test        48.0G   246K         0     24K              0       222K

bloody# zpool trim test

bloody# zfs list -o space test rpool/test
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
rpool/test  90.7G  81.2M         0   81.2M              0          0
test        47.9G  9.45M         0     24K              0      9.43M

bloody# zpool scrub test
bloody# zpool status test | grep scan:
  scan: scrub repaired 0 in 0 days 00:00:00 with 0 errors on Wed May  3 11:32:37 2023
Actions #3

Updated by Electric Monk about 1 year ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

git commit 03f27e8ba0f85d042c7cd047c94bcdf971b1c2cd

commit  03f27e8ba0f85d042c7cd047c94bcdf971b1c2cd
Author: Andy Fiddaman <illumos@fiddaman.net>
Date:   2023-05-10T09:42:43.000Z

    15616 Add DISCARD/TRIM support to lofi(4D)
    Reviewed by: Jason King <jason.brian.king+illumos@gmail.com>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Approved by: Dan McDonald <danmcd@mnx.io>

Actions

Also available in: Atom PDF