2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test if btrfs will commit too many transactions for nothing and cause
8 # performance regression during balance.
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"
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
32 # remove previous $seqres.full before test
35 # real QA test starts here
37 # Modify as appropriate.
40 _require_btrfs_command inspect-internal dump-super
42 _scratch_mkfs > /dev/null
50 local ret=$($BTRFS_UTIL_PROG inspect dump-super "$SCRATCH_DEV" |\
51 grep ^generation | awk '{print $2}')
53 _fail "failed to get super block generation"
58 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
60 # Create some small files to take up enough metadata reserved space
61 for ((i = 0; i < $nr_files; i++)) do
62 _pwrite_byte 0xcd 0 1K "$SCRATCH_MNT/subvol/file_$i" > /dev/null
65 # Commit the fs so we can get a stable super generation
68 before_gen=$(get_super_gen)
70 _run_btrfs_balance_start -m $SCRATCH_MNT >> $seqres.full
72 after_gen=$(get_super_gen)
74 # Since the fs is pretty small, we should have only 1 small metadata chunk and
75 # one tiny system chunk.
76 # Relocating such small chunks only needs 6 commits for each, thus 12 commits for
78 # Here we use 10x the theoretic value as threshold.
79 theoretic_gen=$(( 6 * 2 ))
80 threshold_gen=$(( 10 * $theoretic_gen ))
81 if [ $(( $after_gen - $before_gen )) -gt 120 ]; then
82 echo "balance committed too many transactions"
83 echo "super generation before balance: ${before_gen}"
84 echo "super generation after balance: ${after_gen}"
85 echo "super generation difference: $((after_gen - before_gen))"
86 echo "theoretic generation difference: ${theoretic_gen}"
87 echo "threshold generation difference: ${threshold_gen}"
90 echo "super generation before balance: ${before_gen}" >> $seqres.full
91 echo "super generation after balance: ${after_gen}" >> $seqres.full
92 echo "super generation difference: $((after_gen - before_gen))" >> $seqres.full
93 echo "theoretic generation difference: ${theoretic_gen}" >> $seqres.full
94 echo "threshold generation difference: ${threshold_gen}" >> $seqres.full
97 echo "Silence is golden"