aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2022-01-28 08:27:01 +0800
committerEryu Guan <guaneryu@gmail.com>2022-02-14 01:19:34 +0800
commitbf49b2cde6d6a25d9174006bd7d443601fd97575 (patch)
tree3f35b85beb067ee35ffe6637a815a8d13a5f76b4
parent8925b0290ffe0744d28f99a0a38e92e46cb85d75 (diff)
downloadxfstests-dev-bf49b2cde6d6a25d9174006bd7d443601fd97575.tar.gz
btrfs: defrag with compressed extents
There is a long existing bug in btrfs defrag code that it will always try to defrag compressed extents, even they are already at max capacity. This will not reduce the number of extents, but only waste IO/CPU. The kernel fix is titled: btrfs: defrag: don't defrag extents which is already at its max capacity Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
-rwxr-xr-xtests/btrfs/25957
-rw-r--r--tests/btrfs/259.out2
2 files changed, 59 insertions, 0 deletions
diff --git a/tests/btrfs/259 b/tests/btrfs/259
new file mode 100755
index 0000000000..e7bd8ddd7f
--- /dev/null
+++ b/tests/btrfs/259
@@ -0,0 +1,57 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test 259
+#
+# Make sure btrfs defrag ioctl won't defrag compressed extents which are already
+# at their max capacity.
+#
+. ./common/preamble
+_begin_fstest auto quick defrag
+
+# Import common functions.
+. ./common/filter
+. ./common/btrfs
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs btrfs
+_require_scratch
+
+_scratch_mkfs >> $seqres.full
+
+_scratch_mount -o compress
+
+# Btrfs uses 128K as max extent size for compressed extents, this would result
+# several compressed extents all at their max size
+$XFS_IO_PROG -f -c "pwrite -S 0xee 0 16m" -c sync \
+ $SCRATCH_MNT/foobar >> $seqres.full
+
+old_csum=$(_md5_checksum $SCRATCH_MNT/foobar)
+
+echo "=== File extent layout before defrag ===" >> $seqres.full
+$XFS_IO_PROG -c "fiemap -v" "$SCRATCH_MNT/foobar" >> $seqres.full
+$XFS_IO_PROG -c "fiemap -v" "$SCRATCH_MNT/foobar" > $tmp.before
+
+$BTRFS_UTIL_PROG filesystem defrag "$SCRATCH_MNT/foobar" >> $seqres.full
+sync
+
+new_csum=$(_md5_checksum $SCRATCH_MNT/foobar)
+
+echo "=== File extent layout before defrag ===" >> $seqres.full
+$XFS_IO_PROG -c "fiemap -v" "$SCRATCH_MNT/foobar" >> $seqres.full
+$XFS_IO_PROG -c "fiemap -v" "$SCRATCH_MNT/foobar" > $tmp.after
+
+if [ $new_csum != $old_csum ]; then
+ echo "file content changed"
+fi
+
+diff -q $tmp.before $tmp.after || echo "compressed extents get defragged"
+
+echo "Silence is golden"
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/259.out b/tests/btrfs/259.out
new file mode 100644
index 0000000000..bfbd2dea52
--- /dev/null
+++ b/tests/btrfs/259.out
@@ -0,0 +1,2 @@
+QA output created by 259
+Silence is golden