Skip to contentSkip to conversation

fstests: test that RWF_DONTCACHE I/O drops its folios

PATCH In review Tal Zussman 3 participants 8 messages Nov 8 – Nov 11

lore
Share & tools
lore
#0 lore raw

v2 cover fstests: test that RWF_DONTCACHE I/O drops its folios

Add a test for RWF_DONTCACHE, as suggested by Christoph. [1]

generic/810 writes and reads a 1M file with and without RWF_DONTCACHE and checks with mincore how much of it is still cached after each step. On ext4 without the fix, the dontcache overwrite leaves the whole file cached.

The first two patches make _require_xfs_io_command able to probe "pwrite -U" and "pread -U".

[1] https://lore.kernel.org/linux-ext4/20261012-ext4-dontcache-complete-in-task-v1-1-6ac801557041@columbia.edu/

---
Changes in v2:
- generic/810: fold the writeback wait into report_cached() with an
optional delay, and give the plain cases a short delay, per Brian
Foster.
- Link to v1: https://patch.msgid.link/[email protected]

---
Tal Zussman (3):
common/rc: probe pread options with a real read common/rc: pass -V 1 when probing pwrite and pread -U generic/810: check that RWF_DONTCACHE I/O drops its folios

 common/rc             | 14 ++++++++++
 tests/generic/810     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/810.out | 11 ++++++++
 3 files changed, 102 insertions(+)

---
base-commit: d07dca72d2455f4ba8c660ad4c008541ccccb707
change-id: 20261015-dontcache-test-be6094aa3f20

Best regards,

Signature · 1 line
Tal Zussman <[email protected]>
#1 lore raw

PATCH v2 1/3 common/rc: probe pread options with a real read

_require_xfs_io_command has no pread case, so a pread option falls back to a grep of the help text, and that only matches options that take an argument. A bare -U is reported as unsupported even when xfs_io has it. Add a pread case that does a real read with the option, like the pwrite case does.

---
 common/rc | 5 +++++
 1 file changed, 5 insertions(+)
common/rc +5 -0
index 1eccd60c..945c9e42 100644
@@ -3120,6 +3120,11 @@ _require_xfs_io_command()
 		        "pwrite $pwrite_opts $param 0 $write_size" $testfile 2>&1`
 		param_checked="$pwrite_opts $param"
 		;;
+	"pread")
+		testio=`$XFS_IO_PROG -f -c "pwrite 0 4k" \
+			-c "pread $param 0 4k" $testfile 2>&1`
+		param_checked="$param"
+		;;
 	"scrub"|"repair")
 		test -z "$param" && param="probe"
 		testio=`$XFS_IO_PROG -x -c "$command $param" $TEST_DIR 2>&1`
Signature · 1 line
2.39.5
#2 lore raw

PATCH v2 2/3 common/rc: pass -V 1 when probing pwrite and pread -U

In reply to Tal Zussman

xfs_io refuses pwritev2() and preadv2() flags unless -V is given, so probing -U without it always fails. Pass -V 1 for -U in both the pwrite and pread cases.

---
 common/rc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
common/rc +11 -2
index 945c9e42..a0239034 100644
@@ -3105,6 +3105,10 @@ _require_xfs_io_command()
 			opts+=" -d"
 			pwrite_opts+="-V 1 -b $write_size"
 		fi
+		# -U (RWF_DONTCACHE) only works with vectored I/O writes
+		if [ "$param" == "-U" ]; then
+			pwrite_opts+="-V 1 -b $write_size"
+		fi
 		if [ "$param" == "-A" ]; then
 			opts+=" -d"
 			# try to write the minimum supported atomic write size
@@ -3121,9 +3125,14 @@ _require_xfs_io_command()
 		param_checked="$pwrite_opts $param"
 		;;
 	"pread")
+		# -U (RWF_DONTCACHE) only works with vectored I/O reads
+		local pread_opts=" "
+		if [ "$param" == "-U" ]; then
+			pread_opts+="-V 1 -b 4k"
+		fi
 		testio=`$XFS_IO_PROG -f -c "pwrite 0 4k" \
-			-c "pread $param 0 4k" $testfile 2>&1`
-		param_checked="$param"
+			-c "pread $pread_opts $param 0 4k" $testfile 2>&1`
+		param_checked="$pread_opts $param"
 		;;
 	"scrub"|"repair")
 		test -z "$param" && param="probe"
