xfs/23[12]: abstractify the XFS cow prealloc trimming interval
authorDarrick J. Wong <djwong@kernel.org>
Wed, 31 Mar 2021 01:09:05 +0000 (18:09 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 11 Apr 2021 12:29:14 +0000 (20:29 +0800)
Create a couple of helper functions to get and set the XFS copy on write
preallocation garbage collection interval.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/xfs
tests/xfs/231
tests/xfs/232

index 69f76d6..88510cf 100644 (file)
@@ -1079,3 +1079,26 @@ _require_xfs_copy()
        [ "$USE_EXTERNAL" = yes ] && \
                _notrun "Cannot xfs_copy with external devices"
 }
+
+__xfs_cowgc_interval_knob1="/proc/sys/fs/xfs/speculative_cow_prealloc_lifetime"
+__xfs_cowgc_interval_knob2="/proc/sys/fs/xfs/speculative_prealloc_lifetime"
+
+_xfs_set_cowgc_interval() {
+       if [ -w $__xfs_cowgc_interval_knob1 ]; then
+               echo "$@" > $__xfs_cowgc_interval_knob1
+       elif [ -w $__xfs_cowgc_interval_knob2 ]; then
+               echo "$@" > $__xfs_cowgc_interval_knob2
+       else
+               _fail "Can't find cowgc interval procfs knob?"
+       fi
+}
+
+_xfs_get_cowgc_interval() {
+       if [ -w $__xfs_cowgc_interval_knob1 ]; then
+               cat $__xfs_cowgc_interval_knob1
+       elif [ -w $__xfs_cowgc_interval_knob2 ]; then
+               cat $__xfs_cowgc_interval_knob2
+       else
+               _fail "Can't find cowgc interval procfs knob?"
+       fi
+}
index 5930339..119a71b 100755 (executable)
@@ -22,9 +22,10 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _cleanup()
 {
-    cd /
-    echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
-    rm -rf $tmp.*
+       cd /
+       test -n "$old_cowgc_interval" && \
+               _xfs_set_cowgc_interval $old_cowgc_interval
+       rm -rf $tmp.*
 }
 
 # get standard environment, filters and checks
@@ -40,7 +41,7 @@ _require_xfs_io_command "cowextsize"
 _require_xfs_io_command "falloc"
 _require_xfs_io_command "fiemap"
 
-old_cow_lifetime=$(cat /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime)
+old_cowgc_interval=$(_xfs_get_cowgc_interval)
 
 rm -f $seqres.full
 
@@ -74,7 +75,7 @@ md5sum $testdir/file2 | _filter_scratch
 md5sum $testdir/file2.chk | _filter_scratch
 
 echo "CoW and leave leftovers"
-echo 2 > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
+_xfs_set_cowgc_interval 2
 seq 2 2 $((nr - 1)) | while read f; do
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
@@ -91,7 +92,7 @@ done
 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
 
 echo "CoW and leave leftovers"
-echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
+_xfs_set_cowgc_interval $old_cowgc_interval
 seq 2 2 $((nr - 1)) | while read f; do
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full
index e56eb3a..909f921 100755 (executable)
@@ -23,9 +23,10 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _cleanup()
 {
-    cd /
-    echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
-    rm -rf $tmp.*
+       cd /
+       test -n "$old_cowgc_interval" && \
+               _xfs_set_cowgc_interval $old_cowgc_interval
+       rm -rf $tmp.*
 }
 
 # get standard environment, filters and checks
@@ -41,7 +42,7 @@ _require_cp_reflink
 _require_xfs_io_command "falloc"
 _require_xfs_io_command "fiemap"
 
-old_cow_lifetime=$(cat /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime)
+old_cowgc_interval=$(_xfs_get_cowgc_interval)
 
 rm -f $seqres.full
 
@@ -75,7 +76,7 @@ md5sum $testdir/file2 | _filter_scratch
 md5sum $testdir/file2.chk | _filter_scratch
 
 echo "CoW and leave leftovers"
-echo 2 > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
+_xfs_set_cowgc_interval 2
 seq 2 2 $((nr - 1)) | while read f; do
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2 >> $seqres.full
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f - 1)) 1" $testdir/file2.chk >> $seqres.full
@@ -93,7 +94,7 @@ done
 $XFS_IO_PROG -f -c "falloc 0 $filesize" $testdir/junk >> $seqres.full
 
 echo "CoW and leave leftovers"
-echo $old_cow_lifetime > /proc/sys/fs/xfs/speculative_cow_prealloc_lifetime
+_xfs_set_cowgc_interval $old_cowgc_interval
 seq 2 2 $((nr - 1)) | while read f; do
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2 >> $seqres.full
        $XFS_IO_PROG -f -c "pwrite -S 0x63 $((blksz * f)) 1" $testdir/file2.chk >> $seqres.full