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. Set l2arc_write_max to a value less than the cache device size but
35#		larger than the default (256MB).
36#	5. Record the l2_size.
37#	6. Random read for 1 sec.
38#	7. Record the l2_size again.
39#	8. If (5) <= (7) then we have not looped around yet.
40#	9. Destroy pool.
41#
42
43verify_runnable "global"
44
45command -v fio > /dev/null || log_unsupported "fio missing"
46
47log_assert "Looping around a cache device succeeds."
48
49function 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}
58log_onexit cleanup
59
60typeset write_max=$(get_tunable L2ARC_WRITE_MAX)
61typeset noprefetch=$(get_tunable L2ARC_NOPREFETCH)
62log_must set_tunable32 L2ARC_NOPREFETCH 0
63
64typeset VDEV="$VDIR/vdev.disk"
65typeset VDEV_SZ=$(( 4 * 1024 * 1024 * 1024 ))
66typeset VCACHE="$VDIR/vdev.cache"
67typeset VCACHE_SZ=$(( $VDEV_SZ / 2 ))
68
69typeset fill_mb=$(( floor($VDEV_SZ * 3 / 4 ) ))
70export DIRECTORY=/$TESTPOOL
71export NUMJOBS=4
72export RUNTIME=10
73export PERF_RANDSEED=1234
74export PERF_COMPPERCENT=66
75export PERF_COMPCHUNK=0
76export BLOCKSIZE=128K
77export SYNC_TYPE=0
78export DIRECT=1
79export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))
80
81log_must set_tunable32 L2ARC_WRITE_MAX $(( $VCACHE_SZ * 2 ))
82
83log_must truncate -s $VCACHE_SZ $VCACHE
84log_must truncate -s $VDEV_SZ $VDEV
85
86log_must zpool create -f $TESTPOOL $VDEV cache $VCACHE
87
88# Actually, this test relies on atime writes to force the L2 ARC discards
89log_must zfs set relatime=off $TESTPOOL
90
91log_must fio $FIO_SCRIPTS/mkfiles.fio
92log_must fio $FIO_SCRIPTS/random_reads.fio
93
94log_must set_tunable32 L2ARC_WRITE_MAX $(( 256 * 1024 * 1024 ))
95export RUNTIME=1
96
97typeset do_once=true
98while $do_once || [[ $l2_size1 -le $l2_size2 ]]; do
99	typeset l2_size1=$(get_arcstat l2_size)
100	log_must fio $FIO_SCRIPTS/random_reads.fio
101	typeset l2_size2=$(get_arcstat l2_size)
102	do_once=false
103done
104
105log_must zpool destroy $TESTPOOL
106
107log_pass "Looping around a cache device succeeds."
108