]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh
ZTS: normalize on use of `sync_pool` and `sync_all_pools`
[mirror_zfs.git] / tests / zfs-tests / tests / functional / arc / dbufstats_002_pos.ksh
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 http://www.opensolaris.org/os/licensing.
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
45 DBUFS_FILE=$(mktemp $TEST_BASE_DIR/dbufs.out.XXXXXX)
46
47 function cleanup
48 {
49 log_must rm -f $TESTDIR/file $TESTDIR/file2 $DBUFS_FILE
50 }
51
52 verify_runnable "both"
53
54 log_assert "dbufs move from mru to mfu list"
55
56 log_onexit cleanup
57
58 log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 1 -d R
59 sync_all_pools
60
61 objid=$(get_objnum "$TESTDIR/file")
62 log_note "Object ID for $TESTDIR/file is $objid"
63
64 log_must eval "kstat dbufs > $DBUFS_FILE"
65 dbuf=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid" | wc -l)
66 mru=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=1" | wc -l)
67 mfu=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=3" | wc -l)
68 log_note "dbuf count is $dbuf, mru count is $mru, mfu count is $mfu"
69 verify_ne "0" "$mru" "mru count"
70 verify_eq "0" "$mfu" "mfu count"
71
72 log_must eval "cat $TESTDIR/file > /dev/null"
73 log_must eval "kstat dbufs > $DBUFS_FILE"
74 dbuf=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid" | wc -l)
75 mru=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=1" | wc -l)
76 mfu=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=3" | wc -l)
77 log_note "dbuf count is $dbuf, mru count is $mru, mfu count is $mfu"
78 verify_ne "0" "$mfu" "mfu count"
79
80 log_pass "dbufs move from mru to mfu list passed"