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/include/libtest.shlib
22. $STF_SUITE/tests/functional/l2arc/l2arc.cfg
23
24#
25# DESCRIPTION:
26#	L2ARC MFU/MRU arcstats do not leak
27#
28# STRATEGY:
29#	1. Create pool with a cache device.
30#	2. Create a random file in that pool, smaller than the cache device
31#		and random read for 10 sec.
32#	3. Read l2arc_mfu_asize and l2arc_mru_asize
33#	4. Export pool.
34#	5. Verify l2arc_mfu_asize and l2arc_mru_asize are 0.
35#	6. Import pool.
36#	7. Read random read for 10 sec.
37#	8. Read l2arc_mfu_asize and l2arc_mru_asize
38#	9. Verify that L2ARC MFU increased and MFU+MRU = L2_asize.
39#
40
41verify_runnable "global"
42
43command -v fio > /dev/null || log_unsupported "fio missing"
44
45log_assert "L2ARC MFU/MRU arcstats do not leak."
46
47function cleanup
48{
49	if poolexists $TESTPOOL ; then
50		destroy_pool $TESTPOOL
51	fi
52
53	log_must set_tunable32 L2ARC_NOPREFETCH $noprefetch
54}
55log_onexit cleanup
56
57# L2ARC_NOPREFETCH is set to 0 to let L2ARC handle prefetches
58typeset noprefetch=$(get_tunable L2ARC_NOPREFETCH)
59log_must set_tunable32 L2ARC_NOPREFETCH 0
60
61typeset fill_mb=800
62typeset cache_sz=$(( 1.4 * $fill_mb ))
63export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M
64
65log_must truncate -s ${cache_sz}M $VDEV_CACHE
66
67log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE
68
69log_must fio $FIO_SCRIPTS/mkfiles.fio
70log_must fio $FIO_SCRIPTS/random_reads.fio
71
72arcstat_quiescence_noecho l2_size
73log_must zpool offline $TESTPOOL $VDEV_CACHE
74arcstat_quiescence_noecho l2_size
75
76typeset l2_mfu_init=$(get_arcstat l2_mfu_asize)
77typeset l2_mru_init=$(get_arcstat l2_mru_asize)
78typeset l2_prefetch_init=$(get_arcstat l2_prefetch_asize)
79typeset l2_asize_init=$(get_arcstat l2_asize)
80
81log_must zpool online $TESTPOOL $VDEV_CACHE
82arcstat_quiescence_noecho l2_size
83log_must zpool export $TESTPOOL
84arcstat_quiescence_noecho l2_feeds
85
86log_must test $(get_arcstat l2_mfu_asize) -eq 0
87log_must test $(get_arcstat l2_mru_asize) -eq 0
88log_must zpool import -d $VDIR $TESTPOOL
89arcstat_quiescence_noecho l2_size
90
91log_must fio $FIO_SCRIPTS/random_reads.fio
92arcstat_quiescence_noecho l2_size
93log_must zpool offline $TESTPOOL $VDEV_CACHE
94arcstat_quiescence_noecho l2_size
95
96typeset l2_mfu_end=$(get_arcstat l2_mfu_asize)
97typeset l2_mru_end=$(get_arcstat l2_mru_asize)
98typeset l2_prefetch_end=$(get_arcstat l2_prefetch_asize)
99typeset l2_asize_end=$(get_arcstat l2_asize)
100
101log_must test $(( $l2_mru_end + $l2_mfu_end + $l2_prefetch_end - \
102	$l2_asize_end )) -eq 0
103log_must test $(( $l2_mru_init + $l2_mfu_init + $l2_prefetch_init - \
104	$l2_asize_init )) -eq 0
105
106log_must zpool destroy -f $TESTPOOL
107
108log_pass "L2ARC MFU/MRU arcstats do not leak."
109