re-enable IOCB_NOWAIT writes to files v5
Subsystems (10)
Hi all,
commit 66fa3cedf16a ("fs: Add async write file modification handling.") effectively disabled IOCB_NOWAIT writes as timestamp updates currently always require blocking, and the modern timestamp resolution means we always update timestamps. This leads to a lot of context switches from applications using io_uring to submit file writes, making it often worse than using the legacy aio code that is not using IOCB_NOWAIT.
This series allows non-blocking updates for lazytime if the file system supports it, and adds that support for XFS.
Changes since v4:
- replace the S_* flags with an enum indicating either access or modification time updates to make the logic less fragile and to fix a bug in the previous version
Changes since v3:
- fix was_dirty_time handling in __mark_inode_dirty for the racy flag update case
- refactor inode_update_timestamps to make the lazytime vs blocking logical more clear
- allow non-blocking timestamp updates for fat
Changes since v2:
- drop patches merged upstream
- adjust for the inode state accesors
- keep a check in __writeback_single_inode instead of exercising potentially undefined behavior
- more spelling fixes
Changes since v1:
- more regular numbering of the S_* flags
- fix XFS to actually not block
- don't ignore the generic_update_time return value in file_update_time_flags
- fix the sync_lazytime return value
- fix an out of data comment in btrfs
- fix a race that would update i_version before returning -EAGAIN in XFS
Diffstat:
Documentation/filesystems/locking.rst | 2 Documentation/filesystems/vfs.rst | 6 + fs/btrfs/inode.c | 8 +- fs/fs-writeback.c | 33 +++++++--- fs/gfs2/inode.c | 6 + fs/inode.c | 111 +++++++++++++++++++++------------- fs/internal.h | 3 fs/nfs/inode.c | 4 - fs/orangefs/inode.c | 5 + fs/overlayfs/inode.c | 2 fs/sync.c | 4 - fs/ubifs/file.c | 13 ++- fs/xfs/xfs_iops.c | 34 +++++++++- fs/xfs/xfs_super.c | 29 -------- include/linux/fs.h | 27 ++++++-- include/trace/events/writeback.h | 6 - 16 files changed, 182 insertions(+), 111 deletions(-)
PATCH 1/11 fs: remove inode_update_time
The only external user is gone now, open code it in the two VFS callers.
--- fs/inode.c | 23 ++++++++--------------- include/linux/fs.h | 1 - 2 files changed, 8 insertions(+), 16 deletions(-)
fs/inode.c +8 -15
@@ -2157,19 +2157,6 @@ int generic_update_time(struct inode *inode, int flags) }EXPORT_SYMBOL (generic_update_time); -/* -* This does the actual work of updating an inodes time or version. Must have -* had called mnt_want_write() before calling this. -*/ -int inode_update_time (struct inode *inode,int flags) -{ -if (inode->i_op->update_time) -return inode->i_op->update_time (inode, flags); -generic_update_time (inode, flags); -return 0 ; -} -EXPORT_SYMBOL (inode_update_time); -/** * atime_needs_update - update the access time * @path: the &struct path to update
@@ -2237,7 +2224,10 @@ void touch_atime(const struct path *path)* We may also fail on filesystems that have the ability to make parts * of the fs read only, e.g. subvolumes in Btrfs. */ -inode_update_time (inode,S_ATIME ); +if (inode->i_op->update_time) + inode->i_op->update_time (inode,S_ATIME ); +else +generic_update_time (inode,S_ATIME );mnt_put_write_access (mnt); skip_update:sb_end_write (inode->i_sb);
@@ -2392,7 +2382,10 @@ static int file_update_time_flags(struct file *file, unsigned int flags)if (mnt_get_write_access_file (file))return 0 ; - ret =inode_update_time (inode, sync_mode); +if (inode->i_op->update_time) + ret = inode->i_op->update_time (inode, sync_mode); +else + ret =generic_update_time (inode, sync_mode);mnt_put_write_access_file (file);return ret; }
include/linux/fs.h +0 -1
@@ -2246,7 +2246,6 @@ enum file_time_flags {extern bool atime_needs_update (const struct path *,struct inode *);extern void touch_atime (const struct path *); -int inode_update_time (struct inode *inode,int flags);static inline void file_accessed (struct file *file) {
Signature · 1 line
2.47.3
PATCH 2/11 fs: allow error returns from generic_update_time
In reply to Christoph HellwigNow that no caller looks at the updated flags, switch generic_update_time to the same calling convention as the ->update_time method and return 0 or a negative errno.
This prepares for adding non-blocking timestamp updates that could return -EAGAIN.
--- fs/gfs2/inode.c | 3 +-- fs/inode.c | 4 ++-- fs/ubifs/file.c | 6 ++---- fs/xfs/xfs_iops.c | 6 ++---- include/linux/fs.h | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-)
fs/gfs2/inode.c +1 -2
@@ -2257,8 +2257,7 @@ static int gfs2_update_time(struct inode *inode, int flags)if (error)return error; } -generic_update_time (inode, flags); -return 0 ; +return generic_update_time (inode, flags); }static const struct inode_operations gfs2_file_iops = {
fs/inode.c +2 -2
@@ -2141,7 +2141,7 @@ EXPORT_SYMBOL(inode_update_timestamps);* or S_VERSION need to be updated we attempt to update all three of them. S_ATIME * updates can be handled done independently of the rest. * -* Returns a S_* mask indicating which fields were updated. +* Returns a negative error value on error, else 0. */ int generic_update_time (struct inode *inode,int flags) {
@@ -2153,7 +2153,7 @@ int generic_update_time(struct inode *inode, int flags)if (updated &S_VERSION ) dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags); -return updated; +return 0 ; }EXPORT_SYMBOL (generic_update_time);
fs/ubifs/file.c +2 -4
@@ -1379,10 +1379,8 @@ int ubifs_update_time(struct inode *inode, int flags) .dirtied_ino_d = ALIGN(ui->data_len, 8) };int err, release; -if (!IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) { -generic_update_time (inode, flags); -return 0 ; - } +if (!IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) +return generic_update_time (inode, flags); err =ubifs_budget_space (c, &req);if (err)
fs/xfs/xfs_iops.c +2 -4
@@ -1197,10 +1197,8 @@ xfs_vn_update_time(if (inode->i_sb->s_flags &SB_LAZYTIME ) {if (!((flags &S_VERSION ) && -inode_maybe_inc_iversion (inode, false))) { -generic_update_time (inode, flags); -return 0 ; - } +inode_maybe_inc_iversion (inode, false))) +return generic_update_time (inode, flags);/* Capture the iversion update that just occurred */ log_flags |=XFS_ILOG_CORE ;
include/linux/fs.h +1 -1
@@ -2399,7 +2399,7 @@ extern void ihold(struct inode * inode);extern void iput (struct inode *);void iput_not_last (struct inode *);int inode_update_timestamps (struct inode *inode,int flags); -int generic_update_time (struct inode *,int ); +int generic_update_time (struct inode *inode,int flags);/* /sys/fs */ extern struct kobject *fs_kobj;
Signature · 1 line
2.47.3
PATCH 3/11 nfs: split nfs_update_timestamps
In reply to Christoph HellwigThe VFS paths update either the atime or ctime and mtime but never mix between atime and the others. Split nfs_update_timestamps to match this to prepare for cleaning up the VFS interfaces.
--- fs/nfs/inode.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
fs/nfs/inode.c +15 -16
@@ -669,35 +669,31 @@ static void nfs_set_timestamps_to_ts(struct inode *inode, struct iattr *attr)NFS_I (inode)->cache_validity &= ~cache_flags; } -static void nfs_update_timestamps (struct inode *inode,unsigned int ia_valid) +static void nfs_update_atime (struct inode *inode) { -enum file_time_flags time_flags =0 ; -unsigned int cache_flags =0 ; +inode_update_timestamps (inode,S_ATIME ); +NFS_I (inode)->cache_validity &= ~NFS_INO_INVALID_ATIME ; +} -if (ia_valid &ATTR_MTIME ) { - time_flags |=S_MTIME |S_CTIME ; - cache_flags |=NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ; - } -if (ia_valid &ATTR_ATIME ) { - time_flags |=S_ATIME ; - cache_flags |=NFS_INO_INVALID_ATIME ; - } -inode_update_timestamps (inode, time_flags); -NFS_I (inode)->cache_validity &= ~cache_flags; +static void nfs_update_mtime (struct inode *inode) +{ +inode_update_timestamps (inode,S_MTIME |S_CTIME ); +NFS_I (inode)->cache_validity &= + ~(NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME ); }void nfs_update_delegated_atime (struct inode *inode) {spin_lock (&inode->i_lock);if (nfs_have_delegated_atime (inode)) -nfs_update_timestamps (inode,ATTR_ATIME ); +nfs_update_atime (inode);spin_unlock (&inode->i_lock); }void nfs_update_delegated_mtime_locked (struct inode *inode) {if (nfs_have_delegated_mtime (inode)) -nfs_update_timestamps (inode,ATTR_MTIME ); +nfs_update_mtime (inode); }void nfs_update_delegated_mtime (struct inode *inode)
@@ -747,7 +743,10 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, ATTR_ATIME|ATTR_ATIME_SET); } }else { -nfs_update_timestamps (inode, attr->ia_valid); +if (attr->ia_valid &ATTR_MTIME ) +nfs_update_mtime (inode); +if (attr->ia_valid &ATTR_ATIME ) +nfs_update_atime (inode); attr->ia_valid &= ~(ATTR_MTIME |ATTR_ATIME ); }spin_unlock (&inode->i_lock);
Signature · 1 line
2.47.3
PATCH 4/11 fat: cleanup the flags for fat_truncate_time
In reply to Christoph HellwigFat only has a single on-disk timestamp covering ctime and mtime. Add fat-specific flags that indicate which timestamp fat_truncate_time should update to make this more clear. This allows removing no-op fat_truncate_time calls with the S_CTIME flag and prepares for removing the S_* flags.
--- fs/fat/dir.c | 2 +- fs/fat/fat.h | 8 ++++---- fs/fat/file.c | 14 ++++++-------- fs/fat/inode.c | 2 +- fs/fat/misc.c | 39 ++++++++++++++++----------------------- fs/fat/namei_msdos.c | 13 +++++-------- fs/fat/namei_vfat.c | 9 ++++----- 7 files changed, 37 insertions(+), 50 deletions(-)
fs/fat/dir.c +1 -1
@@ -1080,7 +1080,7 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo) } } -fat_truncate_time (dir,NULL ,S_ATIME |S_MTIME ); +fat_truncate_time (dir,NULL ,FAT_UPDATE_ATIME |FAT_UPDATE_CMTIME );if (IS_DIRSYNC (dir)) (void )fat_sync_inode (dir);else
fs/fat/fat.h +4 -4
@@ -468,10 +468,10 @@ extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts, __le16 *time, __le16 *date, u8 *time_cs);extern struct timespec64 fat_truncate_atime (const struct msdos_sb_info *sbi,const struct timespec64 *ts); -extern struct timespec64 fat_truncate_mtime (const struct msdos_sb_info *sbi, -const struct timespec64 *ts); -extern int fat_truncate_time (struct inode *inode,struct timespec64 *now, -int flags); +#define FAT_UPDATE_ATIME (1u << 0) +#define FAT_UPDATE_CMTIME (1u << 1) +void fat_truncate_time (struct inode *inode,struct timespec64 *now, +unsigned int flags);extern int fat_update_time (struct inode *inode,int flags);extern int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs);
fs/fat/file.c +6 -8
@@ -224,7 +224,7 @@ static int fat_cont_expand(struct inode *inode, loff_t size)if (err) goto out; -fat_truncate_time (inode,NULL ,S_CTIME |S_MTIME ); +fat_truncate_time (inode,NULL ,FAT_UPDATE_CMTIME );mark_inode_dirty (inode);if (IS_SYNC (inode)) {int err2;
@@ -327,7 +327,7 @@ static int fat_free(struct inode *inode, int skip)MSDOS_I (inode)->i_logstart =0 ; }MSDOS_I (inode)->i_attrs |=ATTR_ARCH ; -fat_truncate_time (inode,NULL ,S_CTIME |S_MTIME ); +fat_truncate_time (inode,NULL ,FAT_UPDATE_CMTIME );if (wait) { err =fat_sync_inode (inode);if (err) {
@@ -553,15 +553,13 @@ int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry, }/* -* setattr_copy can't truncate these appropriately, so we'll -* copy them ourselves +* setattr_copy can't truncate these appropriately, so we'll copy them +* ourselves. See fat_truncate_time for the c/mtime logic on fat. */ if (attr->ia_valid &ATTR_ATIME ) -fat_truncate_time (inode, &attr->ia_atime,S_ATIME ); -if (attr->ia_valid &ATTR_CTIME ) -fat_truncate_time (inode, &attr->ia_ctime,S_CTIME ); +fat_truncate_time (inode, &attr->ia_atime,FAT_UPDATE_ATIME );if (attr->ia_valid &ATTR_MTIME ) -fat_truncate_time (inode, &attr->ia_mtime,S_MTIME ); +fat_truncate_time (inode, &attr->ia_mtime,FAT_UPDATE_CMTIME ); attr->ia_valid &= ~(ATTR_ATIME |ATTR_CTIME |ATTR_MTIME );setattr_copy (idmap, inode, attr);
fs/fat/inode.c +1 -1
@@ -246,7 +246,7 @@ static int fat_write_end(const struct kiocb *iocb,if (err < len)fat_write_failed (mapping, pos + len);if (!(err <0 ) && !(MSDOS_I (inode)->i_attrs &ATTR_ARCH )) { -fat_truncate_time (inode,NULL ,S_CTIME |S_MTIME ); +fat_truncate_time (inode,NULL ,FAT_UPDATE_CMTIME );MSDOS_I (inode)->i_attrs |=ATTR_ARCH ;mark_inode_dirty (inode); }
fs/fat/misc.c +16 -23
@@ -299,43 +299,36 @@ struct timespec64 fat_truncate_atime(const struct msdos_sb_info *sbi, }/* -* truncate mtime to 2 second granularity -*/ -struct timespec64 fat_truncate_mtime (const struct msdos_sb_info *sbi, -const struct timespec64 *ts) -{ -return fat_timespec64_trunc_2secs (*ts); -} - -/* -* truncate the various times with appropriate granularity: -* all times in root node are always 0 +* Update the in-inode atime and/or mtime after truncating the timestamp to the +* granularity. All timestamps in root inode are always 0. +* +* ctime and mtime share the same on-disk field, and should be identical in +* memory. All mtime updates will be applied to ctime, but ctime updates are +* ignored. */ -int fat_truncate_time (struct inode *inode,struct timespec64 *now,int flags) +void fat_truncate_time (struct inode *inode,struct timespec64 *now, +unsigned int flags) {struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb);struct timespec64 ts;if (inode->i_ino ==MSDOS_ROOT_INO ) -return 0 ; +return ;if (now ==NULL ) { now = &ts; ts =current_time (inode); } -if (flags &S_ATIME ) +if (flags &FAT_UPDATE_ATIME )inode_set_atime_to_ts (inode,fat_truncate_atime (sbi, now)); -/* -* ctime and mtime share the same on-disk field, and should be -* identical in memory. all mtime updates will be applied to ctime, -* but ctime updates are ignored. -*/ -if (flags &S_MTIME ) -inode_set_mtime_to_ts (inode, -inode_set_ctime_to_ts (inode,fat_truncate_mtime (sbi, now))); +if (flags &FAT_UPDATE_CMTIME ) { +/* truncate mtime to 2 second granularity */ +struct timespec64 mtime =fat_timespec64_trunc_2secs (*now); -return 0 ; +inode_set_mtime_to_ts (inode, mtime); +inode_set_ctime_to_ts (inode, mtime); + } }EXPORT_SYMBOL_GPL (fat_truncate_time);
fs/fat/namei_msdos.c +5 -8
@@ -251,7 +251,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,if (err)return err; -fat_truncate_time (dir, ts,S_CTIME |S_MTIME ); +fat_truncate_time (dir, ts,FAT_UPDATE_CMTIME );if (IS_DIRSYNC (dir)) (void )fat_sync_inode (dir);else
@@ -295,7 +295,7 @@ static int msdos_create(struct mnt_idmap *idmap, struct inode *dir, err =PTR_ERR (inode); goto out; } -fat_truncate_time (inode, &ts,S_ATIME |S_CTIME |S_MTIME ); +fat_truncate_time (inode, &ts,FAT_UPDATE_ATIME |FAT_UPDATE_CMTIME );/* timestamp is already written, so mark_inode_dirty() is unneeded. */ d_instantiate (dentry, inode);
@@ -328,7 +328,6 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry)drop_nlink (dir);clear_nlink (inode); -fat_truncate_time (inode,NULL ,S_CTIME );fat_detach (inode); out:mutex_unlock (&MSDOS_SB (sb)->s_lock);
@@ -382,7 +381,7 @@ static struct dentry *msdos_mkdir(struct mnt_idmap *idmap, struct inode *dir, goto out; }set_nlink (inode,2 ); -fat_truncate_time (inode, &ts,S_ATIME |S_CTIME |S_MTIME ); +fat_truncate_time (inode, &ts,FAT_UPDATE_ATIME |FAT_UPDATE_CMTIME );/* timestamp is already written, so mark_inode_dirty() is unneeded. */ d_instantiate (dentry, inode);
@@ -415,7 +414,6 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry)if (err) goto out;clear_nlink (inode); -fat_truncate_time (inode,NULL ,S_CTIME );fat_detach (inode); out:mutex_unlock (&MSDOS_SB (sb)->s_lock);
@@ -480,7 +478,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,mark_inode_dirty (old_inode);inode_inc_iversion (old_dir); -fat_truncate_time (old_dir,NULL ,S_CTIME |S_MTIME ); +fat_truncate_time (old_dir,NULL ,FAT_UPDATE_CMTIME );if (IS_DIRSYNC (old_dir)) (void )fat_sync_inode (old_dir);else
@@ -540,7 +538,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,if (err) goto error_dotdot;inode_inc_iversion (old_dir); -fat_truncate_time (old_dir, &ts,S_CTIME |S_MTIME ); +fat_truncate_time (old_dir, &ts,FAT_UPDATE_CMTIME );if (IS_DIRSYNC (old_dir)) (void )fat_sync_inode (old_dir);else
@@ -550,7 +548,6 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,drop_nlink (new_inode);if (is_dir)drop_nlink (new_inode); -fat_truncate_time (new_inode, &ts,S_CTIME ); } out:brelse (sinfo.bh);
fs/fat/namei_vfat.c +4 -5
@@ -676,7 +676,7 @@ static int vfat_add_entry(struct inode *dir, const struct qstr *qname, goto cleanup;/* update timestamp */ -fat_truncate_time (dir, ts,S_CTIME |S_MTIME ); +fat_truncate_time (dir, ts,FAT_UPDATE_CMTIME );if (IS_DIRSYNC (dir)) (void )fat_sync_inode (dir);else
@@ -806,7 +806,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry)drop_nlink (dir);clear_nlink (inode); -fat_truncate_time (inode,NULL ,S_ATIME |S_MTIME ); +fat_truncate_time (inode,NULL ,FAT_UPDATE_ATIME |FAT_UPDATE_CMTIME );fat_detach (inode);vfat_d_version_set (dentry,inode_query_iversion (dir)); out:
@@ -832,7 +832,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)if (err) goto out;clear_nlink (inode); -fat_truncate_time (inode,NULL ,S_ATIME |S_MTIME ); +fat_truncate_time (inode,NULL ,FAT_UPDATE_ATIME |FAT_UPDATE_CMTIME );fat_detach (inode);vfat_d_version_set (dentry,inode_query_iversion (dir)); out:
@@ -918,7 +918,7 @@ static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode,static void vfat_update_dir_metadata (struct inode *dir,struct timespec64 *ts) {inode_inc_iversion (dir); -fat_truncate_time (dir, ts,S_CTIME |S_MTIME ); +fat_truncate_time (dir, ts,FAT_UPDATE_CMTIME );if (IS_DIRSYNC (dir)) (void )fat_sync_inode (dir);else
@@ -996,7 +996,6 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,drop_nlink (new_inode);if (is_dir)drop_nlink (new_inode); -fat_truncate_time (new_inode, &ts,S_CTIME ); } out:brelse (sinfo.bh);
Signature · 1 line
2.47.3
Sorry, sending this got interrupted by the broken train wifi. Please look at the immediately following full series instead.