]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cache/cache_012_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cache / cache_012_pos.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 #
18 # Copyright (c) 2020, George Amanakis. All rights reserved.
19 #
20
21 . $STF_SUITE/tests/functional/cache/cache.cfg
22 . $STF_SUITE/tests/functional/cache/cache.kshlib
23
24 #
25 # DESCRIPTION:
26 #       Looping around a cache device with l2arc_write_size exceeding
27 #       the device size succeeds.
28 #
29 # STRATEGY:
30 #       1. Create pool with a cache device.
31 #       2. Set l2arc_write_max to a value larger than the cache device.
32 #       3. Create a file larger than the cache device and random read
33 #               for 10 sec.
34 #       4. Verify that l2arc_write_max is set back to the default.
35 #       5. Set l2arc_write_max to a value less than the cache device size but
36 #               larger than the default (64MB).
37 #       6. Record the l2_size.
38 #       7. Random read for 1 sec.
39 #       8. Record the l2_size again.
40 #       9. If (6) <= (8) then we have not looped around yet.
41 #       10. If (6) > (8) then we looped around. Break out of the loop and test.
42 #       11. Destroy pool.
43 #
44
45 verify_runnable "global"
46
47 log_assert "Looping around a cache device succeeds."
48
49 function cleanup
50 {
51         if poolexists $TESTPOOL ; then
52                 destroy_pool $TESTPOOL
53         fi
54
55         log_must set_tunable32 L2ARC_WRITE_MAX $write_max
56         log_must set_tunable32 L2ARC_NOPREFETCH $noprefetch
57 }
58 log_onexit cleanup
59
60 typeset write_max=$(get_tunable L2ARC_WRITE_MAX)
61 typeset noprefetch=$(get_tunable L2ARC_NOPREFETCH)
62 log_must set_tunable32 L2ARC_NOPREFETCH 0
63
64 typeset VDEV="$VDIR/vdev.disk"
65 typeset VDEV_SZ=$(( 4 * 1024 * 1024 * 1024 ))
66 typeset VCACHE="$VDIR/vdev.cache"
67 typeset VCACHE_SZ=$(( $VDEV_SZ / 2 ))
68
69 typeset fill_mb=$(( floor($VDEV_SZ * 3 / 4 ) ))
70 export DIRECTORY=/$TESTPOOL
71 export NUMJOBS=4
72 export RUNTIME=10
73 export PERF_RANDSEED=1234
74 export PERF_COMPPERCENT=66
75 export PERF_COMPCHUNK=0
76 export BLOCKSIZE=128K
77 export SYNC_TYPE=0
78 export DIRECT=1
79 export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))
80
81 log_must set_tunable32 L2ARC_WRITE_MAX $(( $VCACHE_SZ * 2 ))
82
83 log_must truncate -s $VCACHE_SZ $VCACHE
84 log_must truncate -s $VDEV_SZ $VDEV
85
86 log_must zpool create -f $TESTPOOL $VDEV cache $VCACHE
87
88 log_must fio $FIO_SCRIPTS/mkfiles.fio
89 log_must fio $FIO_SCRIPTS/random_reads.fio
90
91 typeset write_max2=$(get_tunable L2ARC_WRITE_MAX)
92
93 log_must test $write_max2 -eq $write_max
94
95 log_must set_tunable32 L2ARC_WRITE_MAX $(( 64 * 1024 * 1024 ))
96 export RUNTIME=1
97
98 typeset do_once=true
99 while $do_once || [[ $l2_size1 -le $l2_size2 ]]; do
100         typeset l2_size1=$(get_arcstat l2_size)
101         log_must fio $FIO_SCRIPTS/random_reads.fio
102         typeset l2_size2=$(get_arcstat l2_size)
103         do_once=false
104 done
105
106 log_must test $l2_size1 -gt $l2_size2
107
108 log_must zpool destroy $TESTPOOL
109
110 log_pass "Looping around a cache device succeeds."