common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / btrfs / 181
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 181
6 #
7 # Test if btrfs will commit too many transactions for nothing and cause
8 # performance regression during balance.
9 #
10 # This bug is going to be fixed by a patch for kernel title
11 # "btrfs: don't end the transaction for delayed refs in throttle"
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs btrfs
39 _supported_os Linux
40 _require_scratch
41 _require_btrfs_command inspect-internal dump-super
42
43 _scratch_mkfs > /dev/null
44
45 _scratch_mount
46
47 nr_files=1024
48
49 get_super_gen()
50 {
51         local ret=$($BTRFS_UTIL_PROG inspect dump-super "$SCRATCH_DEV" |\
52                 grep ^generation | awk '{print $2}')
53         if [ -z $ret ]; then
54                 _fail "failed to get super block generation"
55         fi
56         echo "$ret"
57 }
58
59 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
60
61 # Create some small files to take up enough metadata reserved space
62 for ((i = 0; i < $nr_files; i++)) do
63         _pwrite_byte 0xcd 0 1K "$SCRATCH_MNT/subvol/file_$i" > /dev/null
64 done
65
66 # Commit the fs so we can get a stable super generation
67 sync
68
69 before_gen=$(get_super_gen)
70
71 _run_btrfs_balance_start -m $SCRATCH_MNT >> $seqres.full
72
73 after_gen=$(get_super_gen)
74
75 # Since the fs is pretty small, we should have only 1 small metadata chunk and
76 # one tiny system chunk.
77 # Relocating such small chunks only needs 6 commits for each, thus 12 commits for
78 # 2 chunks.
79 # Here we use 10x the theoretic value as threshold.
80 theoretic_gen=$(( 6 * 2 ))
81 threshold_gen=$(( 10 * $theoretic_gen ))
82 if [ $(( $after_gen - $before_gen )) -gt 120 ]; then
83         echo "balance committed too many transactions"
84         echo "super generation before balance: ${before_gen}"
85         echo "super generation after balance:  ${after_gen}"
86         echo "super generation difference:     $((after_gen - before_gen))"
87         echo "theoretic generation difference: ${theoretic_gen}"
88         echo "threshold generation difference: ${threshold_gen}"
89 fi
90
91 echo "super generation before balance: ${before_gen}" >> $seqres.full
92 echo "super generation after balance:  ${after_gen}" >> $seqres.full
93 echo "super generation difference:     $((after_gen - before_gen))" >> $seqres.full
94 echo "theoretic generation difference: ${theoretic_gen}" >> $seqres.full
95 echo "threshold generation difference: ${threshold_gen}" >> $seqres.full
96
97 # success, all done
98 echo "Silence is golden"
99
100 status=0
101 exit