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. Fill the pool to a known percentage of capacity.
33 # 3. Verify the vdevs contain 75% or more allocated blocks.
34 # 4. Remove all files making it possible to trim the entire pool.
35 # 5. Manually trim the pool.
36 # 6. Wait for 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
"Run 'zpool trim' 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" "draid"; do
75 if [[ "$type" = "" ]]; then
77 elif [[ "$type" = "mirror" ]]; then
78 VDEVS
="$TRIM_VDEV1 $TRIM_VDEV2"
79 elif [[ "$type" = "raidz2" ]]; then
80 VDEVS
="$TRIM_VDEV1 $TRIM_VDEV2 $TRIM_VDEV3"
81 elif [[ "$type" = "draid" ]]; then
82 VDEVS
="$TRIM_VDEV1 $TRIM_VDEV2 $TRIM_VDEV3 $TRIM_VDEV4"
84 # The per-vdev utilization is lower due to the capacity
85 # resilverd for the distributed spare.
86 VDEV_MAX_MB
=$
(( floor
(4 * MINVDEVSIZE
* 0.50 / 1024 / 1024) ))
89 log_must truncate
-s $
((4 * MINVDEVSIZE
)) $VDEVS
90 log_must zpool create
-f $TESTPOOL $type $VDEVS
92 typeset availspace
=$
(get_prop available
$TESTPOOL)
93 typeset fill_mb
=$
(( floor
(availspace
* 0.90 / 1024 / 1024) ))
95 # Fill the pool, verify the vdevs are no longer sparse.
96 file_write
-o create
-f /$TESTPOOL/file -b 1048576 -c $fill_mb -d R
97 verify_vdevs
"-ge" "$VDEV_MAX_MB" $VDEVS
99 # Remove the file, issue trim, verify the vdevs are now sparse.
100 log_must
rm /$TESTPOOL/file
101 log_must timeout
120 zpool trim
-w $TESTPOOL
102 verify_vdevs
"-le" "$VDEV_MIN_MB" $VDEVS
104 log_must zpool destroy
$TESTPOOL
105 log_must
rm -f $VDEVS
108 log_pass
"Manual trim successfully shrunk vdevs"