Skip to contentSkip to conversation

fstests: generic: add a basic cachestat test case

PATCH In review Qu Wenruo 2 participants 2 messages Jul 15 – Jul 16 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 fstests: generic: add a basic cachestat test case

The test case is inspired by LTP, where there is a regression on 64K page size systems with btrfs, that after a fsync, cachestat() still report dirty pages.

The test case itself is pretty simple, fill the file with a buffered write that is 1/2/4/8/16 page sized, call cachestat() to make sure the cached/dirtied number match the page number.

Then do a fsync(), and make sure the dirty page number reduced to 0 meanwhile cached is still the same.

---
Changelog:
v3:
- Use golden output to greatly simplify the test case

- Do not mkfs for each size, just remove the original file

v2:
- Reject "sync" and "dax" mount options
Those mount options write back data synchronously, will screw up the buffered write dirtied page reporting.

- Use AWK_PROG everywhere.

- Remove the unnecessary redirection for fsync

---
 tests/generic/798     | 39 +++++++++++++++++++++++++++++++++++++++
 tests/generic/798.out | 16 ++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100755 tests/generic/798
 create mode 100644 tests/generic/798.out
tests/generic/798 new file +39 -0
new file mode 100755
index 00000000..0fe37646
@@ -0,0 +1,39 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 798
+#
+# Basic tests for cachestat()
+#
+. ./common/preamble
+_begin_fstest auto quick
+
+_require_xfs_io_command "cachestat"
+_require_scratch
+# Any mount option that writes data back synchronously should be rejected.
+# Or it will screw up the dirtied page reporting for buffered writes.
+_exclude_scratch_mount_option "dax"
+_exclude_scratch_mount_option "sync"
+
+pagesize=$(_get_page_size)
+
+_scratch_mkfs > /dev/null
+_scratch_mount
+
+for num_page in 1 2 4 8 16; do
+	size=$(($pagesize * $num_page))
+
+	echo "=== Test with $num_page pages ==="
+
+	rm -f $SCRATCH_MNT/foobar
+	$XFS_IO_PROG -f -c "pwrite -b $pagesize 0 $size" $SCRATCH_MNT/foobar > /dev/null
+	# Basic cached number reporting
+	$XFS_IO_PROG -c "cachestat 0 $size" $SCRATCH_MNT/foobar
+
+	# Test dirty page number reporting after a fsync.
+	$XFS_IO_PROG -c "fsync" -c "cachestat 0 $size" $SCRATCH_MNT/foobar
+done
+
+_scratch_unmount
+_exit 0
tests/generic/798.out new file +16 -0
new file mode 100644
index 00000000..ca6ead3c
@@ -0,0 +1,16 @@
+QA output created by 798
+=== Test with 1 pages ===
+Cached: 1, Dirty: 1, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 1, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 2 pages ===
+Cached: 2, Dirty: 2, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 2, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 4 pages ===
+Cached: 4, Dirty: 4, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 4, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 8 pages ===
+Cached: 8, Dirty: 8, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 8, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 16 pages ===
+Cached: 16, Dirty: 16, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 16, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
Signature · 1 line
2.51.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Qu Wenruo

The test case is inspired by LTP, where there is a regression on 64K page size systems with btrfs, that after a fsync, cachestat() still report dirty pages.

The test case itself is pretty simple, fill the file with a buffered write that is 1/2/4/8/16 page sized, call cachestat() to make sure the cached/dirtied number match the page number.

Then do a fsync(), and make sure the dirty page number reduced to 0 meanwhile cached is still the same.

---
Changelog:
v3:
- Use golden output to greatly simplify the test case

- Do not mkfs for each size, just remove the original file

v2:
- Reject "sync" and "dax" mount options
Those mount options write back data synchronously, will screw up the buffered write dirtied page reporting.

Quoted 4 lines

- Use AWK_PROG everywhere.

- Remove the unnecessary redirection for fsync
---

Nice. Thanks for the tweaks!

Quoted 76 lines
 tests/generic/798     | 39 +++++++++++++++++++++++++++++++++++++++
 tests/generic/798.out | 16 ++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100755 tests/generic/798
 create mode 100644 tests/generic/798.out
tests/generic/798 new file +39 -0
new file mode 100755
index 00000000..0fe37646
@@ -0,0 +1,39 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 SUSE S.A.  All Rights Reserved.
+#
+# FS QA Test 798
+#
+# Basic tests for cachestat()
+#
+. ./common/preamble
+_begin_fstest auto quick
+
+_require_xfs_io_command "cachestat"
+_require_scratch
+# Any mount option that writes data back synchronously should be rejected.
+# Or it will screw up the dirtied page reporting for buffered writes.
+_exclude_scratch_mount_option "dax"
+_exclude_scratch_mount_option "sync"
+
+pagesize=$(_get_page_size)
+
+_scratch_mkfs > /dev/null
+_scratch_mount
+
+for num_page in 1 2 4 8 16; do
+	size=$(($pagesize * $num_page))
+
+	echo "=== Test with $num_page pages ==="
+
+	rm -f $SCRATCH_MNT/foobar
+	$XFS_IO_PROG -f -c "pwrite -b $pagesize 0 $size" $SCRATCH_MNT/foobar > /dev/null
+	# Basic cached number reporting
+	$XFS_IO_PROG -c "cachestat 0 $size" $SCRATCH_MNT/foobar
+
+	# Test dirty page number reporting after a fsync.
+	$XFS_IO_PROG -c "fsync" -c "cachestat 0 $size" $SCRATCH_MNT/foobar
+done
+
+_scratch_unmount
+_exit 0
tests/generic/798.out new file +16 -0
new file mode 100644
index 00000000..ca6ead3c
@@ -0,0 +1,16 @@
+QA output created by 798
+=== Test with 1 pages ===
+Cached: 1, Dirty: 1, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 1, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 2 pages ===
+Cached: 2, Dirty: 2, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 2, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 4 pages ===
+Cached: 4, Dirty: 4, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 4, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 8 pages ===
+Cached: 8, Dirty: 8, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 8, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
+=== Test with 16 pages ===
+Cached: 16, Dirty: 16, Writeback: 0, Evicted: 0, Recently Evicted: 0
+Cached: 16, Dirty: 0, Writeback: 0, Evicted: 0, Recently Evicted: 0
Signature · 1 line
2.51.2