2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
7 # Check if btrfs send can handle large deduped file, whose file extents
8 # are all pointing to one extent.
9 # Such file structure will cause quite large pressure to any operation which
10 # iterates all backref of one extent.
11 # And unfortunately, btrfs send is one of these operations, and will cause
12 # softlock or OOM on systems with small memory(<4G).
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
20 status=1 # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 # real QA test starts here
39 # Modify as appropriate.
42 _require_scratch_reflink
44 _scratch_mkfs > /dev/null 2>&1
47 nr_extents=$((256 * $LOAD_FACTOR))
49 # Use 128K blocksize, the default value of both deduperemove or
51 blocksize=$((128 * 1024))
52 file=$SCRATCH_MNT/foobar
54 echo LOAD_FACTOR=$LOAD_FACTOR nr_extents=$nr_extents blocksize=$blocksize >> $seqres.full
56 # create the initial file, whose file extents are all point to one extent
57 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
59 for i in $(seq 1 $(($nr_extents - 1))); do
60 _reflink_range $file 0 $file $(($i * $blocksize)) $blocksize \
64 # create a RO snapshot, so we can send out the snapshot
65 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/ro_snap
67 # send out the subvolume, and it will either:
68 # 1) OOM since memory is allocated inside a O(n^3) loop
69 # 2) Softlock since time consuming backref walk is called without scheduling.
70 # the send destination is not important, just send will cause the problem
71 echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/ro_snap > /dev/null" >> $seqres.full
72 $BTRFS_UTIL_PROG send $SCRATCH_MNT/ro_snap > /dev/null 2>>$seqres.full