* [PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses
@ 2026-03-25 12:50 Hans Holmberg
2026-03-26 6:11 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Hans Holmberg @ 2026-03-25 12:50 UTC (permalink / raw)
To: zlang
Cc: fstests, Christoph Hellwig, Damien Le Moal, Darrick J . Wong,
linux-xfs, Hans Holmberg
Test that writes to the systfs attribute zone_gc_low_space triggers
garbage collection for rw (but not ro) file systems.
Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
---
This test will fail currently, but i've submitted a fix:
https://lore.kernel.org/linux-xfs/20260325124312.26349-1-hans.holmberg@wdc.com/
tests/xfs/999 | 89 +++++++++++++++++++++++++++++++++++++++++++++++
tests/xfs/999.out | 2 ++
2 files changed, 91 insertions(+)
create mode 100755 tests/xfs/999
create mode 100644 tests/xfs/999.out
diff --git a/tests/xfs/999 b/tests/xfs/999
new file mode 100755
index 000000000000..f3c2f868cb1e
--- /dev/null
+++ b/tests/xfs/999
@@ -0,0 +1,89 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Western Digital Corporation
+#
+# FS QA Test No. 999
+#
+# Tests that writes to gc_low_space will trigger start of garbage
+# collection for rw (but not ro) file systems
+#
+. ./common/preamble
+_begin_fstest auto rw zone quick
+
+. ./common/zoned
+
+_require_scratch
+_require_odirect
+
+get_scratch_mountstat() {
+ awk -v mount="$SCRATCH_MNT" -v stat="$1" \
+ '$0~"mounted on "mount" with fstype xfs"{f=1} f&&index($0,stat){print $NF;exit}' \
+ /proc/self/mountstats
+}
+
+get_user_available_rt_blocks() {
+ get_scratch_mountstat "user available RT blocks:"
+}
+
+gc_required() {
+ get_scratch_mountstat "RT GC required:"
+}
+
+# figure out if the rt section is internal or not
+if [ -z "$SCRATCH_RTDEV" ]; then
+ zdev=$SCRATCH_DEV
+else
+ zdev=$SCRATCH_RTDEV
+fi
+
+capacity=$(_zone_capacity 0 $zdev)
+_scratch_mkfs_sized $(($capacity * 6)) > $seqres.full 2>&1
+
+# limit max open zones to avoid gc to trigger before we want it to
+export MOUNT_OPTIONS="$MOUNT_OPTIONS -o max_open_zones=2"
+_try_scratch_mount || _notrun "mount option not supported"
+_require_xfs_scratch_zoned
+
+# create three zone-sized files and invalidate 95% of the data
+for i in $(seq 1 3); do
+ filename=$SCRATCH_MNT/data_$i
+ dd if=/dev/zero of=$filename bs=1M oflag=direct\
+ count=$(($capacity / (1024 * 1024))) >> $seqres.full 2>&1
+ truncate -s $(($capacity / 20)) $filename
+done
+
+# remount read-only and set the gc limit to free up unused space
+_scratch_remount ro
+rt_available_pre="$(get_user_available_rt_blocks)"
+_set_fs_sysfs_attr $SCRATCH_DEV "zoned/zonegc_low_space" 100
+
+# reclaiming a zone with 5% used blocks should take way less than 1 second
+sleep 1
+
+# gc should not run for read only file systems
+rt_available_post="$(get_user_available_rt_blocks)"
+[ "$rt_available_post" -gt "$rt_available_pre" ] && _fail "gc should not run while read only"
+
+_set_fs_sysfs_attr $SCRATCH_DEV "zoned/zonegc_low_space" 0
+
+# remount rw and check that gc starts, frees up blocks and stops after
+# the threshold is set to reclaim the unused blocks
+_scratch_remount rw
+
+rt_available_pre="$(get_user_available_rt_blocks)"
+_set_fs_sysfs_attr $SCRATCH_DEV "zoned/zonegc_low_space" 100
+
+i=0
+while [ $(gc_required) -eq "1" ]; do
+ sleep 1
+ let i=$i+1
+ [ $i -gt 3 ] && _fail "gc did not complete within a reasonable time"
+done
+
+rt_available_post="$(get_user_available_rt_blocks)"
+[ "$rt_available_pre" -ge "$rt_available_post" ] && _fail "gc did not free up space"
+
+echo "Silence is golden"
+status=0
+
+exit
diff --git a/tests/xfs/999.out b/tests/xfs/999.out
new file mode 100644
index 000000000000..3b276ca804fc
--- /dev/null
+++ b/tests/xfs/999.out
@@ -0,0 +1,2 @@
+QA output created by 999
+Silence is golden
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses
2026-03-25 12:50 [PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses Hans Holmberg
@ 2026-03-26 6:11 ` Christoph Hellwig
2026-03-26 13:41 ` Hans Holmberg
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2026-03-26 6:11 UTC (permalink / raw)
To: Hans Holmberg
Cc: zlang, fstests, Christoph Hellwig, Damien Le Moal,
Darrick J . Wong, linux-xfs
On Wed, Mar 25, 2026 at 01:50:13PM +0100, Hans Holmberg wrote:
> Test that writes to the systfs attribute zone_gc_low_space triggers
s/systfs/sysfs/
> +get_scratch_mountstat() {
> + awk -v mount="$SCRATCH_MNT" -v stat="$1" \
> + '$0~"mounted on "mount" with fstype xfs"{f=1} f&&index($0,stat){print $NF;exit}' \
> + /proc/self/mountstats
> +}
> +
> +get_user_available_rt_blocks() {
> + get_scratch_mountstat "user available RT blocks:"
> +}
> +
> +gc_required() {
> + get_scratch_mountstat "RT GC required:"
> +}
Should these go to common/xfs ?
> +
> +# figure out if the rt section is internal or not
> +if [ -z "$SCRATCH_RTDEV" ]; then
> + zdev=$SCRATCH_DEV
> +else
> + zdev=$SCRATCH_RTDEV
> +fi
Same for this asa new helper?
> +[ "$rt_available_post" -gt "$rt_available_pre" ] && _fail "gc should not run while read only"
Split up either using \ or a real if statement to avoid the overly long
line.
> +[ "$rt_available_pre" -ge "$rt_available_post" ] && _fail "gc did not free up space"
Same here.
Otherwise this looks good.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses
2026-03-26 6:11 ` Christoph Hellwig
@ 2026-03-26 13:41 ` Hans Holmberg
2026-03-26 14:12 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Hans Holmberg @ 2026-03-26 13:41 UTC (permalink / raw)
To: Christoph Hellwig
Cc: zlang@kernel.org, fstests@vger.kernel.org, Damien Le Moal,
Darrick J . Wong, linux-xfs@vger.kernel.org
On 26/03/2026 07:11, Christoph Hellwig wrote:
> On Wed, Mar 25, 2026 at 01:50:13PM +0100, Hans Holmberg wrote:
>> Test that writes to the systfs attribute zone_gc_low_space triggers
>
> s/systfs/sysfs/
>
>> +get_scratch_mountstat() {
>> + awk -v mount="$SCRATCH_MNT" -v stat="$1" \
>> + '$0~"mounted on "mount" with fstype xfs"{f=1} f&&index($0,stat){print $NF;exit}' \
>> + /proc/self/mountstats
>> +}
>> +
>> +get_user_available_rt_blocks() {
>> + get_scratch_mountstat "user available RT blocks:"
>> +}
>> +
>> +gc_required() {
>> + get_scratch_mountstat "RT GC required:"
>> +}
>
> Should these go to common/xfs ?
That would be useful I think.
And make them not specific to scratch?
_xfs_get_mountstats <MOUNTPOINT>
_xfs_get_rt_gc_required <MOUNTPOINT>
_xfs_get_user_available_rt_blocks <MOUNTPOINT>
>
>> +
>> +# figure out if the rt section is internal or not
>> +if [ -z "$SCRATCH_RTDEV" ]; then
>> + zdev=$SCRATCH_DEV
>> +else
>> + zdev=$SCRATCH_RTDEV
>> +fi
>
> Same for this asa new helper?
Yes, something like:
_xfs_get_scratch_rtdev
>
>> +[ "$rt_available_post" -gt "$rt_available_pre" ] && _fail "gc should not run while read only"
>
> Split up either using \ or a real if statement to avoid the overly long
> line.
>
>> +[ "$rt_available_pre" -ge "$rt_available_post" ] && _fail "gc did not free up space"
>
> Same here.
>
> Otherwise this looks good.
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses
2026-03-26 13:41 ` Hans Holmberg
@ 2026-03-26 14:12 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-03-26 14:12 UTC (permalink / raw)
To: Hans Holmberg
Cc: Christoph Hellwig, zlang@kernel.org, fstests@vger.kernel.org,
Damien Le Moal, Darrick J . Wong, linux-xfs@vger.kernel.org
On Thu, Mar 26, 2026 at 01:41:46PM +0000, Hans Holmberg wrote:
> That would be useful I think.
> And make them not specific to scratch?
>
> _xfs_get_mountstats <MOUNTPOINT>
> _xfs_get_rt_gc_required <MOUNTPOINT>
> _xfs_get_user_available_rt_blocks <MOUNTPOINT>
Sounds good!
>
> >
> >> +
> >> +# figure out if the rt section is internal or not
> >> +if [ -z "$SCRATCH_RTDEV" ]; then
> >> + zdev=$SCRATCH_DEV
> >> +else
> >> + zdev=$SCRATCH_RTDEV
> >> +fi
> >
> > Same for this asa new helper?
>
> Yes, something like:
>
> _xfs_get_scratch_rtdev
Maybe _xfs_get_scratch_rtdev_bdev? That might sounds a bit redundant,
but I think that's good to make the usage of this clear. A comment
explaining it would also be useful here.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-26 14:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25 12:50 [PATCH] xfs: test that zone_gc_low_space writes start gc for rw fses Hans Holmberg
2026-03-26 6:11 ` Christoph Hellwig
2026-03-26 13:41 ` Hans Holmberg
2026-03-26 14:12 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox