1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
25#
26
27. $STF_SUITE/include/libtest.shlib
28. $STF_SUITE/include/math.shlib
29
30#
31# DESCRIPTION:
32# Ensure that dbufs move from mru to mfu as expected.
33#
34# STRATEGY:
35# 1. Set dbuf cache size to a small size (10M for this test)
36# 2. Generate a file with random data (small enough to fit in cache)
37# 3. zpool sync to remove dbufs from anon list in ARC
38# 4. Obtain the object ID using linux stat command
39# 5. Ensure that all dbufs are on the mru list in the ARC
40# 6. Generate another random file large enough to flush dbuf cache
41# 7. cat the first generated file
42# 8. Ensure that at least some dbufs moved to the mfu list in the ARC
43#
44
45DBUFS_FILE=$(mktemp $TEST_BASE_DIR/dbufs.out.XXXXXX)
46
47function cleanup
48{
49	log_must rm -f $TESTDIR/file $TESTDIR/file2 $DBUFS_FILE
50}
51
52verify_runnable "both"
53
54log_assert "dbufs move from mru to mfu list"
55
56log_onexit cleanup
57
58log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 1 -d R
59sync_all_pools
60
61objid=$(get_objnum "$TESTDIR/file")
62log_note "Object ID for $TESTDIR/file is $objid"
63
64log_must eval "kstat dbufs > $DBUFS_FILE"
65dbuf=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid" | wc -l)
66mru=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=1" | wc -l)
67mfu=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=3" | wc -l)
68log_note "dbuf count is $dbuf, mru count is $mru, mfu count is $mfu"
69verify_ne "0" "$mru" "mru count"
70verify_eq "0" "$mfu" "mfu count"
71
72log_must eval "cat $TESTDIR/file > /dev/null"
73log_must eval "kstat dbufs > $DBUFS_FILE"
74dbuf=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid" | wc -l)
75mru=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=1" | wc -l)
76mfu=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=3" | wc -l)
77log_note "dbuf count is $dbuf, mru count is $mru, mfu count is $mfu"
78verify_ne "0" "$mfu" "mfu count"
79
80log_pass "dbufs move from mru to mfu list passed"
81