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
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.
18 # Copyright (c) 2019 by Tim Chase. All rights reserved.
19 # Copyright (c) 2019 Lawrence Livermore National Security, LLC.
22 . $STF_SUITE/include/libtest.shlib
23 . $STF_SUITE/tests/functional/trim/trim.kshlib
24 . $STF_SUITE/tests/functional/trim/trim.cfg
28 # Check various pool geometries stripe, mirror, raidz)
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.
40 verify_runnable "global"
42 log_assert "Set 'autotrim=on' verify pool disks were trimmed"
46 if poolexists $TESTPOOL; then
47 destroy_pool $TESTPOOL
50 log_must rm -f $TRIM_VDEVS
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
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
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
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
70 typeset VDEV_MAX_MB=$(( floor(4 * MINVDEVSIZE * 0.75 / 1024 / 1024) ))
71 typeset VDEV_MIN_MB=$(( floor(4 * MINVDEVSIZE * 0.30 / 1024 / 1024) ))
73 for type in "" "mirror" "raidz2"; do
75 if [[ "$type" = "" ]]; then
77 elif [[ "$type" = "mirror" ]]; then
78 VDEVS="$TRIM_VDEV1 $TRIM_VDEV2"
80 VDEVS="$TRIM_VDEV1 $TRIM_VDEV2 $TRIM_VDEV3"
83 log_must truncate -s $((4 * MINVDEVSIZE)) $VDEVS
84 log_must zpool create -f $TESTPOOL $VDEVS
85 log_must zpool set autotrim=on $TESTPOOL
87 typeset availspace=$(get_prop available $TESTPOOL)
88 typeset fill_mb=$(( floor(availspace * 0.90 / 1024 / 1024) ))
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
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
99 log_must zpool destroy $TESTPOOL
100 log_must rm -f $VDEVS
103 log_pass "Auto trim successfully shrunk vdevs"