2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test No. xfs/013
7 # Exercise the free inode btree (finobt). XFS allocates physical inodes in
8 # chunks of 64. Inode records with at least one free inode are stored in the
9 # finobt to optimize free inode lookup. This test runs a workload that creates
10 # and modifies a sparsely allocated set of inodes in combination with an
14 _begin_fstest auto metadata stress
16 # Import common functions.
19 # Override the default cleanup function.
22 $KILLALL_PROG -9 fsstress 2>/dev/null
25 _scratch_unmount 2>/dev/null
30 sed -e '/^.*No space left on device.*/d'
39 for i in $(seq 0 $count)
41 touch $dir/$i 2>&1 | filter_enospc
50 # replace 5% of the dataset
51 for i in $(seq 0 $((count / 20)))
53 file=$((RANDOM % count))
55 touch $dir/$file 2>&1 | filter_enospc
65 iters=$((iters - mindirs))
67 for i in $(seq 1 $iters)
69 need=$dir/dir$((i + mindirs))
73 if ! pgrep fsstress > /dev/null 2>&1; then
83 # real QA test starts here
87 _require_xfs_mkfs_finobt
89 _require_command "$KILLALL_PROG" killall
91 _scratch_mkfs_xfs "-m crc=1,finobt=1 -d agcount=2" | \
92 _filter_mkfs 2>> $seqres.full
95 COUNT=20000 # number of files per directory
96 LOOPS=15 # last loop iteration
97 MINDIRS=2 # number of dirs for the cleaner to leave trailing behind the
98 # most recent (no less than 2 to prevent an rm from trampling a
101 # create initial directory
102 _create $SCRATCH_MNT/dir1 $COUNT
104 # start background cleaner to remove old directories as new ones are created
105 _cleaner $SCRATCH_MNT $LOOPS $MINDIRS &
107 # start a background stress workload on the fs
108 $FSSTRESS_PROG -d $SCRATCH_MNT/fsstress -n 9999999 -p 2 -S t \
109 >> $seqres.full 2>&1 &
111 # Each cycle clones the current directory and makes a random file replacement
112 # pass on the new directory. The directory is copied to the next using hard
113 # links. The replacement pass then randomly removes and replaces ~5% of the
114 # content in the directory. Files replaced as such are effectively marked to be
115 # freed by the background cleaner as it moves forward and removes all of the
116 # previous hard links to the inode. Over several iterations, this workload
117 # creates a sparsely located set of a free inodes across the set and uses the
118 # finobt to allocate new inodes for replacement.
120 for i in $(seq 1 $LOOPS)
122 # hard link the content of the current directory to the next
123 while ! test -d $SCRATCH_MNT/dir$((i+1)); do
124 cp -Rl $SCRATCH_MNT/dir$i $SCRATCH_MNT/dir$((i+1)) 2>&1 | \
128 # do a random replacement of files in the new directory
129 _rand_replace $SCRATCH_MNT/dir$((i+1)) $COUNT
132 $KILLALL_PROG fsstress
135 # clean out the competing fsstress allocations, then everything else
136 rm -rf $SCRATCH_MNT/fsstress
137 rm -rf $SCRATCH_MNT/dir*