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.
17 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/tests/functional/trim/trim.kshlib
19 . $STF_SUITE/tests/functional/trim/trim.cfg
23 # Verify trimming of L2ARC
26 # 1. Set 'l2arc_trim_ahead = 1' and `l2arc_write_size = 64MB`.
27 # 2. Create a pool on file vdevs to trim.
28 # 3. Verify the cache device was trimmed.
29 # 4. Fill the pool with a file larger than the L2ARC vdev.
30 # 5. Randomly read the previous written file long enough for the
31 # L2ARC vdev to be filled and overwritten 5 times.
32 # 6. Verify trim IOs of the expected type were issued for the pool.
33 # 7. Verify the allocated space on the cache device is less than
37 verify_runnable "global"
39 log_assert "Trim of L2ARC succeeds."
43 if poolexists $TESTPOOL; then
44 destroy_pool $TESTPOOL
48 log_must set_tunable32 L2ARC_TRIM_AHEAD $l2arc_trimahead
49 log_must set_tunable32 L2ARC_WRITE_MAX $l2arc_writemax
53 # The cache device $TRIM_VDEV2 has to be small enough, so that
54 # dev->l2ad_hand loops around and dev->l2ad_first=0. Otherwise
55 # l2arc_evict() exits before evicting/trimming.
56 typeset l2arc_trimahead=$(get_tunable L2ARC_TRIM_AHEAD)
57 typeset l2arc_writemax=$(get_tunable L2ARC_WRITE_MAX)
58 log_must set_tunable32 L2ARC_TRIM_AHEAD 1
59 log_must set_tunable32 L2ARC_WRITE_MAX $((64 * 1024 * 1024))
60 VDEVS="$TRIM_VDEV1 $TRIM_VDEV2"
61 log_must truncate -s $((MINVDEVSIZE)) $TRIM_VDEV2
62 log_must truncate -s $((4 * MINVDEVSIZE)) $TRIM_VDEV1
63 typeset VDEV_MIN_MB=$((MINVDEVSIZE * 0.30 / 1024 / 1024))
65 log_must zpool create -f $TESTPOOL $TRIM_VDEV1 cache $TRIM_VDEV2
66 verify_vdevs "-le" "$VDEV_MIN_MB" $TRIM_VDEV2
68 typeset fill_mb=$(( floor(2 * MINVDEVSIZE) ))
69 export DIRECTORY=/$TESTPOOL
71 export FILE_SIZE=${fill_mb}
72 export PERF_RANDSEED=1234
73 export PERF_COMPPERCENT=66
74 export PERF_COMPCHUNK=0
81 log_must fio $FIO_SCRIPTS/mkfiles.fio
83 # Read randomly from the pool to fill L2ARC.
85 log_must fio $FIO_SCRIPTS/random_reads.fio
89 while $do_once || [[ $l2_size1 -le $l2_size2 ]]; do
90 typeset l2_size1=$(get_arcstat l2_size)
91 log_must fio $FIO_SCRIPTS/random_reads.fio
92 typeset l2_size2=$(get_arcstat l2_size)
96 verify_trim_io $TESTPOOL "ind" 5 $TRIM_VDEV2
98 typeset cache_size=$(zpool list -vp | grep $TRIM_VDEV2 | awk '{print $2}')
99 typeset cache_alloc=$(zpool list -vp | grep $TRIM_VDEV2 | awk '{print $3}')
101 log_must test $cache_alloc -lt $cache_size
103 log_must zpool destroy $TESTPOOL
104 log_must rm -f $VDEVS
106 log_pass "Trim of L2ARC succeeds."