Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iocb: delay evaluation of IS_SYNC(...) until we want to check IOCB_DSYNC

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>

Al Viro 91b94c5d e87f2c26

+14 -9
+1 -1
block/fops.c
··· 37 37 unsigned int op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE; 38 38 39 39 /* avoid the need for a I/O completion work item */ 40 - if (iocb->ki_flags & IOCB_DSYNC) 40 + if (iocb_is_dsync(iocb)) 41 41 op |= REQ_FUA; 42 42 return op; 43 43 }
+1 -1
fs/btrfs/file.c
··· 2021 2021 struct file *file = iocb->ki_filp; 2022 2022 struct btrfs_inode *inode = BTRFS_I(file_inode(file)); 2023 2023 ssize_t num_written, num_sync; 2024 - const bool sync = iocb->ki_flags & IOCB_DSYNC; 2024 + const bool sync = iocb_is_dsync(iocb); 2025 2025 2026 2026 /* 2027 2027 * If the fs flips readonly due to some impossible error, although we
+1 -1
fs/direct-io.c
··· 1210 1210 */ 1211 1211 if (dio->is_async && iov_iter_rw(iter) == WRITE) { 1212 1212 retval = 0; 1213 - if (iocb->ki_flags & IOCB_DSYNC) 1213 + if (iocb_is_dsync(iocb)) 1214 1214 retval = dio_set_defer_completion(dio); 1215 1215 else if (!dio->inode->i_sb->s_dio_done_wq) { 1216 1216 /*
+1 -1
fs/fuse/file.c
··· 1042 1042 { 1043 1043 unsigned int flags = iocb->ki_filp->f_flags; 1044 1044 1045 - if (iocb->ki_flags & IOCB_DSYNC) 1045 + if (iocb_is_dsync(iocb)) 1046 1046 flags |= O_DSYNC; 1047 1047 if (iocb->ki_flags & IOCB_SYNC) 1048 1048 flags |= O_SYNC;
+1 -2
fs/iomap/direct-io.c
··· 548 548 } 549 549 550 550 /* for data sync or sync, we need sync completion processing */ 551 - if (iocb->ki_flags & IOCB_DSYNC && 552 - !(dio_flags & IOMAP_DIO_NOSYNC)) { 551 + if (iocb_is_dsync(iocb) && !(dio_flags & IOMAP_DIO_NOSYNC)) { 553 552 dio->flags |= IOMAP_DIO_NEED_SYNC; 554 553 555 554 /*
+1 -1
fs/zonefs/super.c
··· 746 746 REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE, GFP_NOFS); 747 747 bio->bi_iter.bi_sector = zi->i_zsector; 748 748 bio->bi_ioprio = iocb->ki_ioprio; 749 - if (iocb->ki_flags & IOCB_DSYNC) 749 + if (iocb_is_dsync(iocb)) 750 750 bio->bi_opf |= REQ_FUA; 751 751 752 752 ret = bio_iov_iter_get_pages(bio, from);
+8 -2
include/linux/fs.h
··· 2720 2720 extern int sync_file_range(struct file *file, loff_t offset, loff_t nbytes, 2721 2721 unsigned int flags); 2722 2722 2723 + static inline bool iocb_is_dsync(const struct kiocb *iocb) 2724 + { 2725 + return (iocb->ki_flags & IOCB_DSYNC) || 2726 + IS_SYNC(iocb->ki_filp->f_mapping->host); 2727 + } 2728 + 2723 2729 /* 2724 2730 * Sync the bytes written if this was a synchronous write. Expect ki_pos 2725 2731 * to already be updated for the write, and will return either the amount ··· 2733 2727 */ 2734 2728 static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count) 2735 2729 { 2736 - if (iocb->ki_flags & IOCB_DSYNC) { 2730 + if (iocb_is_dsync(iocb)) { 2737 2731 int ret = vfs_fsync_range(iocb->ki_filp, 2738 2732 iocb->ki_pos - count, iocb->ki_pos - 1, 2739 2733 (iocb->ki_flags & IOCB_SYNC) ? 0 : 1); ··· 3268 3262 res |= IOCB_APPEND; 3269 3263 if (file->f_flags & O_DIRECT) 3270 3264 res |= IOCB_DIRECT; 3271 - if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host)) 3265 + if (file->f_flags & O_DSYNC) 3272 3266 res |= IOCB_DSYNC; 3273 3267 if (file->f_flags & __O_SYNC) 3274 3268 res |= IOCB_SYNC;