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
43log_assert "L2ARC MFU/MRU arcstats do not leak."
44
45function cleanup
46{
47	if poolexists $TESTPOOL ; then
48		destroy_pool $TESTPOOL
49	fi
50
51	log_must set_tunable32 l2arc_noprefetch $noprefetch
52}
53log_onexit cleanup
54
55# l2arc_noprefetch is set to 0 to let L2ARC handle prefetches
56typeset noprefetch=$(get_tunable l2arc_noprefetch)
57log_must set_tunable32 l2arc_noprefetch 0
58
59typeset fill_mb=800
60typeset cache_sz=$(( 1.4 * $fill_mb ))
61export FILE_SIZE=$(( floor($fill_mb / $NUMJOBS) ))M
62
63log_must truncate -s ${cache_sz}M $VDEV_CACHE
64
65log_must zpool create -f $TESTPOOL $VDEV cache $VDEV_CACHE
66
67log_must fio $FIO_SCRIPTS/mkfiles.fio
68log_must fio $FIO_SCRIPTS/random_reads.fio
69
70arcstat_quiescence_noecho l2_size
71log_must zpool offline $TESTPOOL $VDEV_CACHE
72arcstat_quiescence_noecho l2_size
73
74typeset l2_mfu_init=$(get_arcstat l2_mfu_asize)
75typeset l2_mru_init=$(get_arcstat l2_mru_asize)
76typeset l2_prefetch_init=$(get_arcstat l2_prefetch_asize)
77typeset l2_asize_init=$(get_arcstat l2_asize)
78
79log_must zpool online $TESTPOOL $VDEV_CACHE
80arcstat_quiescence_noecho l2_size
81log_must zpool export $TESTPOOL
82arcstat_quiescence_noecho l2_feeds
83
84log_must test $(get_arcstat l2_mfu_asize) -eq 0
85log_must test $(get_arcstat l2_mru_asize) -eq 0
86log_must zpool import -d $VDIR $TESTPOOL
87arcstat_quiescence_noecho l2_size
88
89log_must fio $FIO_SCRIPTS/random_reads.fio
90arcstat_quiescence_noecho l2_size
91log_must zpool offline $TESTPOOL $VDEV_CACHE
92arcstat_quiescence_noecho l2_size
93
94typeset l2_mfu_end=$(get_arcstat l2_mfu_asize)
95typeset l2_mru_end=$(get_arcstat l2_mru_asize)
96typeset l2_prefetch_end=$(get_arcstat l2_prefetch_asize)
97typeset l2_asize_end=$(get_arcstat l2_asize)
98
99log_must test $(( $l2_mfu_end - $l2_mfu_init )) -gt 0
100log_must test $(( $l2_mru_end + $l2_mfu_end + $l2_prefetch_end - \
101	$l2_asize_end )) -eq 0
102log_must test $(( $l2_mru_init + $l2_mfu_init + $l2_prefetch_init - \
103	$l2_asize_init )) -eq 0
104
105log_must zpool destroy -f $TESTPOOL
106
107log_pass "L2ARC MFU/MRU arcstats do not leak."
108