Skip to content

Commit

Permalink
Add TRIM tests to the test suite
Browse files Browse the repository at this point in the history
Test autotrim and manual trim for each vdev type.  Testing autotrim in
a reasonable amount of time requires lowering zfs_trim_min_ext_sz and
forcing transaction groups.
  • Loading branch information
dweeezil committed Apr 9, 2017
1 parent 46177f3 commit 03f6f65
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/sparse/Makefile
tests/zfs-tests/tests/functional/threadsappend/Makefile
tests/zfs-tests/tests/functional/tmpfile/Makefile
tests/zfs-tests/tests/functional/trim/Makefile
tests/zfs-tests/tests/functional/truncate/Makefile
tests/zfs-tests/tests/functional/userquota/Makefile
tests/zfs-tests/tests/functional/upgrade/Makefile
Expand Down
3 changes: 3 additions & 0 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ tests = ['sparse_001_pos']
[tests/functional/tmpfile]
tests = ['tmpfile_001_pos', 'tmpfile_002_pos', 'tmpfile_003_pos']

[tests/functional/trim]
tests = ['autotrim_001_pos', 'manualtrim_001_pos']

[tests/functional/truncate]
tests = ['truncate_001_pos', 'truncate_002_pos']

Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SUBDIRS = \
sparse \
threadsappend \
tmpfile \
trim \
truncate \
upgrade \
userquota \
Expand Down
8 changes: 8 additions & 0 deletions tests/zfs-tests/tests/functional/trim/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/trim
dist_pkgdata_SCRIPTS = \
setup.ksh \
trim.cfg \
trim.kshlib \
cleanup.ksh \
autotrim_001_pos.ksh \
manualtrim_001_pos.ksh
114 changes: 114 additions & 0 deletions tests/zfs-tests/tests/functional/trim/autotrim_001_pos.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/trim/trim.cfg
. $STF_SUITE/tests/functional/trim/trim.kshlib

set_tunable zfs_trim_min_ext_sz 4096
set_tunable zfs_txgs_per_trim 2

function getsizemb
{
typeset rval

rval=$(du --block-size 1048576 -s "$1" | sed -e 's;[ ].*;;')
echo -n "$rval"
}

function checkvdevs
{
typeset vd sz

for vd in $VDEVS; do
sz=$(getsizemb $vd)
log_note Size of $vd is $sz MB
log_must test $sz -le $SHRUNK_SIZE_MB
done
}

function txgs
{
typeset x

# Run some txgs in order to let autotrim do its work.
#
for x in 1 2 3; do
log_must zfs snapshot $TRIMPOOL@snap
log_must zfs destroy $TRIMPOOL@snap
log_must zfs snapshot $TRIMPOOL@snap
log_must zfs destroy $TRIMPOOL@snap
done
}

#
# Check various pool geometries: Create the pool, fill it, remove the test file,
# run some txgs, export the pool and verify that the vdevs shrunk.
#

#
# raidz
#
for z in 1 2 3; do
setupvdevs
log_must zpool create -f $TRIMPOOL raidz$z $VDEVS
log_must zpool set autotrim=on $TRIMPOOL
log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w
log_must rm "/$TRIMPOOL/$TESTFILE"
txgs
log_must zpool export $TRIMPOOL
checkvdevs
done

#
# mirror
#
setupvdevs
log_must zpool create -f $TRIMPOOL mirror $MIRROR_VDEVS_1 mirror $MIRROR_VDEVS_2
log_must zpool set autotrim=on $TRIMPOOL
log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w
log_must rm "/$TRIMPOOL/$TESTFILE"
txgs
log_must zpool export $TRIMPOOL
checkvdevs

#
# stripe
#
setupvdevs
log_must zpool create -f $TRIMPOOL $STRIPE_VDEVS
log_must zpool set autotrim=on $TRIMPOOL
log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w
log_must rm "/$TRIMPOOL/$TESTFILE"
txgs
log_must zpool export $TRIMPOOL
checkvdevs

log_pass TRIM successfully shrunk vdevs
31 changes: 31 additions & 0 deletions tests/zfs-tests/tests/functional/trim/cleanup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/trim/trim.cfg

rm -f $VDEVS
100 changes: 100 additions & 0 deletions tests/zfs-tests/tests/functional/trim/manualtrim_001_pos.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2013, 2014 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/trim/trim.cfg
. $STF_SUITE/tests/functional/trim/trim.kshlib

set_tunable zfs_trim_min_ext_sz 4096

function getsizemb
{
typeset rval

rval=$(du --block-size 1048576 -s "$1" | sed -e 's;[ ].*;;')
echo -n "$rval"
}

function checkvdevs
{
typeset vd sz

for vd in $VDEVS; do
sz=$(getsizemb $vd)
log_note Size of $vd is $sz MB
log_must test $sz -le $SHRUNK_SIZE_MB
done
}

function dotrim
{
log_must rm "/$TRIMPOOL/$TESTFILE"
log_must zpool export $TRIMPOOL
log_must zpool import -d $VDEVDIR $TRIMPOOL
log_must zpool trim $TRIMPOOL
sleep 5
log_must zpool export $TRIMPOOL
}

#
# Check various pool geometries: Create the pool, fill it, remove the test file,
# perform a manual trim, export the pool and verify that the vdevs shrunk.
#

#
# raidz
#
for z in 1 2 3; do
setupvdevs
log_must zpool create -f $TRIMPOOL raidz$z $VDEVS
log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w
dotrim
checkvdevs
done

#
# mirror
#
setupvdevs
log_must zpool create -f $TRIMPOOL mirror $MIRROR_VDEVS_1 mirror $MIRROR_VDEVS_2
log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w
dotrim
checkvdevs

#
# stripe
#
setupvdevs
log_must zpool create -f $TRIMPOOL $STRIPE_VDEVS
log_must file_write -o create -f "/$TRIMPOOL/$TESTFILE" -b $BLOCKSIZE -c $NUM_WRITES -d R -w
dotrim
checkvdevs

log_pass Manual TRIM successfully shrunk vdevs
36 changes: 36 additions & 0 deletions tests/zfs-tests/tests/functional/trim/setup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

#
# Copyright (c) 2013 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/trim/trim.cfg
. $STF_SUITE/tests/functional/trim/trim.kshlib

log_pass TRIM setup succeeded
60 changes: 60 additions & 0 deletions tests/zfs-tests/tests/functional/trim/trim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

#
# Copyright (c) 2013 by Delphix. All rights reserved.
#

#
# Parameters
#
TRIMPOOL=trimpool
VDEVDIR="/tmp"
VDEVS="/tmp/trim1.dev /tmp/trim2.dev /tmp/trim3.dev /tmp/trim4.dev /tmp/trim5.dev"
VDEV_SIZE=128m
TESTFILE=testfile
SHRUNK_SIZE_MB=12

NUM_WRITES=2048
BLOCKSIZE=65536

#
# Computed values and parameters
#
function get_mirror_vdevs
{
set -- $VDEVS
MIRROR_VDEVS_1="$1 $2"
MIRROR_VDEVS_2="$3 $4"
}
get_mirror_vdevs

function get_stripe_vdevs
{
set -- $VDEVS
STRIPE_VDEVS="$1 $2 $3 $4"
}
get_stripe_vdevs
Loading

0 comments on commit 03f6f65

Please sign in to comment.