]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/trim/trim_l2arc.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / trim / trim_l2arc.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
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
8 # 1.0 of the CDDL.
9 #
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.
13 #
14 # CDDL HEADER END
15 #
16
17 . $STF_SUITE/include/libtest.shlib
18 . $STF_SUITE/tests/functional/trim/trim.kshlib
19 . $STF_SUITE/tests/functional/trim/trim.cfg
20
21 #
22 # DESCRIPTION:
23 #       Verify trimming of L2ARC
24 #
25 # STRATEGY:
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
34 #               its size.
35 #
36
37 verify_runnable "global"
38
39 log_assert "Trim of L2ARC succeeds."
40
41 function cleanup
42 {
43         if poolexists $TESTPOOL; then
44                 destroy_pool $TESTPOOL
45         fi
46
47         log_must rm -f $VDEVS
48         log_must set_tunable32 L2ARC_TRIM_AHEAD $l2arc_trimahead
49         log_must set_tunable32 L2ARC_WRITE_MAX $l2arc_writemax
50 }
51 log_onexit cleanup
52
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))
64
65 log_must zpool create -f $TESTPOOL $TRIM_VDEV1 cache $TRIM_VDEV2
66 verify_vdevs "-le" "$VDEV_MIN_MB" $TRIM_VDEV2
67
68 typeset fill_mb=$(( floor(2 * MINVDEVSIZE) ))
69 export DIRECTORY=/$TESTPOOL
70 export NUMJOBS=1
71 export FILE_SIZE=${fill_mb}
72 export PERF_RANDSEED=1234
73 export PERF_COMPPERCENT=66
74 export PERF_COMPCHUNK=0
75 export RUNTIME=30
76 export BLOCKSIZE=128K
77 export SYNC_TYPE=0
78 export DIRECT=1
79
80 # Write to the pool.
81 log_must fio $FIO_SCRIPTS/mkfiles.fio
82
83 # Read randomly from the pool to fill L2ARC.
84 export RUNTIME=30
85 log_must fio $FIO_SCRIPTS/random_reads.fio
86
87 export RUNTIME=1
88 typeset do_once=true
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)
93         do_once=false
94 done
95
96 verify_trim_io $TESTPOOL "ind" 5 $TRIM_VDEV2
97
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}')
100
101 log_must test $cache_alloc -lt $cache_size
102
103 log_must zpool destroy $TESTPOOL
104 log_must rm -f $VDEVS
105
106 log_pass "Trim of L2ARC succeeds."