fs: add FMODE_DIO_PARALLEL_WRITE flag
authorJens Axboe <axboe@kernel.dk>
Tue, 7 Mar 2023 16:40:28 +0000 (09:40 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 3 Apr 2023 13:14:20 +0000 (07:14 -0600)
Some filesystems support multiple threads writing to the same file with
O_DIRECT without requiring exclusive access to it. io_uring can use this
hint to avoid serializing dio writes to this inode, instead allowing them
to run in parallel.

XFS and ext4 both fall into this category, so set the flag for both of
them.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/ext4/file.c
fs/xfs/xfs_file.c
include/linux/fs.h

index 0b8b4499e5ca18a7f437015dce1d9d7071b064e7..d101b3b0c7dad8ade55a08328a09ec4e1a4f7496 100644 (file)
@@ -899,7 +899,8 @@ static int ext4_file_open(struct inode *inode, struct file *filp)
                        return ret;
        }
 
-       filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC;
+       filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC |
+                       FMODE_DIO_PARALLEL_WRITE;
        return dquot_file_open(inode, filp);
 }
 
index 705250f9f90a1b3d9fad16cf84df582145a21422..863289aaa4416569a54b23383eb060ea63abc600 100644 (file)
@@ -1171,7 +1171,8 @@ xfs_file_open(
 {
        if (xfs_is_shutdown(XFS_M(inode->i_sb)))
                return -EIO;
-       file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC | FMODE_BUF_WASYNC;
+       file->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC | FMODE_BUF_WASYNC |
+                       FMODE_DIO_PARALLEL_WRITE;
        return generic_file_open(inode, file);
 }
 
index c85916e9f7db500474d043c1f6a6b5e5c8d22020..475d88640d3d3e2e48f412a7a91bce98c53c67ec 100644 (file)
@@ -168,6 +168,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 
 #define        FMODE_NOREUSE           ((__force fmode_t)0x800000)
 
+/* File supports non-exclusive O_DIRECT writes from multiple threads */
+#define FMODE_DIO_PARALLEL_WRITE       ((__force fmode_t)0x1000000)
+
 /* File was opened by fanotify and shouldn't generate fanotify events */
 #define FMODE_NONOTIFY         ((__force fmode_t)0x4000000)