]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/trim/autotrim_config.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / trim / autotrim_config.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
9 #
10 # A full copy of the text of the CDDL should have accompanied this
11 # source.  A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16
17 #
18 # Copyright (c) 2019 by Tim Chase. All rights reserved.
19 # Copyright (c) 2019 Lawrence Livermore National Security, LLC.
20 #
21
22 . $STF_SUITE/include/libtest.shlib
23 . $STF_SUITE/tests/functional/trim/trim.kshlib
24 . $STF_SUITE/tests/functional/trim/trim.cfg
25
26 #
27 # DESCRIPTION:
28 #       Check various pool geometries stripe, mirror, raidz)
29 #
30 # STRATEGY:
31 #       1. Create a pool on file vdevs to trim.
32 #       2. Set 'autotrim=on' on pool.
33 #       3. Fill the pool to a known percentage of capacity.
34 #       4. Verify the vdevs contain 75% or more allocated blocks.
35 #       5. Remove all files making it possible to trim the entire pool.
36 #       6. Wait for auto trim to issue trim IOs for the free blocks.
37 #       7. Verify the disks contain 30% or less allocated blocks.
38 #       8. Repeat for test for striped, mirrored, and RAIDZ pools.
39
40 verify_runnable "global"
41
42 log_assert "Set 'autotrim=on' verify pool disks were trimmed"
43
44 function cleanup
45 {
46         if poolexists $TESTPOOL; then
47                 destroy_pool $TESTPOOL
48         fi
49
50         log_must rm -f $TRIM_VDEVS
51
52         log_must set_tunable64 TRIM_EXTENT_BYTES_MIN $trim_extent_bytes_min
53         log_must set_tunable64 TRIM_TXG_BATCH $trim_txg_batch
54         log_must set_tunable64 VDEV_MIN_MS_COUNT $vdev_min_ms_count
55 }
56 log_onexit cleanup
57
58 # Minimum trim size is decreased to verify all trim sizes.
59 typeset trim_extent_bytes_min=$(get_tunable TRIM_EXTENT_BYTES_MIN)
60 log_must set_tunable64 TRIM_EXTENT_BYTES_MIN 4096
61
62 # Reduced TRIM_TXG_BATCH to make trimming more frequent.
63 typeset trim_txg_batch=$(get_tunable TRIM_TXG_BATCH)
64 log_must set_tunable64 TRIM_TXG_BATCH 8
65
66 # Increased metaslabs to better simulate larger more realistic devices.
67 typeset vdev_min_ms_count=$(get_tunable VDEV_MIN_MS_COUNT)
68 log_must set_tunable64 VDEV_MIN_MS_COUNT 32
69
70 typeset VDEV_MAX_MB=$(( floor(4 * MINVDEVSIZE * 0.75 / 1024 / 1024) ))
71 typeset VDEV_MIN_MB=$(( floor(4 * MINVDEVSIZE * 0.30 / 1024 / 1024) ))
72
73 for type in "" "mirror" "raidz2"; do
74
75         if [[ "$type" = "" ]]; then
76                 VDEVS="$TRIM_VDEV1"
77         elif [[ "$type" = "mirror" ]]; then
78                 VDEVS="$TRIM_VDEV1 $TRIM_VDEV2"
79         else
80                 VDEVS="$TRIM_VDEV1 $TRIM_VDEV2 $TRIM_VDEV3"
81         fi
82
83         log_must truncate -s $((4 * MINVDEVSIZE)) $VDEVS
84         log_must zpool create -f $TESTPOOL $VDEVS
85         log_must zpool set autotrim=on $TESTPOOL
86
87         typeset availspace=$(get_prop available $TESTPOOL)
88         typeset fill_mb=$(( floor(availspace * 0.90 / 1024 / 1024) ))
89
90         # Fill the pool, verify the vdevs are no longer sparse.
91         file_write -o create -f /$TESTPOOL/file -b 1048576 -c $fill_mb -d R
92         verify_vdevs "-ge" "$VDEV_MAX_MB" $VDEVS
93
94         # Remove the file, wait for trim, verify the vdevs are now sparse.
95         log_must rm /$TESTPOOL/file
96         wait_trim_io $TESTPOOL "ind" 64
97         verify_vdevs "-le" "$VDEV_MIN_MB" $VDEVS
98
99         log_must zpool destroy $TESTPOOL
100         log_must rm -f $VDEVS
101 done
102
103 log_pass "Auto trim successfully shrunk vdevs"