generic/728: Add mmap + DIO write test
PATCH 1/1 generic/728: Add mmap + DIO write test
This is the same as generic/647, but with an additional test that writes a memory-mapped page onto itself using direct I/O.
For direct I/O writes, the kernel will invalidate the page cache before and after carrying out the write. This puts filesystems that fault in pages on demand and then carry out the write with page faults disabled into a position in which they will not be able to make any progress.
--- src/mmap-rw-fault.c | 33 ++++++++++++++++++++++++++++++--- tests/generic/728 | 41 +++++++++++++++++++++++++++++++++++++++++ tests/generic/728.out | 2 ++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100755 tests/generic/728 create mode 100644 tests/generic/728.out
src/mmap-rw-fault.c +30 -3
@@ -20,6 +20,7 @@#include <string.h> #include <errno.h> #include <err.h> +#include <getopt.h> char *filename;unsigned int page_size;
@@ -109,11 +110,29 @@ static ssize_t do_write(int fd, const void *buf, size_t count, off_t offset)return count2; } +static void usage (const char *argv0) +{ +fprintf (stderr,"Usage: %s [-2] {filename}\n" , argv0); +exit (2 ); +} +int main (int argc,char *argv[]) { -if (argc !=2 ) -errx (1 ,"no test filename argument given" ); - filename = argv[1 ]; +int opt, opt_2 =0 ; + +while ((opt =getopt (argc, argv,"2" )) !=-1 ) { +switch (opt) { +case '2' : + opt_2 =1 ; +break ; +default : +usage (argv[0 ]); + } + } + +if (optind +1 != argc) +usage (argv[0 ]); + filename = argv[optind]; page_size = ret =sysconf (_SC_PAGE_SIZE);if (ret ==-1 )
@@ -179,6 +198,14 @@ int main(int argc, char *argv[])errx (1 ,"pread (D_DIRECT) from hole is broken" );done (); +if (opt_2) { +init ('f' ,O_RDWR |O_DIRECT ); + ret =do_write (fd, addr + page_size, page_size, page_size); +if (ret != page_size) +err (1 ,"pwrite %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +done (); + } +if (unlink (filename))err (1 ,"unlink %s" , filename);
tests/generic/728 new file +41 -0
41 lines not on this page · raw message
tests/generic/728.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 728 +Silence is golden
Signature · 1 line
2.40.0
Quoted 84 lines · Andreas Gruenbacher
This is the same as generic/647, but with an additional test that writes a memory-mapped page onto itself using direct I/O.
For direct I/O writes, the kernel will invalidate the page cache before and after carrying out the write. This puts filesystems that fault in pages on demand and then carry out the write with page faults disabled into a position in which they will not be able to make any progress.
--- src/mmap-rw-fault.c | 33 ++++++++++++++++++++++++++++++--- tests/generic/728 | 41 +++++++++++++++++++++++++++++++++++++++++ tests/generic/728.out | 2 ++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100755 tests/generic/728 create mode 100644 tests/generic/728.outsrc/mmap-rw-fault.c +30
-3@@ -20,6 +20,7 @@#include <string.h> #include <errno.h> #include <err.h> +#include <getopt.h> char *filename;unsigned int page_size;@@ -109,11 +110,29 @@ static ssize_t do_write(int fd, const void *buf, size_t count, off_t offset)return count2; } +static void usage (const char *argv0) +{ +fprintf (stderr,"Usage: %s [-2] {filename}\n" , argv0); +exit (2 ); +} +int main (int argc,char *argv[]) { -if (argc !=2 ) -errx (1 ,"no test filename argument given" ); - filename = argv[1 ]; +int opt, opt_2 =0 ; + +while ((opt =getopt (argc, argv,"2" )) !=-1 ) { +switch (opt) { +case '2' : + opt_2 =1 ; +break ; +default : +usage (argv[0 ]); + } + } + +if (optind +1 != argc) +usage (argv[0 ]); + filename = argv[optind]; page_size = ret =sysconf (_SC_PAGE_SIZE);if (ret ==-1 )@@ -179,6 +198,14 @@ int main(int argc, char *argv[])errx (1 ,"pread (D_DIRECT) from hole is broken" );done (); +if (opt_2) { +init ('f' ,O_RDWR |O_DIRECT ); + ret =do_write (fd, addr + page_size, page_size, page_size); +if (ret != page_size) +err (1 ,"pwrite %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +done (); + } +if (unlink (filename))err (1 ,"unlink %s" , filename);tests/generic/728 new file +3
-0@@ -0,0 +1,41 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 Red Hat, Inc. All Rights Reserved.
tests/generic/728 line 13
Quoted 10 lines
tests/generic/728 new file +10
-0+# +# FS QA Test 728 +# +# Trigger page faults in the same file during read and write +# +# This is generic/647 with an additional test that writes a memory-mapped page +# onto itself using direct I/O. +# +# The kernel will invalidate the page cache +# before carrying out the write, so filesystems that fault in the target page before carrying out the direct I/O write will never make any progress.
Oddly linewrapped...
How many filesystems stall when running this? ext4/btrfs/xfs didn't when I tried.
--D
Quoted 39 lines
tests/generic/728 new file +28
-0+# +. ./common/preamble +_begin_fstest auto quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -f $tmp.* + rm -f $TEST_DIR/mmap-rw-fault.tmp +} + +# Import common functions. +. ./common/filter + +# real QA test starts here + +_supported_fs generic +_require_test +_require_odirect +_require_test_program mmap-rw-fault + +echo "Silence is golden" + +$here/src/mmap-rw-fault -2 $TEST_DIR/mmap-rw-fault.tmp + +status=$? +exittests/generic/728.out new file +2
-0@@ -0,0 +1,2 @@ +QA output created by 728 +Silence is goldenSignature · 1 line
2.40.0
Quoted 89 lines · Darrick J. Wong
Quoted 88 lines · Andreas Gruenbacher
This is the same as generic/647, but with an additional test that writes a memory-mapped page onto itself using direct I/O.
For direct I/O writes, the kernel will invalidate the page cache before and after carrying out the write. This puts filesystems that fault in pages on demand and then carry out the write with page faults disabled into a position in which they will not be able to make any progress.
--- src/mmap-rw-fault.c | 33 ++++++++++++++++++++++++++++++--- tests/generic/728 | 41 +++++++++++++++++++++++++++++++++++++++++ tests/generic/728.out | 2 ++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100755 tests/generic/728 create mode 100644 tests/generic/728.outsrc/mmap-rw-fault.c +30
-3@@ -20,6 +20,7 @@#include <string.h> #include <errno.h> #include <err.h> +#include <getopt.h> char *filename;unsigned int page_size;@@ -109,11 +110,29 @@ static ssize_t do_write(int fd, const void *buf, size_t count, off_t offset)return count2; } +static void usage (const char *argv0) +{ +fprintf (stderr,"Usage: %s [-2] {filename}\n" , argv0); +exit (2 ); +} +int main (int argc,char *argv[]) { -if (argc !=2 ) -errx (1 ,"no test filename argument given" ); - filename = argv[1 ]; +int opt, opt_2 =0 ; + +while ((opt =getopt (argc, argv,"2" )) !=-1 ) { +switch (opt) { +case '2' : + opt_2 =1 ; +break ; +default : +usage (argv[0 ]); + } + } + +if (optind +1 != argc) +usage (argv[0 ]); + filename = argv[optind]; page_size = ret =sysconf (_SC_PAGE_SIZE);if (ret ==-1 )@@ -179,6 +198,14 @@ int main(int argc, char *argv[])errx (1 ,"pread (D_DIRECT) from hole is broken" );done (); +if (opt_2) { +init ('f' ,O_RDWR |O_DIRECT ); + ret =do_write (fd, addr + page_size, page_size, page_size); +if (ret != page_size) +err (1 ,"pwrite %s (O_DIRECT): %ld != %u" , filename, ret, page_size); +done (); + } +if (unlink (filename))err (1 ,"unlink %s" , filename);tests/generic/728 new file +7
-0@@ -0,0 +1,41 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test 728 +# +# Trigger page faults in the same file during read and write
Quoted 8 lines
tests/generic/728 line 13
Quoted 6 lines
tests/generic/728 new file +6
-0+# +# This is generic/647 with an additional test that writes a memory-mapped page +# onto itself using direct I/O. +# +# The kernel will invalidate the page cache +# before carrying out the write, so filesystems that fault in the target page before carrying out the direct I/O write will never make any progress.Oddly linewrapped...
Oops, I'll repost.
Quoted 2 lines
How many filesystems stall when running this? ext4/btrfs/xfs didn't when I tried.
gfs2 got this wrong. btrfs also has page faults disabled during direct writes, but it already fell back to buffered writes when it didn't make progress (as does gfs2 now).
Thanks,
Andreas
Quoted 42 lines
--D
Quoted 39 lines
tests/generic/728 new file +28
-0+# +. ./common/preamble +_begin_fstest auto quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -f $tmp.* + rm -f $TEST_DIR/mmap-rw-fault.tmp +} + +# Import common functions. +. ./common/filter + +# real QA test starts here + +_supported_fs generic +_require_test +_require_odirect +_require_test_program mmap-rw-fault + +echo "Silence is golden" + +$here/src/mmap-rw-fault -2 $TEST_DIR/mmap-rw-fault.tmp + +status=$? +exittests/generic/728.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 728 +Silence is golden --2.40.0