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.
41 _require_btrfs_command inspect-internal dump-super
43 _scratch_mkfs > /dev/null
51 local ret=$($BTRFS_UTIL_PROG inspect dump-super "$SCRATCH_DEV" |\
52 grep ^generation | awk '{print $2}')
54 _fail "failed to get super block generation"
59 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
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
66 # Commit the fs so we can get a stable super generation
69 before_gen=$(get_super_gen)
71 _run_btrfs_balance_start -m $SCRATCH_MNT >> $seqres.full
73 after_gen=$(get_super_gen)
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
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}"
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
98 echo "Silence is golden"