iocb: delay evaluation of IS_SYNC(...) until we want to check IOCB_DSYNC
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 22 May 2022 13:39:27 +0000 (09:39 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 10 Jun 2022 20:05:15 +0000 (16:05 -0400)
New helper to be used instead of direct checks for IOCB_DSYNC:
iocb_is_dsync(iocb).  Checks converted, which allows to avoid
the IS_SYNC(iocb->ki_filp->f_mapping->host) part (4 cache lines)
from iocb_flags() - it's checked in iocb_is_dsync() instead

Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
block/fops.c
fs/btrfs/file.c
fs/direct-io.c
fs/fuse/file.c
fs/iomap/direct-io.c
fs/zonefs/super.c
include/linux/fs.h

index d6b3276a6c68088e470790d0fe767b325c4a4cfd..6e86931ab8475273afc47440793ed74f7d2c5771 100644 (file)
@@ -37,7 +37,7 @@ static unsigned int dio_bio_write_op(struct kiocb *iocb)
        unsigned int op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
 
        /* avoid the need for a I/O completion work item */
-       if (iocb->ki_flags & IOCB_DSYNC)
+       if (iocb_is_dsync(iocb))
                op |= REQ_FUA;
        return op;
 }
index 98f81e304eb1d427e19350e45ec6c5951aa38dc3..54358a5c9d56854839b880153cb2dedff0287f9f 100644 (file)
@@ -2021,7 +2021,7 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,
        struct file *file = iocb->ki_filp;
        struct btrfs_inode *inode = BTRFS_I(file_inode(file));
        ssize_t num_written, num_sync;
-       const bool sync = iocb->ki_flags & IOCB_DSYNC;
+       const bool sync = iocb_is_dsync(iocb);
 
        /*
         * If the fs flips readonly due to some impossible error, although we
index 840752006f601aab0c23924425da77ea0e8ae39f..39647eb56904f2f5635740659ba134dfc58ecb52 100644 (file)
@@ -1210,7 +1210,7 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
         */
        if (dio->is_async && iov_iter_rw(iter) == WRITE) {
                retval = 0;
-               if (iocb->ki_flags & IOCB_DSYNC)
+               if (iocb_is_dsync(iocb))
                        retval = dio_set_defer_completion(dio);
                else if (!dio->inode->i_sb->s_dio_done_wq) {
                        /*
index 05caa2b9272e80be0c81898788a7fa3bcbaf0520..00fa861aeeadbc3f1bf0eea18c170aef5b5f9a4c 100644 (file)
@@ -1042,7 +1042,7 @@ static unsigned int fuse_write_flags(struct kiocb *iocb)
 {
        unsigned int flags = iocb->ki_filp->f_flags;
 
-       if (iocb->ki_flags & IOCB_DSYNC)
+       if (iocb_is_dsync(iocb))
                flags |= O_DSYNC;
        if (iocb->ki_flags & IOCB_SYNC)
                flags |= O_SYNC;
index c10c69e2de240cf70b74994983e67b51fa99e2eb..31c7f1035b20b92e9fb9501e55dd82a99c359880 100644 (file)
@@ -548,8 +548,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
                }
 
                /* for data sync or sync, we need sync completion processing */
-               if (iocb->ki_flags & IOCB_DSYNC &&
-                   !(dio_flags & IOMAP_DIO_NOSYNC)) {
+               if (iocb_is_dsync(iocb) && !(dio_flags & IOMAP_DIO_NOSYNC)) {
                        dio->flags |= IOMAP_DIO_NEED_SYNC;
 
                       /*
index bcb21aea990aeb98ce3695139762110af5fe3a88..04a98b4cd7ee6e2fe4eee10f887a65ac72d6a49a 100644 (file)
@@ -746,7 +746,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
                        REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE, GFP_NOFS);
        bio->bi_iter.bi_sector = zi->i_zsector;
        bio->bi_ioprio = iocb->ki_ioprio;
-       if (iocb->ki_flags & IOCB_DSYNC)
+       if (iocb_is_dsync(iocb))
                bio->bi_opf |= REQ_FUA;
 
        ret = bio_iov_iter_get_pages(bio, from);
index 6a2a4906041fda0885a7b7d179517a8e4ff5fe13..380a1292f4f9a2bc35cfe2553aa30014e8659b00 100644 (file)
@@ -2720,6 +2720,12 @@ extern int vfs_fsync(struct file *file, int datasync);
 extern int sync_file_range(struct file *file, loff_t offset, loff_t nbytes,
                                unsigned int flags);
 
+static inline bool iocb_is_dsync(const struct kiocb *iocb)
+{
+       return (iocb->ki_flags & IOCB_DSYNC) ||
+               IS_SYNC(iocb->ki_filp->f_mapping->host);
+}
+
 /*
  * Sync the bytes written if this was a synchronous write.  Expect ki_pos
  * to already be updated for the write, and will return either the amount
@@ -2727,7 +2733,7 @@ extern int sync_file_range(struct file *file, loff_t offset, loff_t nbytes,
  */
 static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count)
 {
-       if (iocb->ki_flags & IOCB_DSYNC) {
+       if (iocb_is_dsync(iocb)) {
                int ret = vfs_fsync_range(iocb->ki_filp,
                                iocb->ki_pos - count, iocb->ki_pos - 1,
                                (iocb->ki_flags & IOCB_SYNC) ? 0 : 1);
@@ -3262,7 +3268,7 @@ static inline int iocb_flags(struct file *file)
                res |= IOCB_APPEND;
        if (file->f_flags & O_DIRECT)
                res |= IOCB_DIRECT;
-       if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host))
+       if (file->f_flags & O_DSYNC)
                res |= IOCB_DSYNC;
        if (file->f_flags & __O_SYNC)
                res |= IOCB_SYNC;