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 _begin_fstest auto quick clone send
17 # Import common functions.
21 # real QA test starts here
23 # Modify as appropriate.
26 _require_scratch_reflink
28 _scratch_mkfs > /dev/null 2>&1
31 nr_extents=$((256 * $LOAD_FACTOR))
33 # Use 128K blocksize, the default value of both deduperemove or
35 blocksize=$((128 * 1024))
36 file=$SCRATCH_MNT/foobar
38 echo LOAD_FACTOR=$LOAD_FACTOR nr_extents=$nr_extents blocksize=$blocksize >> $seqres.full
40 # create the initial file, whose file extents are all point to one extent
41 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file | _filter_xfs_io
43 for i in $(seq 1 $(($nr_extents - 1))); do
44 _reflink_range $file 0 $file $(($i * $blocksize)) $blocksize \
48 # create a RO snapshot, so we can send out the snapshot
49 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/ro_snap
51 # send out the subvolume, and it will either:
52 # 1) OOM since memory is allocated inside a O(n^3) loop
53 # 2) Softlock since time consuming backref walk is called without scheduling.
54 # the send destination is not important, just send will cause the problem
55 echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/ro_snap > /dev/null" >> $seqres.full
56 $BTRFS_UTIL_PROG send $SCRATCH_MNT/ro_snap > /dev/null 2>>$seqres.full