Skip to contentSkip to conversation

fsx: check pwritev2(,RWF_DONTCACHE)in test_dontcache_io as well

PATCH In review Chao Yu 2 participants 2 messages Aug 5, 2025

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 fsx: check pwritev2(,RWF_DONTCACHE)in test_dontcache_io as well

filesystem like XFS or ext4 has supported dontcache in both read&write side, so we can know whether filesystem can support dontcache by only checking w/ preadv2(,RWF_DONTCACHE).

However, filesystem can decide only support in read side or write side, not sure, all filesystems will support this feature in both read&write side later.

Let's add a check condition for write path as well.

---
 ltp/fsx.c | 43 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)
ltp/fsx.c +34 -9
index 163b9453..5ad178fa 100644
@@ -198,7 +198,8 @@ int	o_direct;			/* -Z */
 int	aio = 0;
 int	uring = 0;
 int	mark_nr = 0;
-int	dontcache_io = 1;
+int	read_dontcache_io = 1;
+int	write_dontcache_io = 1;
 int	hugepages = 0;                  /* -h flag */
 
 /* Stores info needed to periodically collapse hugepages */
@@ -1959,7 +1960,7 @@ do_preallocate(unsigned offset, unsigned length, int keep_size, int unshare)
 #endif
 
 int
-test_dontcache_io(void)
+test_read_dontcache_io(void)
 {
 	char buf[4096];
 	struct iovec iov = { .iov_base = buf, .iov_len = sizeof(buf) };
@@ -1971,7 +1972,27 @@ test_dontcache_io(void)
 		if (!quiet)
 			fprintf(stderr,
 				"main: filesystem does not support "
-				"dontcache IO, disabling!\n");
+				"read dontcache IO, disabling!\n");
+		return 0;
+	}
+
+	return 1;
+}
+
+int
+test_write_dontcache_io(void)
+{
+	char buf[4096];
+	struct iovec iov = { .iov_base = buf, .iov_len = sizeof(buf) };
+	int ret, e;
+
+	ret = pwritev2(fd, &iov, 1, 0, RWF_DONTCACHE);
+	e = ret < 0 ? errno : 0;
+	if (e == EOPNOTSUPP) {
+		if (!quiet)
+			fprintf(stderr,
+				"main: filesystem does not support "
+				"write dontcache IO, disabling!\n");
 		return 0;
 	}
 
@@ -2366,7 +2387,7 @@ have_op:
 
 	case OP_READ_DONTCACHE:
 		TRIM_OFF_LEN(offset, size, file_size);
-		if (dontcache_io)
+		if (read_dontcache_io)
 			doread(offset, size, RWF_DONTCACHE);
 		else
 			doread(offset, size, 0);
@@ -2379,7 +2400,7 @@ have_op:
 
 	case OP_WRITE_DONTCACHE:
 		TRIM_OFF_LEN(offset, size, maxfilelen);
-		if (dontcache_io)
+		if (write_dontcache_io)
 			dowrite(offset, size, RWF_DONTCACHE);
 		else
 			dowrite(offset, size, 0);
@@ -3250,7 +3271,8 @@ main(int argc, char **argv)
 				usage();
 			break;
 		case 'T':
-			dontcache_io = 0;
+			read_dontcache_io = 0;
+			write_dontcache_io = 0;
 			break;
 		case 'W':
 		        mapped_writes = 0;
@@ -3263,7 +3285,8 @@ main(int argc, char **argv)
 		case 'Z':
 			o_direct = O_DIRECT;
 			o_flags |= O_DIRECT;
-			dontcache_io = 0;
+			read_dontcache_io = 0;
+			write_dontcache_io = 0;
 			break;
 		case 254:  /* --duration */
 			if (!optarg) {
@@ -3473,8 +3496,10 @@ main(int argc, char **argv)
 		copy_range_calls = test_copy_range();
 	if (exchange_range_calls)
 		exchange_range_calls = test_exchange_range();
-	if (dontcache_io)
-		dontcache_io = test_dontcache_io();
+	if (read_dontcache_io)
+		read_dontcache_io = test_read_dontcache_io();
+	if (write_dontcache_io)
+		write_dontcache_io = test_write_dontcache_io();
 
 	while (keep_running())
 		if (!test())
Signature · 1 line
2.49.0
#1 lore raw
Quoted 9 lines · Chao Yu

filesystem like XFS or ext4 has supported dontcache in both read&write side, so we can know whether filesystem can support dontcache by only checking w/ preadv2(,RWF_DONTCACHE).

However, filesystem can decide only support in read side or write side, not sure, all filesystems will support this feature in both read&write side later.

Let's add a check condition for write path as well.

Once more:

https://lore.kernel.org/lkml/[email protected]/T/#t

Signature · 1 line
Jens Axboe