Signature · 1 line
2.39.5
Reviewed-by on v2 2/3
#3 lore raw

Re: [PATCH v2 2/3] common/rc: pass -V 1 when probing pwrite and pread -U

Quoted 3 lines · Tal Zussman

xfs_io refuses pwritev2() and preadv2() flags unless -V is given, so probing -U without it always fails. Pass -V 1 for -U in both the pwrite and pread cases.

Looks good:

#4 lore raw

PATCH v2 3/3 generic/810: check that RWF_DONTCACHE I/O drops its folios

In reply to Tal Zussman

A dontcache write drops its folios from the page cache once writeback completes, and a dontcache read drops them once the read completes.

Test this by writing and reading a 1M file with and without RWF_DONTCACHE and checking with mincore how much of it is cached
afterwards: all of it for plain I/O, none of it for dontcache I/O.

The overwrite is a separate case because the drop is skipped when writeback completes in interrupt context, which is what happens on ext4 without commit "ext4: complete dropbehind writeback in task context" [1].

---
 tests/generic/810     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/810.out | 11 ++++++++
 2 files changed, 88 insertions(+)
tests/generic/810 new file +77 -0
new file mode 100755
index 00000000..1866848f
@@ -0,0 +1,77 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Tal Zussman.  All Rights Reserved.
+#
+# FS QA Test No. 810
+#
+# Check that RWF_DONTCACHE I/O drops its folios from the page cache: a
+# dontcache write once its writeback completes, and a dontcache read once the
+# read completes. Plain buffered I/O on the same file has to leave them cached.
+#
+. ./common/preamble
+_begin_fstest auto quick rw
+
+_require_scratch
+_require_xfs_io_command "pwrite" "-U"
+_require_xfs_io_command "pread" "-U"
+_require_xfs_io_command "mincore"
+_exclude_scratch_mount_option "dax"
+
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+size=$((1024 * 1024))
+file=$SCRATCH_MNT/file
+pagesize=$(_get_page_size)
+
+# Count the bytes of the file that are in the page cache.
+cached_bytes()
+{
+	local pages
+
+	pages=$($XFS_IO_PROG -c "mmap -r 0 $size" -c "mincore" $file | \
+		awk '{ n += $4 } END { print n + 0 }')
+	echo $((pages * pagesize))
+}
+
+# Report how many bytes are cached, after waiting up to $1 seconds for the
+# cache to empty. Dontcache writeback can drop folios just after fsync returns.
+report_cached()
+{
+	local delay=${1:-0}
+	local i
+
+	for ((i = 0; i < delay * 10; i++)); do
+		[ "$(cached_bytes)" -eq 0 ] && break
+		sleep 0.1
+	done
+	echo "$(cached_bytes) of $size bytes cached"
+}
+
+echo "plain write"
+$XFS_IO_PROG -f -c "pwrite -q 0 $size" -c fsync $file
+report_cached 1
+
+echo "dontcache write to a new file"
+rm -f $file
+$XFS_IO_PROG -f -c "pwrite -q -U -V 1 -b $size 0 $size" -c fsync $file
+report_cached 5
+
+# Start each of the remaining cases from an empty page cache.
+echo "dontcache overwrite"
+_scratch_cycle_mount
+$XFS_IO_PROG -c "pwrite -q -U -V 1 -b $size 0 $size" -c fsync $file
+report_cached 5
+
+echo "dontcache read"
+_scratch_cycle_mount
+$XFS_IO_PROG -c "pread -q -U -V 1 -b $size 0 $size" $file
+report_cached 5
+
+echo "plain read"
+_scratch_cycle_mount
+$XFS_IO_PROG -c "pread -q 0 $size" $file
+report_cached 1
+
+_scratch_unmount
+_exit 0
tests/generic/810.out new file +11 -0
new file mode 100644
index 00000000..cb6c3f2a
@@ -0,0 +1,11 @@
+QA output created by 810
+plain write
+1048576 of 1048576 bytes cached
+dontcache write to a new file
+0 of 1048576 bytes cached
+dontcache overwrite
+0 of 1048576 bytes cached
+dontcache read
+0 of 1048576 bytes cached
+plain read
+1048576 of 1048576 bytes cached
Signature · 1 line
2.39.5
Reviewed-by on v2 3/3
#5 lore raw

