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