From 790f4d8444fa4bed79d2b441212eec2167414c65 Mon Sep 17 00:00:00 2001 From: Dave Chinner Date: Tue, 24 Sep 2024 10:45:48 +0200 Subject: [PATCH] xfs: new EOF fragmentation tests These tests create substantial file fragmentation as a result of application actions that defeat post-EOF preallocation optimisations. They are intended to replicate known vectors for these problems, and provide a check that the fragmentation levels have been controlled. The mitigations we make may not completely remove fragmentation (e.g. they may demonstrate speculative delalloc related extent size growth) so the checks don't assume we'll end up with perfect layouts and hence check for an exceptable level of fragmentation rather than none. Signed-off-by: Dave Chinner [move to different test number, update to current xfstest APIs] Signed-off-by: Christoph Hellwig Reviewed-by: Zorro Lang Signed-off-by: Zorro Lang --- tests/xfs/629 | 67 ++++++++++++++++++++++++++++++++++++++++ tests/xfs/629.out | 9 ++++++ tests/xfs/630 | 70 ++++++++++++++++++++++++++++++++++++++++++ tests/xfs/630.out | 9 ++++++ tests/xfs/631 | 70 ++++++++++++++++++++++++++++++++++++++++++ tests/xfs/631.out | 9 ++++++ tests/xfs/632 | 78 +++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/632.out | 33 ++++++++++++++++++++ 8 files changed, 345 insertions(+) create mode 100755 tests/xfs/629 create mode 100644 tests/xfs/629.out create mode 100755 tests/xfs/630 create mode 100644 tests/xfs/630.out create mode 100755 tests/xfs/631 create mode 100644 tests/xfs/631.out create mode 100755 tests/xfs/632 create mode 100644 tests/xfs/632.out diff --git a/tests/xfs/629 b/tests/xfs/629 new file mode 100755 index 00000000..58beedc0 --- /dev/null +++ b/tests/xfs/629 @@ -0,0 +1,67 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test No. 629 +# +# Post-EOF preallocation defeat test for O_SYNC buffered I/O. +# + +. ./common/preamble +_begin_fstest auto quick prealloc rw + +. ./common/filter + +_require_scratch +# _count_extents() needs the fiemap command +_require_xfs_io_command "fiemap" + +_cleanup() +{ + # wait all background processes done + wait + cd / + rm -r -f $tmp.* +} + +_scratch_mkfs > "$seqres.full" 2>&1 +_scratch_mount + +# Write multiple files in parallel using synchronous buffered writes. Aim is to +# interleave allocations to fragment the files. Synchronous writes defeat the +# open/write/close heuristics in xfs_file_release() that prevent EOF block +# removal, so this should fragment badly. Typical problematic behaviour shows +# per-file extent counts of >900 (almost worse case) whilst fixed behaviour +# typically shows extent counts in the low 20s. +# +# Failure is determined by golden output mismatch from _within_tolerance(). + +workfile=$SCRATCH_MNT/file +nfiles=8 +wsize=4096 +wcnt=1000 + +write_sync_file() +{ + idx=$1 + + for ((cnt=0; cnt /dev/null 2>&1 & +done +wait +sync + +for ((n=0; n "$seqres.full" 2>&1 +_scratch_mount + +# Write multiple files in parallel using buffered writes with extent size hints. +# Aim is to interleave allocations to fragment the files. Writes w/ extent size +# hints set defeat the open/write/close heuristics in xfs_file_release() that +# prevent EOF block removal, so this should fragment badly. Typical problematic +# behaviour shows per-file extent counts of 1000 (worst case!) whilst +# fixed behaviour should show very few extents (almost best case). +# +# Failure is determined by golden output mismatch from _within_tolerance(). + +workfile=$SCRATCH_MNT/file +nfiles=8 +wsize=4096 +wcnt=1000 +extent_size=16m + +write_extsz_file() +{ + idx=$1 + + $XFS_IO_PROG -f -c "extsize $extent_size" $workfile.$idx + for ((cnt=0; cnt /dev/null 2>&1 & +done +wait +sync + +for ((n=0; n "$seqres.full" 2>&1 +_scratch_mount + +# Write multiple files in parallel using O_DIRECT writes w/ extent size hints. +# Aim is to interleave allocations to fragment the files. O_DIRECT writes defeat +# the open/write/close heuristics in xfs_file_release() that prevent EOF block +# removal, so this should fragment badly. Typical problematic behaviour shows +# per-file extent counts of ~1000 (worst case) whilst fixed behaviour typically +# shows extent counts in the low single digits (almost best case) +# +# Failure is determined by golden output mismatch from _within_tolerance(). + +workfile=$SCRATCH_MNT/file +nfiles=8 +wsize=4096 +wcnt=1000 +extent_size=16m + +write_direct_file() +{ + idx=$1 + + $XFS_IO_PROG -f -c "extsize $extent_size" $workfile.$idx + for ((cnt=0; cnt /dev/null 2>&1 & +done +wait +sync + +for ((n=0; n "$seqres.full" 2>&1 +_scratch_mount + +# Write multiple files in parallel using synchronous buffered writes that +# repeatedly close and reopen the fails. Aim is to interleave allocations to +# fragment the files. Assuming we've fixed the synchronous write defeat, we can +# still trigger the same issue with a open/read/close on O_RDONLY files. We +# should not be triggering EOF preallocation removal on files we don't have +# permission to write, so until this is fixed it should fragment badly. Typical +# problematic behaviour shows per-file extent counts of 50-350 whilst fixed +# behaviour typically demonstrates post-eof speculative delalloc growth in +# extent size (~6 extents for 50MB file). +# +# Failure is determined by golden output mismatch from _within_tolerance(). + +workfile=$SCRATCH_MNT/file +nfiles=32 +wsize=4096 +wcnt=1000 + +write_file() +{ + idx=$1 + + $XFS_IO_PROG -f -s -c "pwrite -b 64k 0 50m" $workfile.$idx +} + +read_file() +{ + idx=$1 + + for ((cnt=0; cnt /dev/null 2>&1 & + read_file $n > /dev/null 2>&1 & +done +wait + +for ((n=0; n