Re: [PATCH v2 3/3] generic/810: check that RWF_DONTCACHE I/O drops its folios

Quoted 7 lines · Tal Zussman

A dontcache write drops its folios from the page cache once writeback completes, and a dontcache read drops them once the read completes.

Test this by writing and reading a 1M file with and without RWF_DONTCACHE and checking with mincore how much of it is cached
afterwards: all of it for plain I/O, none of it for dontcache I/O.

Quoted 8 lines

The overwrite is a separate case because the drop is skipped when writeback completes in interrupt context, which is what happens on ext4 without commit "ext4: complete dropbehind writeback in task context" [1].

---

I like it. Thanks for the tweaks!

Quoted 109 lines
 tests/generic/810     | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/810.out | 11 ++++++++
 2 files changed, 88 insertions(+)
tests/generic/810 new file +77 -0
new file mode 100755
index 00000000..1866848f
@@ -0,0 +1,77 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Tal Zussman.  All Rights Reserved.
+#
+# FS QA Test No. 810
+#
+# Check that RWF_DONTCACHE I/O drops its folios from the page cache: a
+# dontcache write once its writeback completes, and a dontcache read once the
+# read completes. Plain buffered I/O on the same file has to leave them cached.
+#
+. ./common/preamble
+_begin_fstest auto quick rw
+
+_require_scratch
+_require_xfs_io_command "pwrite" "-U"
+_require_xfs_io_command "pread" "-U"
+_require_xfs_io_command "mincore"
+_exclude_scratch_mount_option "dax"
+
+_scratch_mkfs > $seqres.full 2>&1
+_scratch_mount
+
+size=$((1024 * 1024))
+file=$SCRATCH_MNT/file
+pagesize=$(_get_page_size)
+
+# Count the bytes of the file that are in the page cache.
+cached_bytes()
+{
+	local pages
+
+	pages=$($XFS_IO_PROG -c "mmap -r 0 $size" -c "mincore" $file | \
+		awk '{ n += $4 } END { print n + 0 }')
+	echo $((pages * pagesize))
+}
+
+# Report how many bytes are cached, after waiting up to $1 seconds for the
+# cache to empty. Dontcache writeback can drop folios just after fsync returns.
+report_cached()
+{
+	local delay=${1:-0}
+	local i
+
+	for ((i = 0; i < delay * 10; i++)); do
+		[ "$(cached_bytes)" -eq 0 ] && break
+		sleep 0.1
+	done
+	echo "$(cached_bytes) of $size bytes cached"
+}
+
+echo "plain write"
+$XFS_IO_PROG -f -c "pwrite -q 0 $size" -c fsync $file
+report_cached 1
+
+echo "dontcache write to a new file"
+rm -f $file
+$XFS_IO_PROG -f -c "pwrite -q -U -V 1 -b $size 0 $size" -c fsync $file
+report_cached 5
+
+# Start each of the remaining cases from an empty page cache.
+echo "dontcache overwrite"
+_scratch_cycle_mount
+$XFS_IO_PROG -c "pwrite -q -U -V 1 -b $size 0 $size" -c fsync $file
+report_cached 5
+
+echo "dontcache read"
+_scratch_cycle_mount
+$XFS_IO_PROG -c "pread -q -U -V 1 -b $size 0 $size" $file
+report_cached 5
+
+echo "plain read"
+_scratch_cycle_mount
+$XFS_IO_PROG -c "pread -q 0 $size" $file
+report_cached 1
+
+_scratch_unmount
+_exit 0
tests/generic/810.out new file +11 -0
new file mode 100644
index 00000000..cb6c3f2a
@@ -0,0 +1,11 @@
+QA output created by 810
+plain write
+1048576 of 1048576 bytes cached
+dontcache write to a new file
+0 of 1048576 bytes cached
+dontcache overwrite
+0 of 1048576 bytes cached
+dontcache read
+0 of 1048576 bytes cached
+plain read
+1048576 of 1048576 bytes cached
Signature · 2 lines
-- 
2.39.5
#6 lore raw

Re: [PATCH v2 3/3] generic/810: check that RWF_DONTCACHE I/O drops its folios

Quoted 5 lines · Brian Foster

I like it. Thanks for the tweaks!

Thanks, and thanks for the review! The end result looks cleaner.