fs: implement multigrain timestamps
Subsystems (34)
Jeff Layton
maintainerv7 cover fs: implement multigrain timestamps
The VFS always uses coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes.
Unfortunately, this coarseness has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide to invalidate the cache.
Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problems with timestamp granularity. Other applications have similar issues with timestamps (e.g backup applications).
If we were to always use fine-grained timestamps, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates.
What we need is a way to only use fine-grained timestamps when they are being actively queried. The idea is to use an unused bit in the ctime's tv_nsec field to mark when the mtime or ctime has been queried via getattr. Once that has been marked, the next m/ctime update will use a fine-grained timestamp.
Credit goes to Dave Chinner for the original idea, and to Ben Coddington for the catchy name. This series should apply cleanly onto Christian's vfs.ctime branch, once the v6 mgtime patches have been dropped. That should be everything above this commit:
525deaeb2fbf gfs2: fix timestamp handling on quota inodes
base-commit: cf22d118b89a09a0160586412160d89098f7c4c7
---
Changes in v7:
- change update_time operation to fetch the current time itself
- don't modify current_time operation. Leave it always returning coarse timestamp
- rework inode_set_ctime_current for better atomicity and ensure that all mgtime filesystems use it
- reorder arguments to fill_mg_cmtime
Changes in v6:
- drop the patch that removed XFS_ICHGTIME_CHG
- change WARN_ON_ONCE to ASSERT in xfs conversion patch
---
Jeff Layton (13):
fs: remove silly warning from current_time
fs: pass the request_mask to generic_fillattr
fs: drop the timespec64 arg from generic_update_time
btrfs: have it use inode_update_timestamps
fat: make fat_update_time get its own timestamp
ubifs: have ubifs_update_time use inode_update_timestamps
xfs: have xfs_vn_update_time gets its own timestamp
fs: drop the timespec64 argument from update_time
fs: add infrastructure for multigrain timestamps
tmpfs: add support for multigrain timestamps
xfs: switch to multigrain timestamps
ext4: switch to multigrain timestamps
btrfs: convert to multigrain timestamps
fs/9p/vfs_inode.c | 4 +- fs/9p/vfs_inode_dotl.c | 4 +- fs/afs/inode.c | 2 +- fs/bad_inode.c | 3 +- fs/btrfs/file.c | 24 +---- fs/btrfs/inode.c | 14 +-- fs/btrfs/super.c | 5 +- fs/btrfs/volumes.c | 4 +- fs/ceph/inode.c | 2 +- fs/coda/inode.c | 3 +- fs/ecryptfs/inode.c | 5 +- fs/erofs/inode.c | 2 +- fs/exfat/file.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/ext4/super.c | 2 +- fs/f2fs/file.c | 2 +- fs/fat/fat.h | 3 +- fs/fat/file.c | 2 +- fs/fat/misc.c | 6 +- fs/fuse/dir.c | 2 +- fs/gfs2/inode.c | 8 +- fs/hfsplus/inode.c | 2 +- fs/inode.c | 200 +++++++++++++++++++++++++++++++--------- fs/kernfs/inode.c | 2 +- fs/libfs.c | 4 +- fs/minix/inode.c | 2 +- fs/nfs/inode.c | 2 +- fs/nfs/namespace.c | 3 +- fs/ntfs3/file.c | 2 +- fs/ocfs2/file.c | 2 +- fs/orangefs/inode.c | 5 +- fs/overlayfs/inode.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/proc/base.c | 4 +- fs/proc/fd.c | 2 +- fs/proc/generic.c | 2 +- fs/proc/proc_net.c | 2 +- fs/proc/proc_sysctl.c | 2 +- fs/proc/root.c | 3 +- fs/smb/client/inode.c | 2 +- fs/smb/server/smb2pdu.c | 22 ++--- fs/smb/server/vfs.c | 3 +- fs/stat.c | 65 ++++++++++--- fs/sysv/itree.c | 3 +- fs/ubifs/dir.c | 2 +- fs/ubifs/file.c | 19 ++-- fs/ubifs/ubifs.h | 2 +- fs/udf/symlink.c | 2 +- fs/vboxsf/utils.c | 2 +- fs/xfs/libxfs/xfs_trans_inode.c | 6 +- fs/xfs/xfs_iops.c | 25 +++-- fs/xfs/xfs_super.c | 2 +- include/linux/fs.h | 55 +++++++++-- mm/shmem.c | 4 +- 55 files changed, 368 insertions(+), 192 deletions(-)
---
base-commit: 525deaeb2fbf634222f4231608c72190c551c935
change-id: 20230713-mgctime-f2a9fc324918
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v7 1/13 fs: remove silly warning from current_time
An inode with no superblock? Unpossible!
--- fs/inode.c | 6 ------ 1 file changed, 6 deletions(-)
fs/inode.c +0 -6
@@ -2495,12 +2495,6 @@ struct timespec64 current_time(struct inode *inode)struct timespec64 now;ktime_get_coarse_real_ts64 (&now); - -if (unlikely (!inode->i_sb)) { -WARN (1 ,"current_time() called with uninitialized super_block in the inode" ); -return now; - } -return timestamp_truncate (now, inode); }EXPORT_SYMBOL (current_time);
Signature · 1 line
2.41.0
Re: [PATCH v7 01/13] fs: remove silly warning from current_time
Quoted 3 lines · Jeff Layton
An inode with no superblock? Unpossible!
Signed-off-by Jeff Layton <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 25 lines
--- fs/inode.c | 6 ------ 1 file changed, 6 deletions(-)fs/inode.c +0
-6@@ -2495,12 +2495,6 @@ struct timespec64 current_time(struct inode *inode)struct timespec64 now;ktime_get_coarse_real_ts64 (&now); - -if (unlikely (!inode->i_sb)) { -WARN (1 ,"current_time() called with uninitialized super_block in the inode" ); -return now; - } -return timestamp_truncate (now, inode); }EXPORT_SYMBOL (current_time);Signature · 2 lines
-- 2.41.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerPATCH v7 2/13 fs: pass the request_mask to generic_fillattr
In reply to Jeff Laytongeneric_fillattr just fills in the entire stat struct indiscriminately today, copying data from the inode. There is at least one attribute (STATX_CHANGE_COOKIE) that can have side effects when it is reported, and we're looking at adding more with the addition of multigrain timestamps.
Add a request_mask argument to generic_fillattr and have most callers just pass in the value that is passed to getattr. Have other callers (e.g. ksmbd) just pass in STATX_BASIC_STATS. Also move the setting of STATX_CHANGE_COOKIE into generic_fillattr.
--- fs/9p/vfs_inode.c | 4 ++-- fs/9p/vfs_inode_dotl.c | 4 ++-- fs/afs/inode.c | 2 +- fs/btrfs/inode.c | 2 +- fs/ceph/inode.c | 2 +- fs/coda/inode.c | 3 ++- fs/ecryptfs/inode.c | 5 +++-- fs/erofs/inode.c | 2 +- fs/exfat/file.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/f2fs/file.c | 2 +- fs/fat/file.c | 2 +- fs/fuse/dir.c | 2 +- fs/gfs2/inode.c | 2 +- fs/hfsplus/inode.c | 2 +- fs/kernfs/inode.c | 2 +- fs/libfs.c | 4 ++-- fs/minix/inode.c | 2 +- fs/nfs/inode.c | 2 +- fs/nfs/namespace.c | 3 ++- fs/ntfs3/file.c | 2 +- fs/ocfs2/file.c | 2 +- fs/orangefs/inode.c | 2 +- fs/proc/base.c | 4 ++-- fs/proc/fd.c | 2 +- fs/proc/generic.c | 2 +- fs/proc/proc_net.c | 2 +- fs/proc/proc_sysctl.c | 2 +- fs/proc/root.c | 3 ++- fs/smb/client/inode.c | 2 +- fs/smb/server/smb2pdu.c | 22 +++++++++++----------- fs/smb/server/vfs.c | 3 ++- fs/stat.c | 24 +++++++++++++----------- fs/sysv/itree.c | 3 ++- fs/ubifs/dir.c | 2 +- fs/udf/symlink.c | 2 +- fs/vboxsf/utils.c | 2 +- include/linux/fs.h | 2 +- mm/shmem.c | 2 +- 40 files changed, 73 insertions(+), 65 deletions(-)
fs/9p/vfs_inode.c +2 -2
@@ -1016,7 +1016,7 @@ v9fs_vfs_getattr(struct mnt_idmap *idmap, const struct path *path,p9_debug (P9_DEBUG_VFS ,"dentry: %p\n" , dentry); v9ses =v9fs_dentry2v9ses (dentry);if (v9ses->cache & (CACHE_META |CACHE_LOOSE )) { -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);return 0 ; }else if (v9ses->cache &CACHE_WRITEBACK ) {if (S_ISREG (inode->i_mode)) {
@@ -1037,7 +1037,7 @@ v9fs_vfs_getattr(struct mnt_idmap *idmap, const struct path *path,return PTR_ERR (st);v9fs_stat2inode (st,d_inode (dentry), dentry->d_sb,0 ); -generic_fillattr (&nop_mnt_idmap,d_inode (dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask,d_inode (dentry), stat);p9stat_free (st);kfree (st);
fs/9p/vfs_inode_dotl.c +2 -2
@@ -451,7 +451,7 @@ v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap,p9_debug (P9_DEBUG_VFS ,"dentry: %p\n" , dentry); v9ses =v9fs_dentry2v9ses (dentry);if (v9ses->cache & (CACHE_META |CACHE_LOOSE )) { -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);return 0 ; }else if (v9ses->cache) {if (S_ISREG (inode->i_mode)) {
@@ -476,7 +476,7 @@ v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap,return PTR_ERR (st);v9fs_stat2inode_dotl (st,d_inode (dentry),0 ); -generic_fillattr (&nop_mnt_idmap,d_inode (dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask,d_inode (dentry), stat);/* Change block size to what the server returned */ stat->blksize = st->st_blksize;
fs/afs/inode.c +1 -1
@@ -773,7 +773,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path, do { read_seqbegin_or_lock(&vnode->cb_lock, &seq); - generic_fillattr(&nop_mnt_idmap, inode, stat); + generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && stat->nlink > 0) stat->nlink -= 1;
fs/btrfs/inode.c +1 -1
@@ -8746,7 +8746,7 @@ static int btrfs_getattr(struct mnt_idmap *idmap,STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat); stat->dev =BTRFS_I (inode)->root->anon_dev;spin_lock (&BTRFS_I (inode)->lock);
fs/ceph/inode.c +1 -1
@@ -2467,7 +2467,7 @@ int ceph_getattr(struct mnt_idmap *idmap, const struct path *path,return err; } -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->ino =ceph_present_inode (inode);/*
fs/coda/inode.c +2 -1
@@ -256,7 +256,8 @@ int coda_getattr(struct mnt_idmap *idmap, const struct path *path, {int err =coda_revalidate_inode (d_inode (path->dentry));if (!err) -generic_fillattr (&nop_mnt_idmap,d_inode (path->dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask, +d_inode (path->dentry), stat);return err; }
fs/ecryptfs/inode.c +3 -2
@@ -982,7 +982,7 @@ static int ecryptfs_getattr_link(struct mnt_idmap *idmap, mount_crypt_stat = &ecryptfs_superblock_to_private ( dentry->d_sb)->mount_crypt_stat; -generic_fillattr (&nop_mnt_idmap,d_inode (dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask,d_inode (dentry), stat);if (mount_crypt_stat->flags &ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES ) {char *target;size_t targetsiz;
@@ -1011,7 +1011,8 @@ static int ecryptfs_getattr(struct mnt_idmap *idmap,if (!rc) {fsstack_copy_attr_all (d_inode (dentry),ecryptfs_inode_to_lower (d_inode (dentry))); -generic_fillattr (&nop_mnt_idmap,d_inode (dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask, +d_inode (dentry), stat); stat->blocks = lower_stat.blocks; }return rc;
fs/erofs/inode.c +1 -1
@@ -368,7 +368,7 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, stat->attributes_mask |= (STATX_ATTR_COMPRESSED |STATX_ATTR_IMMUTABLE ); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat);return 0 ; }
fs/exfat/file.c +1 -1
@@ -232,7 +232,7 @@ int exfat_getattr(struct mnt_idmap *idmap, const struct path *path,struct inode *inode =d_backing_inode (path->dentry);struct exfat_inode_info *ei =EXFAT_I (inode); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);exfat_truncate_atime (&stat->atime); stat->result_mask |=STATX_BTIME ; stat->btime.tv_sec = ei->i_crtime.tv_sec;
fs/ext2/inode.c +1 -1
@@ -1628,7 +1628,7 @@ int ext2_getattr(struct mnt_idmap *idmap, const struct path *path,STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);return 0 ; }
fs/ext4/inode.c +1 -1
@@ -5535,7 +5535,7 @@ int ext4_getattr(struct mnt_idmap *idmap, const struct path *path,STATX_ATTR_NODUMP | STATX_ATTR_VERITY); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat);return 0 ; }
fs/f2fs/file.c +1 -1
@@ -882,7 +882,7 @@ int f2fs_getattr(struct mnt_idmap *idmap, const struct path *path,STATX_ATTR_NODUMP | STATX_ATTR_VERITY); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat);/* we need to show initial sectors used for inline_data/dentries */ if ((S_ISREG(inode->i_mode) && f2fs_has_inline_data(inode)) ||
fs/fat/file.c +1 -1
@@ -401,7 +401,7 @@ int fat_getattr(struct mnt_idmap *idmap, const struct path *path,struct inode *inode =d_inode (path->dentry);struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat); stat->blksize = sbi->cluster_size;if (sbi->options.nfs ==FAT_NFS_NOSTALE_RO ) {
fs/fuse/dir.c +1 -1
@@ -1224,7 +1224,7 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file,forget_all_cached_acls (inode); err =fuse_do_getattr (inode, stat, file); }else if (stat) { -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->mode = fi->orig_i_mode; stat->ino = fi->orig_ino; }
fs/gfs2/inode.c +1 -1
@@ -2071,7 +2071,7 @@ static int gfs2_getattr(struct mnt_idmap *idmap,STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);if (gfs2_holder_initialized (&gh))gfs2_glock_dq_uninit (&gh);
fs/hfsplus/inode.c +1 -1
@@ -298,7 +298,7 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path, stat->attributes_mask |=STATX_ATTR_APPEND |STATX_ATTR_IMMUTABLE |STATX_ATTR_NODUMP ; -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);return 0 ; }
fs/kernfs/inode.c +1 -1
@@ -190,7 +190,7 @@ int kernfs_iop_getattr(struct mnt_idmap *idmap,down_read (&root->kernfs_iattr_rwsem);kernfs_refresh_inode (kn, inode); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);up_read (&root->kernfs_iattr_rwsem);return 0 ;
fs/libfs.c +2 -2
@@ -33,7 +33,7 @@ int simple_getattr(struct mnt_idmap *idmap, const struct path *path, unsigned int query_flags) {struct inode *inode =d_inode (path->dentry); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->blocks = inode->i_mapping->nrpages << (PAGE_SHIFT -9 );return 0 ; }
@@ -1334,7 +1334,7 @@ static int empty_dir_getattr(struct mnt_idmap *idmap, u32 request_mask, unsigned int query_flags) { struct inode *inode = d_inode(path->dentry); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);return 0 ; }
fs/minix/inode.c +1 -1
@@ -656,7 +656,7 @@ int minix_getattr(struct mnt_idmap *idmap, const struct path *path,struct super_block *sb = path->dentry->d_sb;struct inode *inode =d_inode (path->dentry); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);if (INODE_VERSION (inode) ==MINIX_V1 ) stat->blocks = (BLOCK_SIZE /512 ) *V1_minix_blocks (stat->size, sb);else
fs/nfs/inode.c +1 -1
@@ -912,7 +912,7 @@ int nfs_getattr(struct mnt_idmap *idmap, const struct path *path,/* Only return attributes that were revalidated. */ stat->result_mask =nfs_get_valid_attrmask (inode) | request_mask; -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->ino =nfs_compat_user_ino64 (NFS_FILEID (inode)); stat->change_cookie =inode_peek_iversion_raw (inode); stat->attributes_mask |=STATX_ATTR_CHANGE_MONOTONIC ;
fs/nfs/namespace.c +2 -1
@@ -215,7 +215,8 @@ nfs_namespace_getattr(struct mnt_idmap *idmap,if (NFS_FH (d_inode (path->dentry))->size !=0 )return nfs_getattr (idmap, path, stat, request_mask, query_flags); -generic_fillattr (&nop_mnt_idmap,d_inode (path->dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask,d_inode (path->dentry), + stat);return 0 ; }
fs/ntfs3/file.c +1 -1
@@ -85,7 +85,7 @@ int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path, stat->attributes_mask |=STATX_ATTR_COMPRESSED |STATX_ATTR_ENCRYPTED ; -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat); stat->result_mask |=STATX_BTIME ; stat->btime = ni->i_crtime;
fs/ocfs2/file.c +1 -1
@@ -1319,7 +1319,7 @@ int ocfs2_getattr(struct mnt_idmap *idmap, const struct path *path, goto bail; } -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);/* * If there is inline data in the inode, the inode will normally not * have data blocks allocated (it may have an external xattr block).
fs/orangefs/inode.c +1 -1
@@ -871,7 +871,7 @@ int orangefs_getattr(struct mnt_idmap *idmap, const struct path *path, ret =orangefs_inode_getattr (inode, request_mask &STATX_SIZE ?ORANGEFS_GETATTR_SIZE :0 );if (ret ==0 ) { -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);/* override block size reported to stat */ if (!(request_mask &STATX_SIZE ))
fs/proc/base.c +2 -2
@@ -1966,7 +1966,7 @@ int pid_getattr(struct mnt_idmap *idmap, const struct path *path,struct proc_fs_info *fs_info =proc_sb_info (inode->i_sb);struct task_struct *task; -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->uid =GLOBAL_ROOT_UID ; stat->gid =GLOBAL_ROOT_GID ;
@@ -3899,7 +3899,7 @@ static int proc_task_getattr(struct mnt_idmap *idmap, {struct inode *inode =d_inode (path->dentry);struct task_struct *p =get_proc_task (inode); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);if (p) { stat->nlink +=get_nr_threads (p);
fs/proc/fd.c +1 -1
@@ -352,7 +352,7 @@ static int proc_fd_getattr(struct mnt_idmap *idmap,struct inode *inode =d_inode (path->dentry);int rv =0 ; -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);/* If it's a directory, put the number of open fds there */ if (S_ISDIR (inode->i_mode)) {
fs/proc/generic.c +1 -1
@@ -146,7 +146,7 @@ static int proc_getattr(struct mnt_idmap *idmap, } } -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);return 0 ; }
fs/proc/proc_net.c +1 -1
@@ -308,7 +308,7 @@ static int proc_tgid_net_getattr(struct mnt_idmap *idmap, net =get_proc_task_net (inode); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);if (net !=NULL ) { stat->nlink = net->proc_net->nlink;
fs/proc/proc_sysctl.c +1 -1
@@ -849,7 +849,7 @@ static int proc_sys_getattr(struct mnt_idmap *idmap,if (IS_ERR (head))return PTR_ERR (head); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat);if (table) stat->mode = (stat->mode &S_IFMT ) | table->mode;
fs/proc/root.c +2 -1
@@ -314,7 +314,8 @@ static int proc_root_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask, unsigned int query_flags) { - generic_fillattr(&nop_mnt_idmap, d_inode(path->dentry), stat); + generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(path->dentry), +stat ); stat->nlink = proc_root.nlink +nr_processes ();return 0 ; }
fs/smb/client/inode.c +1 -1
@@ -2540,7 +2540,7 @@ int cifs_getattr(struct mnt_idmap *idmap, const struct path *path,return rc; } -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->blksize = cifs_sb->ctx->bsize; stat->ino =CIFS_I (inode)->uniqueid;
fs/smb/server/smb2pdu.c +11 -11
@@ -4391,8 +4391,8 @@ static int get_file_basic_info(struct smb2_query_info_rsp *rsp, } basic_info = (struct smb2_file_basic_info *)rsp->Buffer; -generic_fillattr (file_mnt_idmap (fp->filp),file_inode (fp->filp), - &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , +file_inode (fp->filp), &stat); basic_info->CreationTime =cpu_to_le64 (fp->create_time); time =ksmbd_UnixTimeToNT (stat.atime); basic_info->LastAccessTime =cpu_to_le64 (time);
@@ -4417,7 +4417,7 @@ static void get_file_standard_info(struct smb2_query_info_rsp *rsp,struct kstat stat; inode =file_inode (fp->filp); -generic_fillattr (file_mnt_idmap (fp->filp), inode, &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , inode, &stat); sinfo = (struct smb2_file_standard_info *)rsp->Buffer; delete_pending =ksmbd_inode_pending_delete (fp);
@@ -4471,7 +4471,7 @@ static int get_file_all_info(struct ksmbd_work *work,return PTR_ERR (filename); inode =file_inode (fp->filp); -generic_fillattr (file_mnt_idmap (fp->filp), inode, &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , inode, &stat);ksmbd_debug (SMB ,"filename = %s\n" , filename); delete_pending =ksmbd_inode_pending_delete (fp);
@@ -4548,8 +4548,8 @@ static void get_file_stream_info(struct ksmbd_work *work,int buf_free_len;struct smb2_query_info_req *req =ksmbd_req_buf_next (work); -generic_fillattr (file_mnt_idmap (fp->filp),file_inode (fp->filp), - &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , +file_inode (fp->filp), &stat); file_info = (struct smb2_file_stream_info *)rsp->Buffer; buf_free_len =
@@ -4639,8 +4639,8 @@ static void get_file_internal_info(struct smb2_query_info_rsp *rsp,struct smb2_file_internal_info *file_info;struct kstat stat; -generic_fillattr (file_mnt_idmap (fp->filp),file_inode (fp->filp), - &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , +file_inode (fp->filp), &stat); file_info = (struct smb2_file_internal_info *)rsp->Buffer; file_info->IndexNumber =cpu_to_le64 (stat.ino); rsp->OutputBufferLength =
@@ -4665,7 +4665,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp, file_info = (struct smb2_file_ntwrk_info *)rsp->Buffer; inode =file_inode (fp->filp); -generic_fillattr (file_mnt_idmap (fp->filp), inode, &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , inode, &stat); file_info->CreationTime =cpu_to_le64 (fp->create_time); time =ksmbd_UnixTimeToNT (stat.atime);
@@ -4726,8 +4726,8 @@ static void get_file_compression_info(struct smb2_query_info_rsp *rsp,struct smb2_file_comp_info *file_info;struct kstat stat; -generic_fillattr (file_mnt_idmap (fp->filp),file_inode (fp->filp), - &stat); +generic_fillattr (file_mnt_idmap (fp->filp),STATX_BASIC_STATS , +file_inode (fp->filp), &stat); file_info = (struct smb2_file_comp_info *)rsp->Buffer; file_info->CompressedFileSize =cpu_to_le64 (stat.blocks <<9 );
fs/smb/server/vfs.c +2 -1
@@ -1650,7 +1650,8 @@ int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,u64 time;int rc; -generic_fillattr (idmap,d_inode (dentry), ksmbd_kstat->kstat); +generic_fillattr (idmap,STATX_BASIC_STATS ,d_inode (dentry), + ksmbd_kstat->kstat); time =ksmbd_UnixTimeToNT (ksmbd_kstat->kstat->ctime); ksmbd_kstat->create_time = time;
fs/stat.c +13 -11
@@ -28,9 +28,10 @@/** * generic_fillattr - Fill in the basic attributes from the inode struct -* @idmap: idmap of the mount the inode was found from -* @inode: Inode to use as the source -* @stat: Where to fill in the attributes +* @idmap: idmap of the mount the inode was found from +* @request_mask: statx request_mask +* @inode: Inode to use as the source +* @stat: Where to fill in the attributes * * Fill in the basic attributes in the kstat structure from data that's to be * found on the VFS inode structure. This is the default if no getattr inode
@@ -42,8 +43,8 @@* uid and gid filds. On non-idmapped mounts or if permission checking is to be * performed on the raw inode simply passs @nop_mnt_idmap. */ -void generic_fillattr (struct mnt_idmap *idmap,struct inode *inode, -struct kstat *stat) +void generic_fillattr (struct mnt_idmap *idmap,u32 request_mask, +struct inode *inode,struct kstat *stat) {vfsuid_t vfsuid =i_uid_into_vfsuid (idmap, inode);vfsgid_t vfsgid =i_gid_into_vfsgid (idmap, inode);
@@ -61,6 +62,12 @@ void generic_fillattr(struct mnt_idmap *idmap, struct inode *inode, stat->ctime =inode_get_ctime (inode); stat->blksize =i_blocksize (inode); stat->blocks = inode->i_blocks; + +if ((request_mask &STATX_CHANGE_COOKIE ) &&IS_I_VERSION (inode)) { + stat->result_mask |=STATX_CHANGE_COOKIE ; + stat->change_cookie =inode_query_iversion (inode); + } + }EXPORT_SYMBOL (generic_fillattr);
@@ -123,17 +130,12 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat, stat->attributes_mask |= (STATX_ATTR_AUTOMOUNT |STATX_ATTR_DAX ); -if ((request_mask &STATX_CHANGE_COOKIE ) &&IS_I_VERSION (inode)) { - stat->result_mask |=STATX_CHANGE_COOKIE ; - stat->change_cookie =inode_query_iversion (inode); - } - idmap =mnt_idmap (path->mnt);if (inode->i_op->getattr)return inode->i_op->getattr (idmap, path, stat, request_mask, query_flags); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat);return 0 ; }EXPORT_SYMBOL (vfs_getattr_nosec);
fs/sysv/itree.c +2 -1
@@ -449,7 +449,8 @@ int sysv_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags) { struct super_block *s = path->dentry->d_sb; -generic_fillattr (&nop_mnt_idmap,d_inode (path->dentry), stat); +generic_fillattr (&nop_mnt_idmap, request_mask,d_inode (path->dentry), + stat); stat->blocks = (s->s_blocksize /512 ) *sysv_nblocks (s, stat->size); stat->blksize = s->s_blocksize;return 0 ;
fs/ubifs/dir.c +1 -1
@@ -1654,7 +1654,7 @@ int ubifs_getattr(struct mnt_idmap *idmap, const struct path *path,STATX_ATTR_ENCRYPTED | STATX_ATTR_IMMUTABLE); -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); stat->blksize =UBIFS_BLOCK_SIZE ; stat->size = ui->ui_size;
fs/udf/symlink.c +1 -1
@@ -149,7 +149,7 @@ static int udf_symlink_getattr(struct mnt_idmap *idmap,struct inode *inode =d_backing_inode (dentry);struct page *page; -generic_fillattr (&nop_mnt_idmap, inode, stat); +generic_fillattr (&nop_mnt_idmap, request_mask, inode, stat); page =read_mapping_page (inode->i_mapping,0 ,NULL );if (IS_ERR (page))return PTR_ERR (page);
fs/vboxsf/utils.c +1 -1
@@ -252,7 +252,7 @@ int vboxsf_getattr(struct mnt_idmap *idmap, const struct path *path,if (err)return err; -generic_fillattr (&nop_mnt_idmap,d_inode (dentry), kstat); +generic_fillattr (&nop_mnt_idmap, request_mask,d_inode (dentry), kstat);return 0 ; }
include/linux/fs.h +1 -1
@@ -2917,7 +2917,7 @@ extern void page_put_link(void *);extern int page_symlink (struct inode *inode,const char *symname,int len);extern const struct inode_operations page_symlink_inode_operations;extern void kfree_link (void *); -void generic_fillattr (struct mnt_idmap *,struct inode *,struct kstat *); +void generic_fillattr (struct mnt_idmap *,u32 ,struct inode *,struct kstat *);void generic_fill_statx_attr (struct inode *inode,struct kstat *stat);extern int vfs_getattr_nosec (const struct path *,struct kstat *,u32 ,unsigned int );extern int vfs_getattr (const struct path *,struct kstat *,u32 ,unsigned int );
mm/shmem.c +1 -1
@@ -1073,7 +1073,7 @@ static int shmem_getattr(struct mnt_idmap *idmap, stat->attributes_mask |= (STATX_ATTR_APPEND |STATX_ATTR_IMMUTABLE |STATX_ATTR_NODUMP ); -generic_fillattr (idmap, inode, stat); +generic_fillattr (idmap, request_mask, inode, stat);if (shmem_is_huge (inode,0 , false,NULL ,0 )) stat->blksize =HPAGE_PMD_SIZE ;
Signature · 1 line
2.41.0
Jeff Layton
maintainerPATCH v7 3/13 fs: drop the timespec64 arg from generic_update_time
In reply to Jeff LaytonIn future patches we're going to change how the ctime is updated to keep track of when it has been queried. The way that the update_time operation works (and a lot of its callers) make this difficult, since they grab a timestamp early and then pass it down to eventually be copied into the inode.
All of the existing update_time callers pass in the result of current_time() in some fashion. Drop the "time" parameter from generic_update_time, and rework it to fetch its own timestamp.
This change means that an update_time could fetch a different timestamp than was seen in inode_needs_update_time. update_time is only ever called with one of two flag combinations: Either S_ATIME is set, or S_MTIME|S_CTIME|S_VERSION are set.
With this change we now treat the flags argument as an indicator that some value needed to be updated when last checked, rather than an indication to update specific timestamps.
Rework the logic for updating the timestamps and put it in a new inode_update_timestamps helper that other update_time routines can use. S_ATIME is as treated as we always have, but if any of the other three are set, then we attempt to update all three.
Also, some callers of generic_update_time need to know what timestamps were actually updated. Change it to return an S_* flag mask to indicate that and rework the callers to expect it.
--- fs/gfs2/inode.c | 3 +- fs/inode.c | 84 +++++++++++++++++++++++++++++++++++++++++------------ fs/orangefs/inode.c | 3 +- fs/ubifs/file.c | 6 ++-- fs/xfs/xfs_iops.c | 6 ++-- include/linux/fs.h | 3 +- 6 files changed, 80 insertions(+), 25 deletions(-)
fs/gfs2/inode.c +2 -1
@@ -2155,7 +2155,8 @@ static int gfs2_update_time(struct inode *inode, struct timespec64 *time,if (error)return error; } -return generic_update_time (inode, time, flags); +generic_update_time (inode, flags); +return 0 ; }static const struct inode_operations gfs2_file_iops = {
fs/inode.c +66 -18
102 lines not on this page · raw message
fs/orangefs/inode.c +2 -1
@@ -903,9 +903,10 @@ int orangefs_permission(struct mnt_idmap *idmap,int orangefs_update_time (struct inode *inode,struct timespec64 *time,int flags) {struct iattr iattr; +gossip_debug (GOSSIP_INODE_DEBUG ,"orangefs_update_time: %pU\n" ,get_khandle_from_ino (inode)); -generic_update_time (inode, time, flags); + flags =generic_update_time (inode, flags);memset (&iattr,0 ,sizeof iattr);if (flags &S_ATIME ) iattr.ia_valid |=ATTR_ATIME ;
fs/ubifs/file.c +4 -2
@@ -1387,8 +1387,10 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time, .dirtied_ino_d = ALIGN(ui->data_len, 8) };int err, release; -if (!IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) -return generic_update_time (inode, time, flags); +if (!IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) { +generic_update_time (inode, flags); +return 0 ; + } err =ubifs_budget_space (c, &req);if (err)
fs/xfs/xfs_iops.c +4 -2
@@ -1042,8 +1042,10 @@ xfs_vn_update_time(if (inode->i_sb->s_flags &SB_LAZYTIME ) {if (!((flags &S_VERSION ) && -inode_maybe_inc_iversion (inode, false))) -return generic_update_time (inode, now, flags); +inode_maybe_inc_iversion (inode, false))) { +generic_update_time (inode, flags); +return 0 ; + }/* Capture the iversion update that just occurred */ log_flags |=XFS_ILOG_CORE ;
include/linux/fs.h +2 -1
@@ -2343,7 +2343,8 @@ extern int current_umask(void);extern void ihold (struct inode * inode);extern void iput (struct inode *); -extern int generic_update_time (struct inode *,struct timespec64 *,int ); +int inode_update_timestamps (struct inode *inode,int flags); +int generic_update_time (struct inode *,int );/* /sys/fs */ extern struct kobject *fs_kobj;
Signature · 1 line
2.41.0
Re: [PATCH v7 03/13] fs: drop the timespec64 arg from generic_update_time
Quoted 24 lines · Jeff Layton
In future patches we're going to change how the ctime is updated to keep track of when it has been queried. The way that the
update_timeoperation works (and a lot of its callers) make this difficult, since they grab a timestamp early and then pass it down to eventually be copied into the inode.All of the existing
update_timecallers pass in the result ofcurrent_time()in some fashion. Drop the "time" parameter fromgeneric_update_time, and rework it to fetch its own timestamp.This change means that an
update_timecould fetch a different timestamp than was seen ininode_needs_update_time.update_timeis only ever called with one of two flag combinations: EitherS_ATIMEis set, or S_MTIME|S_CTIME|S_VERSION are set.With this change we now treat the flags argument as an indicator that some value needed to be updated when last checked, rather than an indication to update specific timestamps.
Rework the logic for updating the timestamps and put it in a new
inode_update_timestampshelper that otherupdate_timeroutines can use.S_ATIMEis as treated as we always have, but if any of the other three are set, then we attempt to update all three.
Quoted 5 lines
Also, some callers of
generic_update_timeneed to know what timestamps were actually updated. Change it to return an S_* flag mask to indicate that and rework the callers to expect it.Signed-off-by Jeff Layton <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 199 lines
--- fs/gfs2/inode.c | 3 +- fs/inode.c | 84 +++++++++++++++++++++++++++++++++++++++++------------ fs/orangefs/inode.c | 3 +- fs/ubifs/file.c | 6 ++-- fs/xfs/xfs_iops.c | 6 ++-- include/linux/fs.h | 3 +- 6 files changed, 80 insertions(+), 25 deletions(-)fs/gfs2/inode.c +2
-1@@ -2155,7 +2155,8 @@ static int gfs2_update_time(struct inode *inode, struct timespec64 *time,if (error)return error; } -return generic_update_time (inode, time, flags); +generic_update_time (inode, flags); +return 0 ; }static const struct inode_operations gfs2_file_iops = {fs/inode.c +66
-18@@ -1881,29 +1881,76 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,return 0 ; } -int generic_update_time (struct inode *inode,struct timespec64 *time,int flags) +/** +* inode_update_timestamps - update the timestamps on the inode +* @inode: inode to be updated +* @flags: S_* flags that needed to be updated +* +* The update_time function is called when an inode's timestamps need to be +* updated for a read or write operation. This function handles updating the +* actual timestamps. It's up to the caller to ensure that the inode is marked +* dirty appropriately. +* +* In the case where any of S_MTIME, S_CTIME, or S_VERSION need to be updated, +* attempt to update all three of them. S_ATIME updates can be handled +* independently of the rest. +* +* Returns a set of S_* flags indicating which values changed. +*/ +int inode_update_timestamps (struct inode *inode,int flags) { -int dirty_flags =0 ; +int updated =0 ; +struct timespec64 now; + +if (flags & (S_MTIME |S_CTIME |S_VERSION )) { +struct timespec64 ctime =inode_get_ctime (inode); -if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -if (flags &S_ATIME ) - inode->i_atime = *time; -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *time); -if (flags &S_MTIME ) - inode->i_mtime = *time; - -if (inode->i_sb->s_flags &SB_LAZYTIME ) - dirty_flags |=I_DIRTY_TIME ; -else - dirty_flags |=I_DIRTY_SYNC ; + now =inode_set_ctime_current (inode); +if (!timespec64_equal (&now, &ctime)) + updated |=S_CTIME ; +if (!timespec64_equal (&now, &inode->i_mtime)) { + inode->i_mtime = now; + updated |=S_MTIME ; + } +if (IS_I_VERSION (inode) &&inode_maybe_inc_iversion (inode, updated)) + updated |=S_VERSION ; + }else { + now =current_time (inode); } -if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) - dirty_flags |=I_DIRTY_SYNC ; +if (flags &S_ATIME ) { +if (!timespec64_equal (&now, &inode->i_atime)) { + inode->i_atime = now; + updated |=S_ATIME ; + } + } +return updated; +} +EXPORT_SYMBOL (inode_update_timestamps); + +/** +* generic_update_time - update the timestamps on the inode +* @inode: inode to be updated +* @flags: S_* flags that needed to be updated +* +* The update_time function is called when an inode's timestamps need to be +* updated for a read or write operation. In the case where any of S_MTIME, S_CTIME, +* 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. +*/ +int generic_update_time (struct inode *inode,int flags) +{ +int updated =inode_update_timestamps (inode, flags); +int dirty_flags =0 ; +if (updated & (S_ATIME |S_MTIME |S_CTIME )) + dirty_flags = inode->i_sb->s_flags &SB_LAZYTIME ?I_DIRTY_TIME :I_DIRTY_SYNC ; +if (updated &S_VERSION ) + dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags); -return 0 ; +return updated; }EXPORT_SYMBOL (generic_update_time);@@ -1915,7 +1962,8 @@ int inode_update_time(struct inode *inode, struct timespec64 *time, int flags) {if (inode->i_op->update_time)return inode->i_op->update_time (inode, time, flags); -return generic_update_time (inode, time, flags); +generic_update_time (inode, flags); +return 0 ; }EXPORT_SYMBOL (inode_update_time);fs/orangefs/inode.c +2
-1@@ -903,9 +903,10 @@ int orangefs_permission(struct mnt_idmap *idmap,int orangefs_update_time (struct inode *inode,struct timespec64 *time,int flags) {struct iattr iattr; +gossip_debug (GOSSIP_INODE_DEBUG ,"orangefs_update_time: %pU\n" ,get_khandle_from_ino (inode)); -generic_update_time (inode, time, flags); + flags =generic_update_time (inode, flags);memset (&iattr,0 ,sizeof iattr);if (flags &S_ATIME ) iattr.ia_valid |=ATTR_ATIME ;fs/ubifs/file.c +4
-2@@ -1387,8 +1387,10 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time, .dirtied_ino_d = ALIGN(ui->data_len, 8) };int err, release; -if (!IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) -return generic_update_time (inode, time, flags); +if (!IS_ENABLED (CONFIG_UBIFS_ATIME_SUPPORT )) { +generic_update_time (inode, flags); +return 0 ; + } err =ubifs_budget_space (c, &req);if (err)fs/xfs/xfs_iops.c +4
-2@@ -1042,8 +1042,10 @@ xfs_vn_update_time(if (inode->i_sb->s_flags &SB_LAZYTIME ) {if (!((flags &S_VERSION ) && -inode_maybe_inc_iversion (inode, false))) -return generic_update_time (inode, now, flags); +inode_maybe_inc_iversion (inode, false))) { +generic_update_time (inode, flags); +return 0 ; + }/* Capture the iversion update that just occurred */ log_flags |=XFS_ILOG_CORE ;include/linux/fs.h +2
-1@@ -2343,7 +2343,8 @@ extern int current_umask(void);extern void ihold (struct inode * inode);extern void iput (struct inode *); -extern int generic_update_time (struct inode *,struct timespec64 *,int ); +int inode_update_timestamps (struct inode *inode,int flags); +int generic_update_time (struct inode *,int );/* /sys/fs */ extern struct kobject *fs_kobj;Signature · 2 lines
-- 2.41.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerPATCH v7 4/13 btrfs: have it use inode_update_timestamps
In reply to Jeff LaytonIn later patches, we're going to drop the "now" argument from the update_time operation. Have btrfs_update_time use the new inode_update_timestamps helper to fetch a new timestamp and update it properly.
--- fs/btrfs/inode.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
fs/btrfs/inode.c +1 -8
@@ -6068,14 +6068,7 @@ static int btrfs_update_time(struct inode *inode, struct timespec64 *now,if (btrfs_root_readonly (root))return -EROFS ; -if (flags &S_VERSION ) - dirty |=inode_maybe_inc_iversion (inode, dirty); -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *now); -if (flags &S_MTIME ) - inode->i_mtime = *now; -if (flags &S_ATIME ) - inode->i_atime = *now; + dirty =inode_update_timestamps (inode, flags);return dirty ?btrfs_dirty_inode (BTRFS_I (inode)) :0 ; }
Signature · 1 line
2.41.0
Re: [PATCH v7 04/13] btrfs: have it use inode_update_timestamps
Quoted 6 lines · Jeff Layton
In later patches, we're going to drop the "now" argument from the
update_timeoperation. Havebtrfs_update_timeuse the newinode_update_timestampshelper to fetch a new timestamp and update it properly.Signed-off-by Jeff Layton <[email protected]>
Nice cleanup! Feel free to add:
Honza
Quoted 28 lines
--- fs/btrfs/inode.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)fs/btrfs/inode.c +1
-8@@ -6068,14 +6068,7 @@ static int btrfs_update_time(struct inode *inode, struct timespec64 *now,if (btrfs_root_readonly (root))return -EROFS ; -if (flags &S_VERSION ) - dirty |=inode_maybe_inc_iversion (inode, dirty); -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *now); -if (flags &S_MTIME ) - inode->i_mtime = *now; -if (flags &S_ATIME ) - inode->i_atime = *now; + dirty =inode_update_timestamps (inode, flags);return dirty ?btrfs_dirty_inode (BTRFS_I (inode)) :0 ; }Signature · 2 lines
-- 2.41.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerPATCH v7 5/13 fat: make fat_update_time get its own timestamp
In reply to Jeff LaytonIn later patches, we're going to drop the "now" parameter from the update_time operation. Fix fat_update_time to fetch its own timestamp. It turns out that this is easily done by just passing a NULL timestamp pointer to fat_update_time.
Also, it may be that things have changed by the time we get to calling fat_update_time after checking inode_needs_update_time. Ensure that we attempt the i_version bump if any of the S_* flags besides S_ATIME are set.
--- fs/fat/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/fat/misc.c +2 -2
@@ -347,14 +347,14 @@ int fat_update_time(struct inode *inode, struct timespec64 *now, int flags)return 0 ;if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -fat_truncate_time (inode, now, flags); +fat_truncate_time (inode,NULL , flags);if (inode->i_sb->s_flags &SB_LAZYTIME ) dirty_flags |=I_DIRTY_TIME ;else dirty_flags |=I_DIRTY_SYNC ; } -if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags);
Signature · 1 line
2.41.0
Re: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 4 lines · Jeff Layton
In later patches, we're going to drop the "now" parameter from the
update_timeoperation. Fixfat_update_timeto fetch its own timestamp. It turns out that this is easily done by just passing a NULL timestamp pointer tofat_update_time.
^^^ fat_truncate_time()
Quoted 6 lines
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.Signed-off-by Jeff Layton <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 29 lines
--- fs/fat/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/fat/misc.c +2
-2@@ -347,14 +347,14 @@ int fat_update_time(struct inode *inode, struct timespec64 *now, int flags)return 0 ;if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -fat_truncate_time (inode, now, flags); +fat_truncate_time (inode,NULL , flags);if (inode->i_sb->s_flags &SB_LAZYTIME ) dirty_flags |=I_DIRTY_TIME ;else dirty_flags |=I_DIRTY_SYNC ; } -if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags);Signature · 2 lines
-- 2.41.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 6 lines · Jan Kara
Quoted 4 lines · Jeff Layton
In later patches, we're going to drop the "now" parameter from the
update_timeoperation. Fixfat_update_timeto fetch its own timestamp. It turns out that this is easily done by just passing a NULL timestamp pointer tofat_update_time.^^^ fat_truncate_time()
Fixed in-tree, thanks!
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
In reply to Jeff LaytonQuoted 4 lines · Jeff Layton
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.
I'm not sure what it meaning though, this is from generic_update_time(). Are you going to change generic_update_time() too? If so, it doesn't break lazytime feature?
Thanks.
Quoted 26 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/fat/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/fat/misc.c +2
-2@@ -347,14 +347,14 @@ int fat_update_time(struct inode *inode, struct timespec64 *now, int flags)return 0 ;if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -fat_truncate_time (inode, now, flags); +fat_truncate_time (inode,NULL , flags);if (inode->i_sb->s_flags &SB_LAZYTIME ) dirty_flags |=I_DIRTY_TIME ;else dirty_flags |=I_DIRTY_SYNC ; } -if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags);
Signature · 1 line
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 7 lines · OGAWA Hirofumi
Quoted 4 lines · Jeff Layton
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.
Quoted 5 lines
I'm not sure what it meaning though, this is from
generic_update_time(). Are you going to changegeneric_update_time()too? If so, it doesn't break lazytime feature?Thanks.
BTW, fat is not implementing lazytime now, but it is for future.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
In reply to OGAWA HirofumiQuoted 11 lines · OGAWA Hirofumi
Quoted 4 lines · Jeff Layton
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.I'm not sure what it meaning though, this is from
generic_update_time(). Are you going to changegeneric_update_time()too? If so, it doesn't break lazytime feature?
Yes. generic_update_time is also being changed in a similar fashion. This shouldn't break the lazytime feature: lazytime is all about how and when timestamps get written to disk. This work is all about which clocksource the timestamps originally come from.
Quoted 29 lines
Thanks.
Quoted 26 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/fat/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/fat/misc.c +2
-2@@ -347,14 +347,14 @@ int fat_update_time(struct inode *inode, struct timespec64 *now, int flags)return 0 ;if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -fat_truncate_time (inode, now, flags); +fat_truncate_time (inode,NULL , flags);if (inode->i_sb->s_flags &SB_LAZYTIME ) dirty_flags |=I_DIRTY_TIME ;else dirty_flags |=I_DIRTY_SYNC ; } -if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags);
Signature · 1 line
Jeff Layton <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 13 lines · Jeff Layton
Quoted 11 lines · OGAWA Hirofumi
Quoted 4 lines · Jeff Layton
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.I'm not sure what it meaning though, this is from
generic_update_time(). Are you going to changegeneric_update_time()too? If so, it doesn't break lazytime feature?
Quoted 4 lines
Yes.
generic_update_timeis also being changed in a similar fashion. This shouldn't break the lazytime feature: lazytime is all about how and when timestamps get written to disk. This work is all about which clocksource the timestamps originally come from.
I can only find the following update in this series, another series updates generic_update_time()? The patch updates only if S_VERSION is set.
Your fat patch sets I_DIRTY_SYNC always instead of I_DIRTY_TIME. When I last time checked lazytime, and it was depending on I_DIRTY_TIME.
Are you sure it doesn't break lazytime? I'm totally confusing, and really similar with generic_update_time()?
Thanks.
+/**
+ * generic_update_time - update the timestamps on the inode
+ * @inode: inode to be updated
+ * @flags: S_* flags that needed to be updated
+ *
+ * The update_time function is called when an inode's timestamps need to be
+ * updated for a read or write operation. In the case where any of S_MTIME, S_CTIME,
+ * 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.
+ */
+int generic_update_time(struct inode *inode, int flags)
+{
+ int updated = inode_update_timestamps(inode, flags);
+ int dirty_flags = 0;
+ if (updated & (S_ATIME|S_MTIME|S_CTIME))
+ dirty_flags = inode->i_sb->s_flags & SB_LAZYTIME ? I_DIRTY_TIME : I_DIRTY_SYNC;
+ if (updated & S_VERSION)
+ dirty_flags |= I_DIRTY_SYNC;
__mark_inode_dirty(inode, dirty_flags);
- return 0;
+ return updated;
}
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
fs/fat/misc.c +1
-1-if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;__mark_inode_dirty (inode, dirty_flags);
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 24 lines · OGAWA Hirofumi
Quoted 13 lines · Jeff Layton
Quoted 11 lines · OGAWA Hirofumi
Quoted 4 lines · Jeff Layton
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.I'm not sure what it meaning though, this is from
generic_update_time(). Are you going to changegeneric_update_time()too? If so, it doesn't break lazytime feature?Quoted 4 lines
Yes.
generic_update_timeis also being changed in a similar fashion. This shouldn't break the lazytime feature: lazytime is all about how and when timestamps get written to disk. This work is all about which clocksource the timestamps originally come from.I can only find the following update in this series, another series updates
generic_update_time()? The patch updates only ifS_VERSIONis set.
Quoted 6 lines
Your fat patch sets
I_DIRTY_SYNCalways instead ofI_DIRTY_TIME. When I last time checked lazytime, and it was depending onI_DIRTY_TIME.Are you sure it doesn't break lazytime? I'm totally confusing, and really similar with
generic_update_time()?
I'm a little confused too. Why do you believe this will break -o relatime handling? This patch changes two things:
1/ it has fat_update_time fetch its own timestamp (and ignore the "now" parameter). This is in line with the changes in patch #3 of this series, which explains the rationale for this in more detail.
2/ it changes fat_update_time to also update the i_version if any of S_CTIME|S_MTIME|S_VERSION are set. relatime is all about the S_ATIME, and it is specifically excluded from that set.
The rationale for the second change is is also in patch #3, but basically, we can't guarantee that current_time hasn't changed since we last checked for inode_needs_update_time, so if any of S_CTIME/S_MTIME/S_VERSION have changed, then we need to assume that any of them may need to be changed and attempt to update all 3.
That said, I think the logic in fat_update_time isn't quite right. I think want something like this on top of this patch to ensure that the S_CTIME and S_MTIME get updated, even if the flags only have S_VERSION set.
Thoughts?
---------------------8<-----------------------
fs/fat/misc.c +14 -8
@@ -346,15 +346,21 @@ int fat_update_time(struct inode *inode, int flags)if (inode->i_ino ==MSDOS_ROOT_INO )return 0 ; -if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -fat_truncate_time (inode,NULL , flags); -if (inode->i_sb->s_flags &SB_LAZYTIME ) - dirty_flags |=I_DIRTY_TIME ; -else - dirty_flags |=I_DIRTY_SYNC ; - } +/* +* If any of the flags indicate an expicit change to the file, then we +* need to ensure that we attempt to update all of 3. We do not do +* this in the case of an S_ATIME-only update. +*/ +if (flags & (S_CTIME |S_MTIME |S_VERSION )) + flags |=S_CTIME |S_MTIME |S_VERSION ; + +fat_truncate_time (inode,NULL , flags); +if (inode->i_sb->s_flags &SB_LAZYTIME ) + dirty_flags |=I_DIRTY_TIME ; +else + dirty_flags |=I_DIRTY_SYNC ; -if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) +if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 17 lines · Jeff Layton
I'm a little confused too. Why do you believe this will break -o relatime handling? This patch changes two things:
1/ it has
fat_update_timefetch its own timestamp (and ignore the "now" parameter). This is in line with the changes in patch #3 of this series, which explains the rationale for this in more detail.2/ it changes
fat_update_timeto also update thei_versionif any of S_CTIME|S_MTIME|S_VERSION are set. relatime is all about theS_ATIME, and it is specifically excluded from that set.The rationale for the second change is is also in patch #3, but basically, we can't guarantee that
current_timehasn't changed since we last checked forinode_needs_update_time, so if any of S_CTIME/S_MTIME/S_VERSION have changed, then we need to assume that any of them may need to be changed and attempt to update all 3.
Quoted 6 lines
That said, I think the logic in
fat_update_timeisn't quite right. I think want something like this on top of this patch to ensure that theS_CTIMEandS_MTIMEget updated, even if the flags only haveS_VERSIONset.Thoughts?
I'm not talking about "relatime" at all, I'm always talking about "lazytime".
I_DIRTY_TIME delays to update on disk inode only if changed timestamp. But you changed it to I_DIRTY_SYNC, i.e. always update on disk inode by timestamp.
Thanks.
Quoted 35 lines
---------------------8<-----------------------
fs/fat/misc.c +14
-8@@ -346,15 +346,21 @@ int fat_update_time(struct inode *inode, int flags)if (inode->i_ino ==MSDOS_ROOT_INO )return 0 ; -if (flags & (S_ATIME |S_CTIME |S_MTIME )) { -fat_truncate_time (inode,NULL , flags); -if (inode->i_sb->s_flags &SB_LAZYTIME ) - dirty_flags |=I_DIRTY_TIME ; -else - dirty_flags |=I_DIRTY_SYNC ; - } +/* +* If any of the flags indicate an expicit change to the file, then we +* need to ensure that we attempt to update all of 3. We do not do +* this in the case of an S_ATIME-only update. +*/ +if (flags & (S_CTIME |S_MTIME |S_VERSION )) + flags |=S_CTIME |S_MTIME |S_VERSION ; + +fat_truncate_time (inode,NULL , flags); +if (inode->i_sb->s_flags &SB_LAZYTIME ) + dirty_flags |=I_DIRTY_TIME ; +else + dirty_flags |=I_DIRTY_SYNC ; -if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) +if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;
Signature · 1 line
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 24 lines · OGAWA Hirofumi
Quoted 22 lines · Jeff Layton
I'm a little confused too. Why do you believe this will break -o relatime handling? This patch changes two things:
1/ it has
fat_update_timefetch its own timestamp (and ignore the "now" parameter). This is in line with the changes in patch #3 of this series, which explains the rationale for this in more detail.2/ it changes
fat_update_timeto also update thei_versionif any of S_CTIME|S_MTIME|S_VERSION are set. relatime is all about theS_ATIME, and it is specifically excluded from that set.The rationale for the second change is is also in patch #3, but basically, we can't guarantee that
current_timehasn't changed since we last checked forinode_needs_update_time, so if any of S_CTIME/S_MTIME/S_VERSION have changed, then we need to assume that any of them may need to be changed and attempt to update all 3.That said, I think the logic in
fat_update_timeisn't quite right. I think want something like this on top of this patch to ensure that theS_CTIMEandS_MTIMEget updated, even if the flags only haveS_VERSIONset.
Quoted 8 lines
Quoted 1 line
Thoughts?
I'm not talking about "relatime" at all, I'm always talking about "lazytime".
I_DIRTY_TIMEdelays to update on disk inode only if changed timestamp. But you changed it toI_DIRTY_SYNC, i.e. always update on disk inode by timestamp.
And if change like it, why doesn't same change goes to generic_update_time()? It looks like generic_update_time() in this series doesn't work like you said.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jan Kara
reviewerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
In reply to OGAWA HirofumiQuoted 24 lines · OGAWA Hirofumi
Quoted 13 lines · Jeff Layton
Quoted 11 lines · OGAWA Hirofumi
Quoted 4 lines · Jeff Layton
Also, it may be that things have changed by the time we get to calling
fat_update_timeafter checkinginode_needs_update_time. Ensure that we attempt thei_versionbump if any of the S_* flags besidesS_ATIMEare set.I'm not sure what it meaning though, this is from
generic_update_time(). Are you going to changegeneric_update_time()too? If so, it doesn't break lazytime feature?Quoted 4 lines
Yes.
generic_update_timeis also being changed in a similar fashion. This shouldn't break the lazytime feature: lazytime is all about how and when timestamps get written to disk. This work is all about which clocksource the timestamps originally come from.I can only find the following update in this series, another series updates
generic_update_time()? The patch updates only ifS_VERSIONis set.
Quoted 5 lines
Your fat patch sets
I_DIRTY_SYNCalways instead ofI_DIRTY_TIME. When I last time checked lazytime, and it was depending onI_DIRTY_TIME.Are you sure it doesn't break lazytime? I'm totally confusing, and really similar with
generic_update_time()?
Since you are talking past one another with Jeff let me chime in here :). I think you are worried about this hunk:
- if ((flags & S_VERSION) && inode_maybe_inc_iversion(inode, false))
+ if ((flags & (S_VERSION|S_CTIME|S_MTIME)) && inode_maybe_inc_iversion(inode, false))
dirty_flags |= I_DIRTY_SYNC;
which makes the 'flags' test pass even if we just modified ctime or mtime. But do note the second part of the if - inode_maybe_inc_iversion() - so we are going to mark the inode dirty with I_DIRTY_SYNC only if someone queried iversion since the last time we have incremented it.
So this hunk is not really changing how inode is marked dirty, it only changes how often we check whether iversion needs increment and that should be fine (and desirable). Hence lazytime isn't really broken by this in any way.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 2 lines · Jan Kara
Since you are talking past one another with Jeff let me chime in here :). I think you are worried about this hunk:
Right.
Quoted 9 lines
fs/fat/misc.c +1
-1-if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;which makes the 'flags' test pass even if we just modified ctime or mtime. But do note the second part of the if -
inode_maybe_inc_iversion()- so we are going to mark the inode dirty withI_DIRTY_SYNConly if someone queried iversion since the last time we have incremented it.
Quoted 4 lines
So this hunk is not really changing how inode is marked dirty, it only changes how often we check whether iversion needs increment and that should be fine (and desirable). Hence lazytime isn't really broken by this in any way.
OK. However, then it doesn't explain what I asked. This is not same with generic_update_time(), only FAT does.
If thinks it is right thing, why generic_update_time() doesn't? I said first reply, this was from generic_update_time(). (Or I'm misreading updated generic_update_time()?)
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 24 lines · OGAWA Hirofumi
Quoted 2 lines · Jan Kara
Since you are talking past one another with Jeff let me chime in here :). I think you are worried about this hunk:
Right.
Quoted 9 lines
fs/fat/misc.c +1
-1-if ((flags &S_VERSION ) &&inode_maybe_inc_iversion (inode, false)) +if ((flags & (S_VERSION |S_CTIME |S_MTIME )) &&inode_maybe_inc_iversion (inode, false)) dirty_flags |=I_DIRTY_SYNC ;which makes the 'flags' test pass even if we just modified ctime or mtime. But do note the second part of the if -
inode_maybe_inc_iversion()- so we are going to mark the inode dirty withI_DIRTY_SYNConly if someone queried iversion since the last time we have incremented it.Quoted 4 lines
So this hunk is not really changing how inode is marked dirty, it only changes how often we check whether iversion needs increment and that should be fine (and desirable). Hence lazytime isn't really broken by this in any way.
OK. However, then it doesn't explain what I asked. This is not same with
generic_update_time(), only FAT does.
Quoted 4 lines
If thinks it is right thing, why
generic_update_time()doesn't? I said first reply, this was fromgeneric_update_time(). (Or I'm misreading updatedgeneric_update_time()?)
My mistake re: lazytime vs. relatime, but Jan is correct that this shouldn't break anything there.
The logic in the revised generic_update_time is different because FAT is is a bit strange. fat_update_time does extra truncation on the timestamp that it is handed beyond what timestamp_truncate() does. fat_truncate_time is called in many different places too, so I don't feel comfortable making big changes to how that works.
In the case of generic_update_time, it calls inode_update_timestamps which returns a mask that shows which timestamps got updated. It then marks the dirty_flags appropriately for what was actually changed.
generic_update_time is used across many filesystems so we need to ensure that it's OK to use even when multigrain timestamps are enabled. Those haven't been enabled in FAT though, so I didn't bother, and left it to dirtying the inode in the same way it was before, even though it now fetches its own timestamps from the clock. Given the way that the mtime and ctime are smooshed together in FAT, that seemed reasonable.
Is there a particular case or flag combination you're concerned about here?
Signature · 1 line
Jeff Layton <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 2 lines · Jeff Layton
Quoted 1 line · OGAWA Hirofumi
Jan Kara <[email protected]> writes:
[...]
Quoted 2 lines
My mistake re: lazytime vs. relatime, but Jan is correct that this shouldn't break anything there.
Actually breaks ("break" means not corrupt fs, means it breaks lazytime optimization). It is just not always, but it should be always for some userspaces.
Quoted 17 lines
The logic in the revised
generic_update_timeis different because FAT is is a bit strange.fat_update_timedoes extra truncation on the timestamp that it is handed beyond whattimestamp_truncate()does.fat_truncate_timeis called in many different places too, so I don't feel comfortable making big changes to how that works.In the case of
generic_update_time, it callsinode_update_timestampswhich returns a mask that shows which timestamps got updated. It then marks thedirty_flagsappropriately for what was actually changed.
generic_update_timeis used across many filesystems so we need to ensure that it's OK to use even when multigrain timestamps are enabled. Those haven't been enabled in FAT though, so I didn't bother, and left it to dirtying the inode in the same way it was before, even though it now fetches its own timestamps from the clock. Given the way that the mtime and ctime are smooshed together in FAT, that seemed reasonable.
Quoted 2 lines
Is there a particular case or flag combination you're concerned about here?
Yes. Because FAT has strange timestamps that different granularity on disk . This is why generic time truncation doesn't work for FAT.
Well anyway, my concern is the only following part. In generic_update_time(), S_[CM]TIME are not the cause of I_DIRTY_SYNC if lazytime mode.
- if ((flags & S_VERSION) && inode_maybe_inc_iversion(inode, false))
+ if ((flags & (S_VERSION|S_CTIME|S_MTIME)) && inode_maybe_inc_iversion(inode, false))
dirty_flags |= I_DIRTY_SYNC;
If reverted this part to check only S_VERSION, I'm fine.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 43 lines · OGAWA Hirofumi
Quoted 2 lines · Jeff Layton
Quoted 1 line · OGAWA Hirofumi
Jan Kara <[email protected]> writes:
[...]
Quoted 2 lines
My mistake re: lazytime vs. relatime, but Jan is correct that this shouldn't break anything there.
Actually breaks ("break" means not corrupt fs, means it breaks lazytime optimization). It is just not always, but it should be always for some userspaces.
Quoted 17 lines
The logic in the revised
generic_update_timeis different because FAT is is a bit strange.fat_update_timedoes extra truncation on the timestamp that it is handed beyond whattimestamp_truncate()does.fat_truncate_timeis called in many different places too, so I don't feel comfortable making big changes to how that works.In the case of
generic_update_time, it callsinode_update_timestampswhich returns a mask that shows which timestamps got updated. It then marks thedirty_flagsappropriately for what was actually changed.
generic_update_timeis used across many filesystems so we need to ensure that it's OK to use even when multigrain timestamps are enabled. Those haven't been enabled in FAT though, so I didn't bother, and left it to dirtying the inode in the same way it was before, even though it now fetches its own timestamps from the clock. Given the way that the mtime and ctime are smooshed together in FAT, that seemed reasonable.Quoted 2 lines
Is there a particular case or flag combination you're concerned about here?
Yes. Because FAT has strange timestamps that different granularity on disk . This is why generic time truncation doesn't work for FAT.
Well anyway, my concern is the only following part. In
generic_update_time(), S_[CM]TIME are not the cause ofI_DIRTY_SYNCif lazytime mode.(quoted diff) +1
-1- if ((flags & S_VERSION) && inode_maybe_inc_iversion(inode, false)) + if ((flags & (S_VERSION|S_CTIME|S_MTIME)) && inode_maybe_inc_iversion(inode, false))
Quoted 2 lines
dirty_flags |= I_DIRTY_SYNC;
That would be wrong. The problem is that we're changing how update_time works:
Previously, update_time was given a timestamp and a set of S_* flags to indicate which fields should be updated. Now, update_time is not given a timestamp. It needs to fetch it itself, but that subtly changes the meaning of the flags field.
It now means "these fields needed to be updated when I last checked". The timestamp and i_version may now be different from when the flags field was set. This means that if any of S_CTIME/S_MTIME/S_VERSION were set that we need to attempt to update all 3 of them. They may now be different from the timestamp or version that we ultimately end up with.
The above may look to you like it would always cause I_DIRTY_SYNC to be set on any ctime or mtime update, but inode_maybe_inc_iversion only returns true if it actually updated i_version, and it only does that if someone issued a ->getattr against the file since the last time it was updated.
So, this shouldn't generate any more DIRTY_SYNC updates than it did before.
Signature · 1 line
Jeff Layton <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 17 lines · Jeff Layton
Quoted 2 lines · OGAWA Hirofumi
Jeff Layton <[email protected]> writes:
That would be wrong. The problem is that we're changing how
update_timeworks:Previously,
update_timewas given a timestamp and a set of S_* flags to indicate which fields should be updated. Now,update_timeis not given a timestamp. It needs to fetch it itself, but that subtly changes the meaning of the flags field.It now means "these fields needed to be updated when I last checked". The timestamp and
i_versionmay now be different from when the flags field was set. This means that if any of S_CTIME/S_MTIME/S_VERSION were set that we need to attempt to update all 3 of them. They may now be different from the timestamp or version that we ultimately end up with.
Quoted 8 lines
The above may look to you like it would always cause
I_DIRTY_SYNCto be set on any ctime or mtime update, butinode_maybe_inc_iversiononly returns true if it actually updatedi_version, and it only does that if someone issued a ->getattr against the file since the last time it was updated.So, this shouldn't generate any more
DIRTY_SYNCupdates than it did before.
Again, if you claim so, why generic_update_time() doesn't work same? Why only FAT does?
Or I'm misreading generic_update_time() patch?
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 25 lines · OGAWA Hirofumi
Quoted 23 lines · Jeff Layton
Quoted 2 lines · OGAWA Hirofumi
Jeff Layton <[email protected]> writes:
That would be wrong. The problem is that we're changing how
update_timeworks:Previously,
update_timewas given a timestamp and a set of S_* flags to indicate which fields should be updated. Now,update_timeis not given a timestamp. It needs to fetch it itself, but that subtly changes the meaning of the flags field.It now means "these fields needed to be updated when I last checked". The timestamp and
i_versionmay now be different from when the flags field was set. This means that if any of S_CTIME/S_MTIME/S_VERSION were set that we need to attempt to update all 3 of them. They may now be different from the timestamp or version that we ultimately end up with.The above may look to you like it would always cause
I_DIRTY_SYNCto be set on any ctime or mtime update, butinode_maybe_inc_iversiononly returns true if it actually updatedi_version, and it only does that if someone issued a ->getattr against the file since the last time it was updated.
Quoted 8 lines
Quoted 2 lines
So, this shouldn't generate any more
DIRTY_SYNCupdates than it did before.Again, if you claim so, why
generic_update_time()doesn't work same? Why only FAT does?Or I'm misreading
generic_update_time()patch?
When you say it "doesn't work the same", what do you mean, specifically? I had to make some allowances for the fact that FAT is substantially different in its timestamp handling, and I tried to preserve existing behavior as best I could.
Signature · 1 line
Jeff Layton <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 4 lines · Jeff Layton
When you say it "doesn't work the same", what do you mean, specifically? I had to make some allowances for the fact that FAT is substantially different in its timestamp handling, and I tried to preserve existing behavior as best I could.
Ah, ok. I was misreading some.
inode_update_timestamps() checks IS_I_VERSION() now, not S_VERSION. So, if adding the check of IS_I_VERSION() and (S_MTIME|S_CTIME|S_VERSION) to FAT?
With it, IS_I_VERSION() would be false on FAT, and I'm fine.
I.e. something like
if ((flags & (S_VERSION|S_CTIME|S_MTIME)) && IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, false))
dirty_flags |= I_DIRTY_SYNC;
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 15 lines · OGAWA Hirofumi
Quoted 4 lines · Jeff Layton
When you say it "doesn't work the same", what do you mean, specifically? I had to make some allowances for the fact that FAT is substantially different in its timestamp handling, and I tried to preserve existing behavior as best I could.
Ah, ok. I was misreading some.
inode_update_timestamps()checksIS_I_VERSION()now, notS_VERSION. So, if adding the check ofIS_I_VERSION()and (S_MTIME|S_CTIME|S_VERSION) to FAT?With it,
IS_I_VERSION()would be false on FAT, and I'm fine.
Quoted 7 lines
I.e. something like
if ((flags & (S_VERSION|S_CTIME|S_MTIME)) && IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, false))
dirty_flags|=I_DIRTY_SYNC;Thanks.
If you do that then the i_version counter would never be incremented. But...I think I see what you're getting at.
Most filesystems that support the i_version counter have an on-disk field for it. FAT obviously has no such thing. I suspect the i_version bits in fat_update_time were added by mistake. FAT doesn't set SB_I_VERSION so there's no need to do anything to the i_version field at all.
Also, given that the mtime and ctime are always kept in sync on FAT, we're probably fine to have it look something like this:
--------------------8<------------------ int fat_update_time(struct inode *inode, int flags)
{
int dirty_flags = 0;
if (inode->i_ino == MSDOS_ROOT_INO)
return 0;
fat_truncate_time(inode, NULL, flags);
if (inode->i_sb->s_flags & SB_LAZYTIME)
dirty_flags |= I_DIRTY_TIME;
else
dirty_flags |= I_DIRTY_SYNC;
__mark_inode_dirty(inode, dirty_flags);
return 0;
} --------------------8<------------------
...and we should probably do that in a separate patch in advance of the update_time rework, since it's really a different change.
If you're in agreement, then I'll plan to respin the series with this fixed and resend.
Thanks for being patient!
Signature · 1 line
Jeff Layton <[email protected]>
OGAWA Hirofumi
maintainerRe: [PATCH v7 05/13] fat: make fat_update_time get its own timestamp
Quoted 11 lines · Jeff Layton
If you do that then the
i_versioncounter would never be incremented. But...I think I see what you're getting at.Most filesystems that support the
i_versioncounter have an on-disk field for it. FAT obviously has no such thing. I suspect thei_versionbits infat_update_timewere added by mistake. FAT doesn't setSB_I_VERSIONso there's no need to do anything to thei_versionfield at all.Also, given that the mtime and ctime are always kept in sync on FAT, we're probably fine to have it look something like this:
Yes.
IIRC, when I wrote, I decided to make it keep similar with generic function, instead of heavily customize for FAT (for maintenance reason). It is why. There would be other places with same reason.
E.g. LAZYTIME check is same reason too. (current FAT doesn't support it)
So I personally I would prefer to leave it. But if you want to remove it, it would be ok too.
Thanks.
Quoted 26 lines
--------------------8<------------------ int
fat_update_time(struct inode *inode, int flags){ int dirty_flags = 0; if (inode->i_ino == MSDOS_ROOT_INO) return 0; fat_truncate_time(inode, NULL, flags); if (inode->i_sb->s_flags & SB_LAZYTIME) dirty_flags |= I_DIRTY_TIME; else dirty_flags |= I_DIRTY_SYNC; __mark_inode_dirty(inode, dirty_flags); return 0; }--------------------8<------------------
...and we should probably do that in a separate patch in advance of the
update_timerework, since it's really a different change.If you're in agreement, then I'll plan to respin the series with this fixed and resend.
Thanks for being patient!
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Jeff Layton
maintainerPATCH v7 6/13 ubifs: have ubifs_update_time use inode_update_timestamps
In reply to Jeff LaytonIn later patches, we're going to drop the "now" parameter from the update_time operation. Prepare ubifs for this, by having it use the new inode_update_timestamps helper.
--- fs/ubifs/file.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
fs/ubifs/file.c +2 -8
@@ -1397,15 +1397,9 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time,return err;mutex_lock (&ui->ui_mutex); -if (flags &S_ATIME ) - inode->i_atime = *time; -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *time); -if (flags &S_MTIME ) - inode->i_mtime = *time; - - release = ui->dirty; +inode_update_timestamps (inode, flags);__mark_inode_dirty (inode,I_DIRTY_SYNC ); + release = ui->dirty;mutex_unlock (&ui->ui_mutex);if (release)ubifs_release_budget (c, &req);
Signature · 1 line
2.41.0
Jan Kara
reviewerRe: [PATCH v7 06/13] ubifs: have ubifs_update_time use inode_update_timestamps
Quoted 5 lines · Jeff Layton
In later patches, we're going to drop the "now" parameter from the
update_timeoperation. Prepare ubifs for this, by having it use the newinode_update_timestampshelper.Signed-off-by Jeff Layton <[email protected]>
One comment below:
Quoted 10 lines
fs/ubifs/file.c +0
-2@@ -1397,15 +1397,9 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time,return err;mutex_lock (&ui->ui_mutex); -if (flags &S_ATIME ) - inode->i_atime = *time;
fs/ubifs/file.c int ubifs_update_time(struct inode *inode, struct timespec64 *time, · line 1403
Quoted 10 lines
fs/ubifs/file.c +2
-6-if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *time); -if (flags &S_MTIME ) - inode->i_mtime = *time; - - release = ui->dirty; +inode_update_timestamps (inode, flags);__mark_inode_dirty (inode,I_DIRTY_SYNC ); + release = ui->dirty;mutex_unlock (&ui->ui_mutex);
I think this is wrong. You need to keep sampling ui->dirty before calling __mark_inode_dirty(). Otherwise you could release budget for inode update you really need...
fs/ubifs/file.c int ubifs_update_time(struct inode *inode, struct timespec64 *time, · line 1405
Quoted 2 lines
fs/ubifs/file.c +0
-0if (release)ubifs_release_budget (c, &req);
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [PATCH v7 06/13] ubifs: have ubifs_update_time use inode_update_timestamps
Quoted 25 lines · Jan Kara
Quoted 5 lines · Jeff Layton
In later patches, we're going to drop the "now" parameter from the
update_timeoperation. Prepare ubifs for this, by having it use the newinode_update_timestampshelper.Signed-off-by Jeff Layton <[email protected]>One comment below:
Quoted 16 lines
fs/ubifs/file.c +0
-8@@ -1397,15 +1397,9 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time,return err;mutex_lock (&ui->ui_mutex); -if (flags &S_ATIME ) - inode->i_atime = *time; -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *time); -if (flags &S_MTIME ) - inode->i_mtime = *time; - - release = ui->dirty;
Quoted 8 lines
fs/ubifs/file.c int ubifs_update_time(struct inode *inode, struct timespec64 *time, · line 1403
Quoted 4 lines
fs/ubifs/file.c +2
-0+inode_update_timestamps (inode, flags);__mark_inode_dirty (inode,I_DIRTY_SYNC ); + release = ui->dirty;mutex_unlock (&ui->ui_mutex);I think this is wrong. You need to keep sampling
ui->dirtybefore calling__mark_inode_dirty(). Otherwise you could release budget for inode update you really need...
Fixed in-tree.
Re: [PATCH v7 06/13] ubifs: have ubifs_update_time use inode_update_timestamps
Quoted 35 lines · Christian Brauner
Quoted 25 lines · Jan Kara
Quoted 5 lines · Jeff Layton
In later patches, we're going to drop the "now" parameter from the
update_timeoperation. Prepare ubifs for this, by having it use the newinode_update_timestampshelper.Signed-off-by Jeff Layton <[email protected]>One comment below:
Quoted 16 lines
fs/ubifs/file.c +0
-8@@ -1397,15 +1397,9 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time,return err;mutex_lock (&ui->ui_mutex); -if (flags &S_ATIME ) - inode->i_atime = *time; -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *time); -if (flags &S_MTIME ) - inode->i_mtime = *time; - - release = ui->dirty;Quoted 8 lines
fs/ubifs/file.c int ubifs_update_time(struct inode *inode, struct timespec64 *time, · line 1403
Quoted 4 lines
fs/ubifs/file.c +2
-0+inode_update_timestamps (inode, flags);__mark_inode_dirty (inode,I_DIRTY_SYNC ); + release = ui->dirty;mutex_unlock (&ui->ui_mutex);I think this is wrong. You need to keep sampling
ui->dirtybefore calling__mark_inode_dirty(). Otherwise you could release budget for inode update you really need...
Quoted 1 line
Fixed in-tree.
Thanks. With that feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerPATCH v7 7/13 xfs: have xfs_vn_update_time gets its own timestamp
In reply to Jeff LaytonIn later patches we're going to drop the "now" parameter from the update_time operation. Prepare XFS for this by reworking how it fetches timestamps and sets them in the inode. Ensure that we update the ctime even if only S_MTIME is set.
--- fs/xfs/xfs_iops.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/xfs/xfs_iops.c +8 -4
@@ -1037,6 +1037,7 @@ xfs_vn_update_time(int log_flags =XFS_ILOG_TIMESTAMP ;struct xfs_trans *tp;int error; +struct timespec64 now =current_time (inode);trace_xfs_update_time (ip);
@@ -1056,12 +1057,15 @@ xfs_vn_update_time(return error;xfs_ilock (ip,XFS_ILOCK_EXCL ); -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *now); +if (flags & (S_CTIME |S_MTIME )) + now =inode_set_ctime_current (inode); +else + now =current_time (inode); +if (flags &S_MTIME ) - inode->i_mtime = *now; + inode->i_mtime = now;if (flags &S_ATIME ) - inode->i_atime = *now; + inode->i_atime = now;xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_trans_log_inode (tp, ip, log_flags);
Signature · 1 line
2.41.0
Re: [PATCH v7 07/13] xfs: have xfs_vn_update_time gets its own timestamp
Quoted 15 lines · Jeff Layton
In later patches we're going to drop the "now" parameter from the
update_timeoperation. Prepare XFS for this by reworking how it fetches timestamps and sets them in the inode. Ensure that we update the ctime even if onlyS_MTIMEis set.Signed-off-by Jeff Layton <[email protected]>--- fs/xfs/xfs_iops.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)fs/xfs/xfs_iops.c +0
-0
fs/xfs/xfs_iops.c xfs_vn_update_time( · line 1040
Quoted 4 lines
fs/xfs/xfs_iops.c +1
-0@@ -1037,6 +1037,7 @@ xfs_vn_update_time(int log_flags =XFS_ILOG_TIMESTAMP ;struct xfs_trans *tp;int error; +struct timespec64 now =current_time (inode);
No need to fetch current_time() here where you overwrite it just a bit later...
Quoted 10 lines
fs/xfs/xfs_iops.c +4
-2@@ -1056,12 +1057,15 @@ xfs_vn_update_time(return error;xfs_ilock (ip,XFS_ILOCK_EXCL ); -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *now); +if (flags & (S_CTIME |S_MTIME )) + now =inode_set_ctime_current (inode); +else + now =current_time (inode);
fs/xfs/xfs_iops.c xfs_vn_update_time( · line 1071
Quoted 10 lines
fs/xfs/xfs_iops.c +3
-2+if (flags &S_MTIME ) - inode->i_mtime = *now; + inode->i_mtime = now;if (flags &S_ATIME ) - inode->i_atime = *now; + inode->i_atime = now;xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_trans_log_inode (tp, ip, log_flags);
Otherwise the patch looks good to me so feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [PATCH v7 07/13] xfs: have xfs_vn_update_time gets its own timestamp
Quoted 11 lines · Jan Kara
Quoted 10 lines · Jeff Layton
In later patches we're going to drop the "now" parameter from the
update_timeoperation. Prepare XFS for this by reworking how it fetches timestamps and sets them in the inode. Ensure that we update the ctime even if onlyS_MTIMEis set.Signed-off-by Jeff Layton <[email protected]>--- fs/xfs/xfs_iops.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
Quoted 12 lines
fs/xfs/xfs_iops.c xfs_vn_update_time( · line 1040
Quoted 9 lines
fs/xfs/xfs_iops.c +1
-0@@ -1037,6 +1037,7 @@ xfs_vn_update_time(int log_flags =XFS_ILOG_TIMESTAMP ;struct xfs_trans *tp;int error; +struct timespec64 now =current_time (inode);No need to fetch
current_time()here where you overwrite it just a bit later...
It also shadows the @now parameter of that function. Since that function parameter is dropped in follow-up patches I simply s/now/time/g it here. In any case, fixed in-tree.
Re: [PATCH v7 07/13] xfs: have xfs_vn_update_time gets its own timestamp
In reply to Jeff LaytonQuoted 23 lines · Jeff Layton
In later patches we're going to drop the "now" parameter from the
update_timeoperation. Prepare XFS for this by reworking how it fetches timestamps and sets them in the inode. Ensure that we update the ctime even if onlyS_MTIMEis set.Signed-off-by Jeff Layton <[email protected]>--- fs/xfs/xfs_iops.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)fs/xfs/xfs_iops.c +1
-0@@ -1037,6 +1037,7 @@ xfs_vn_update_time(int log_flags =XFS_ILOG_TIMESTAMP ;struct xfs_trans *tp;int error; +struct timespec64 now =current_time (inode);trace_xfs_update_time (ip);
fs/xfs/xfs_iops.c xfs_vn_update_time( · line 1060
Quoted 6 lines
fs/xfs/xfs_iops.c +1
-2@@ -1056,12 +1057,15 @@ xfs_vn_update_time(return error;xfs_ilock (ip,XFS_ILOCK_EXCL ); -if (flags &S_CTIME ) -inode_set_ctime_to_ts (inode, *now); +if (flags & (S_CTIME |S_MTIME ))
Minor nit: spaces around ^ the operator.
Otherwise looks ok to me...
--D
Quoted 17 lines
fs/xfs/xfs_iops.c +6
-2+ now =inode_set_ctime_current (inode); + else + now =current_time (inode); +if (flags &S_MTIME ) - inode->i_mtime = *now; + inode->i_mtime = now;if (flags &S_ATIME ) - inode->i_atime = *now; + inode->i_atime = now;xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_trans_log_inode (tp, ip, log_flags);Signature · 2 lines
-- 2.41.0
Jeff Layton
maintainerPATCH v7 8/13 fs: drop the timespec64 argument from update_time
In reply to Jeff LaytonNow that all of the update_time operations are prepared for it, we can drop the timespec64 argument from the update_time operation. Do that and remove it from some associated functions like inode_update_time and inode_needs_update_time.
--- fs/bad_inode.c | 3 +-- fs/btrfs/inode.c | 3 +-- fs/btrfs/volumes.c | 4 +--- fs/fat/fat.h | 3 +-- fs/fat/misc.c | 2 +- fs/gfs2/inode.c | 3 +-- fs/inode.c | 30 +++++++++++++----------------- fs/overlayfs/inode.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/ubifs/file.c | 3 +-- fs/ubifs/ubifs.h | 2 +- fs/xfs/xfs_iops.c | 1 - include/linux/fs.h | 4 ++-- 13 files changed, 25 insertions(+), 37 deletions(-)
fs/bad_inode.c +1 -2
@@ -133,8 +133,7 @@ static int bad_inode_fiemap(struct inode *inode,return -EIO ; } -static int bad_inode_update_time (struct inode *inode,struct timespec64 *time, -int flags) +static int bad_inode_update_time (struct inode *inode,int flags) {return -EIO ; }
fs/btrfs/inode.c +1 -2
@@ -6059,8 +6059,7 @@ static int btrfs_dirty_inode(struct btrfs_inode *inode)* This is a copy of file_update_time. We need this so we can return error on * ENOSPC for updating the inode in the case of file write and mmap writes. */ -static int btrfs_update_time (struct inode *inode,struct timespec64 *now, -int flags) +static int btrfs_update_time (struct inode *inode,int flags) {struct btrfs_root *root =BTRFS_I (inode)->root;bool dirty = flags & ~S_VERSION ;
fs/btrfs/volumes.c +1 -3
@@ -1917,15 +1917,13 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,static void update_dev_time (const char *device_path) {struct path path; -struct timespec64 now;int ret; ret =kern_path (device_path,LOOKUP_FOLLOW , &path);if (ret)return ; - now =current_time (d_inode (path.dentry)); -inode_update_time (d_inode (path.dentry), &now,S_MTIME |S_CTIME |S_VERSION ); +inode_update_time (d_inode (path.dentry),S_MTIME |S_CTIME |S_VERSION );path_put (&path); }
fs/fat/fat.h +1 -2
@@ -460,8 +460,7 @@ 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); -extern int fat_update_time (struct inode *inode,struct timespec64 *now, -int flags); +extern int fat_update_time (struct inode *inode,int flags);extern int fat_sync_bhs (struct buffer_head **bhs,int nr_bhs);int fat_cache_init (void );
fs/fat/misc.c +1 -1
@@ -339,7 +339,7 @@ int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags) }EXPORT_SYMBOL_GPL (fat_truncate_time); -int fat_update_time (struct inode *inode,struct timespec64 *now,int flags) +int fat_update_time (struct inode *inode,int flags) {int dirty_flags =0 ;
fs/gfs2/inode.c +1 -2
@@ -2139,8 +2139,7 @@ loff_t gfs2_seek_hole(struct file *file, loff_t offset)return vfs_setpos (file, ret, inode->i_sb->s_maxbytes); } -static int gfs2_update_time (struct inode *inode,struct timespec64 *time, -int flags) +static int gfs2_update_time (struct inode *inode,int flags) {struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_glock *gl = ip->i_gl;
fs/inode.c +13 -17
@@ -1958,10 +1958,10 @@ 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,struct timespec64 *time,int flags) +int inode_update_time (struct inode *inode,int flags) {if (inode->i_op->update_time) -return inode->i_op->update_time (inode, time, flags); +return inode->i_op->update_time (inode, flags);generic_update_time (inode, flags);return 0 ; }
@@ -2015,7 +2015,6 @@ void touch_atime(const struct path *path) {struct vfsmount *mnt = path->mnt;struct inode *inode =d_inode (path->dentry); -struct timespec64 now;if (!atime_needs_update (path, inode))return ;
@@ -2034,8 +2033,7 @@ 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. */ - now =current_time (inode); -inode_update_time (inode, &now,S_ATIME ); +inode_update_time (inode,S_ATIME );__mnt_drop_write (mnt); skip_update:sb_end_write (inode->i_sb);
@@ -2120,20 +2118,21 @@ int file_remove_privs(struct file *file) }EXPORT_SYMBOL (file_remove_privs); -static int inode_needs_update_time (struct inode *inode,struct timespec64 *now) +static int inode_needs_update_time (struct inode *inode) {int sync_it =0 ; +struct timespec64 now =current_time (inode);struct timespec64 ctime;/* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME (inode))return 0 ; -if (!timespec64_equal (&inode->i_mtime, now)) +if (!timespec64_equal (&inode->i_mtime, &now)) sync_it =S_MTIME ; ctime =inode_get_ctime (inode); -if (!timespec64_equal (&ctime, now)) +if (!timespec64_equal (&ctime, &now)) sync_it |=S_CTIME ;if (IS_I_VERSION (inode) &&inode_iversion_need_inc (inode))
@@ -2142,15 +2141,14 @@ static int inode_needs_update_time(struct inode *inode, struct timespec64 *now)return sync_it; } -static int __file_update_time (struct file *file,struct timespec64 *now, -int sync_mode) +static int __file_update_time (struct file *file,int sync_mode) {int ret =0 ;struct inode *inode =file_inode (file);/* try to update time settings */ if (!__mnt_want_write_file (file)) { - ret =inode_update_time (inode, now, sync_mode); + ret =inode_update_time (inode, sync_mode);__mnt_drop_write_file (file); }
@@ -2175,13 +2173,12 @@ int file_update_time(struct file *file) {int ret;struct inode *inode =file_inode (file); -struct timespec64 now =current_time (inode); - ret =inode_needs_update_time (inode, &now); + ret =inode_needs_update_time (inode);if (ret <=0 )return ret; -return __file_update_time (file, &now, ret); +return __file_update_time (file, ret); }EXPORT_SYMBOL (file_update_time);
@@ -2204,7 +2201,6 @@ static int file_modified_flags(struct file *file, int flags) {int ret;struct inode *inode =file_inode (file); -struct timespec64 now =current_time (inode);/* * Clear the security bits if the process is not being run by root.
@@ -2217,13 +2213,13 @@ static int file_modified_flags(struct file *file, int flags)if (unlikely (file->f_mode &FMODE_NOCMTIME ))return 0 ; - ret =inode_needs_update_time (inode, &now); + ret =inode_needs_update_time (inode);if (ret <=0 )return ret;if (flags &IOCB_NOWAIT )return -EAGAIN ; -return __file_update_time (file, &now, ret); +return __file_update_time (file, ret); }/**
fs/overlayfs/inode.c +1 -1
@@ -693,7 +693,7 @@ int ovl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, }#endif -int ovl_update_time (struct inode *inode,struct timespec64 *ts,int flags) +int ovl_update_time (struct inode *inode,int flags) {if (flags &S_ATIME ) {struct ovl_fs *ofs = inode->i_sb->s_fs_info;
fs/overlayfs/overlayfs.h +1 -1
@@ -665,7 +665,7 @@ static inline struct posix_acl *ovl_get_acl_path(const struct path *path, }#endif -int ovl_update_time (struct inode *inode,struct timespec64 *ts,int flags); +int ovl_update_time (struct inode *inode,int flags);bool ovl_is_private_xattr (struct super_block *sb,const char *name);struct ovl_inode_params {
fs/ubifs/file.c +1 -2
@@ -1378,8 +1378,7 @@ static inline int mctime_update_needed(const struct inode *inode,* * This function updates time of the inode. */ -int ubifs_update_time (struct inode *inode,struct timespec64 *time, -int flags) +int ubifs_update_time (struct inode *inode,int flags) {struct ubifs_inode *ui =ubifs_inode (inode);struct ubifs_info *c = inode->i_sb->s_fs_info;
fs/ubifs/ubifs.h +1 -1
@@ -2027,7 +2027,7 @@ int ubifs_calc_dark(const struct ubifs_info *c, int spc);int ubifs_fsync (struct file *file,loff_t start,loff_t end,int datasync);int ubifs_setattr (struct mnt_idmap *idmap,struct dentry *dentry,struct iattr *attr); -int ubifs_update_time (struct inode *inode,struct timespec64 *time,int flags); +int ubifs_update_time (struct inode *inode,int flags);/* dir.c */ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
fs/xfs/xfs_iops.c +0 -1
@@ -1029,7 +1029,6 @@ xfs_vn_setattr( STATIC intxfs_vn_update_time (struct inode *inode, -struct timespec64 *now,int flags) {struct xfs_inode *ip =XFS_I (inode);
include/linux/fs.h +2 -2
@@ -1887,7 +1887,7 @@ struct inode_operations {ssize_t (*listxattr) (struct dentry *,char *,size_t );int (*fiemap)(struct inode *,struct fiemap_extent_info *,u64 start,u64 len); -int (*update_time)(struct inode *,struct timespec64 *,int ); +int (*update_time)(struct inode *,int );int (*atomic_open)(struct inode *,struct dentry *,struct file *,unsigned open_flag,umode_t create_mode);
@@ -2237,7 +2237,7 @@ 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,struct timespec64 *time,int flags); +int inode_update_time (struct inode *inode,int flags);static inline void file_accessed (struct file *file) {
Signature · 1 line
2.41.0
Re: [PATCH v7 08/13] fs: drop the timespec64 argument from update_time
Quoted 6 lines · Jeff Layton
Now that all of the
update_timeoperations are prepared for it, we can drop the timespec64 argument from theupdate_timeoperation. Do that and remove it from some associated functions likeinode_update_timeandinode_needs_update_time.Signed-off-by Jeff Layton <[email protected]>
Looks good to me. Feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [PATCH v7 08/13] fs: drop the timespec64 argument from update_time
In reply to Jeff LaytonQuoted 6 lines · Jeff Layton
Now that all of the
update_timeoperations are prepared for it, we can drop the timespec64 argument from theupdate_timeoperation. Do that and remove it from some associated functions likeinode_update_timeandinode_needs_update_time.Signed-off-by Jeff Layton <[email protected]>
Quoted 14 lines
--- fs/bad_inode.c | 3 +-- fs/btrfs/inode.c | 3 +-- fs/btrfs/volumes.c | 4 +--- fs/fat/fat.h | 3 +-- fs/fat/misc.c | 2 +- fs/gfs2/inode.c | 3 +-- fs/inode.c | 30 +++++++++++++----------------- fs/overlayfs/inode.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/ubifs/file.c | 3 +-- fs/ubifs/ubifs.h | 2 +- fs/xfs/xfs_iops.c | 1 - include/linux/fs.h | 4 ++--
This was missing the conversion of fs/orangefs orangefs_update_time() causing the build to fail. So at some point kbuild will yell here. Fwiw, I've fixed that up in-tree.
Mike Marshall
maintainerRe: [PATCH v7 08/13] fs: drop the timespec64 argument from update_time
I've been following this patch on fsdevel... is there a remote I could fetch with a branch that has this in it?
-Mike
Quoted 26 lines · Christian Brauner
Quoted 6 lines · Jeff Layton
Now that all of the
update_timeoperations are prepared for it, we can drop the timespec64 argument from theupdate_timeoperation. Do that and remove it from some associated functions likeinode_update_timeandinode_needs_update_time.Signed-off-by Jeff Layton <[email protected]>Quoted 14 lines
--- fs/bad_inode.c | 3 +-- fs/btrfs/inode.c | 3 +-- fs/btrfs/volumes.c | 4 +--- fs/fat/fat.h | 3 +-- fs/fat/misc.c | 2 +- fs/gfs2/inode.c | 3 +-- fs/inode.c | 30 +++++++++++++----------------- fs/overlayfs/inode.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/ubifs/file.c | 3 +-- fs/ubifs/ubifs.h | 2 +- fs/xfs/xfs_iops.c | 1 - include/linux/fs.h | 4 ++--This was missing the conversion of fs/orangefs
orangefs_update_time()causing the build to fail. So at some point kbuild will yell here. Fwiw, I've fixed that up in-tree.
Jeff Layton
maintainerRe: [PATCH v7 08/13] fs: drop the timespec64 argument from update_time
Yes. It's in Christian's vfs.ctime branch:
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=vfs.ctime
Quoted 32 lines · Mike Marshall
I've been following this patch on fsdevel... is there a remote I could fetch with a branch that has this in it?
-Mike
Quoted 26 lines · Christian Brauner
Quoted 6 lines · Jeff Layton
Now that all of the
update_timeoperations are prepared for it, we can drop the timespec64 argument from theupdate_timeoperation. Do that and remove it from some associated functions likeinode_update_timeandinode_needs_update_time.Signed-off-by Jeff Layton <[email protected]>Quoted 14 lines
--- fs/bad_inode.c | 3 +-- fs/btrfs/inode.c | 3 +-- fs/btrfs/volumes.c | 4 +--- fs/fat/fat.h | 3 +-- fs/fat/misc.c | 2 +- fs/gfs2/inode.c | 3 +-- fs/inode.c | 30 +++++++++++++----------------- fs/overlayfs/inode.c | 2 +- fs/overlayfs/overlayfs.h | 2 +- fs/ubifs/file.c | 3 +-- fs/ubifs/ubifs.h | 2 +- fs/xfs/xfs_iops.c | 1 - include/linux/fs.h | 4 ++--This was missing the conversion of fs/orangefs
orangefs_update_time()causing the build to fail. So at some point kbuild will yell here. Fwiw, I've fixed that up in-tree.
Cheers,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v7 9/13 fs: add infrastructure for multigrain timestamps
In reply to Jeff LaytonThe VFS always uses coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes.
Unfortunately, this has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide to invalidate the cache. Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problems with timestamp granularity. Other applications have similar issues with timestamps (e.g backup applications).
If we were to always use fine-grained timestamps, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates.
What we need is a way to only use fine-grained timestamps when they are being actively queried.
POSIX generally mandates that when the the mtime changes, the ctime must also change. The kernel always stores normalized ctime values, so only the first 30 bits of the tv_nsec field are ever used.
Use the 31st bit of the ctime tv_nsec field to indicate that something has queried the inode for the mtime or ctime. When this flag is set, on the next mtime or ctime update, the kernel will fetch a fine-grained timestamp instead of the usual coarse-grained one.
Filesytems can opt into this behavior by setting the FS_MGTIME flag in the fstype. Filesystems that don't set this flag will continue to use coarse-grained timestamps.
Later patches will convert individual filesystems to use the new infrastructure.
--- fs/inode.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/stat.c | 41 +++++++++++++++++++++++++-- include/linux/fs.h | 46 ++++++++++++++++++++++++++++-- 3 files changed, 162 insertions(+), 7 deletions(-)
fs/inode.c +79 -3
@@ -2118,10 +2118,52 @@ int file_remove_privs(struct file *file) }EXPORT_SYMBOL (file_remove_privs); +/** +* current_mgtime - Return FS time (possibly fine-grained) +* @inode: inode. +* +* Return the current time truncated to the time granularity supported by +* the fs, as suitable for a ctime/mtime change. If the ctime is flagged +* as having been QUERIED, get a fine-grained timestamp. +*/ +struct timespec64 current_mgtime (struct inode *inode) +{ +struct timespec64 now, ctime; +atomic_long_t *pnsec = (atomic_long_t *)&inode->__i_ctime.tv_nsec; +long nsec =atomic_long_read (pnsec); + +if (nsec &I_CTIME_QUERIED ) { +ktime_get_real_ts64 (&now); +return timestamp_truncate (now, inode); + } + +ktime_get_coarse_real_ts64 (&now); + now =timestamp_truncate (now, inode); + +/* +* If we've recently fetched a fine-grained timestamp +* then the coarse-grained one may still be earlier than the +* existing ctime. Just keep the existing value if so. +*/ + ctime =inode_get_ctime (inode); +if (timespec64_compare (&ctime, &now) >0 ) + now = ctime; + +return now; +} +EXPORT_SYMBOL (current_mgtime); + +static struct timespec64 current_ctime (struct inode *inode) +{ +if (is_mgtime (inode)) +return current_mgtime (inode); +return current_time (inode); +} +static int inode_needs_update_time (struct inode *inode) {int sync_it =0 ; -struct timespec64 now =current_time (inode); +struct timespec64 now =current_ctime (inode);struct timespec64 ctime;/* First try to exhaust all avenues to not sync */
@@ -2552,9 +2594,43 @@ EXPORT_SYMBOL(current_time);*/ struct timespec64 inode_set_ctime_current (struct inode *inode) { -struct timespec64 now =current_time (inode); +struct timespec64 now; +struct timespec64 ctime; + + ctime.tv_nsec =READ_ONCE (inode->__i_ctime.tv_nsec); +if (!(ctime.tv_nsec &I_CTIME_QUERIED )) { + now =current_time (inode); -inode_set_ctime (inode, now.tv_sec, now.tv_nsec); +/* Just copy it into place if it's not multigrain */ +if (!is_mgtime (inode)) { +inode_set_ctime_to_ts (inode, now); +return now; + } + +/* +* If we've recently updated with a fine-grained timestamp, +* then the coarse-grained one may still be earlier than the +* existing ctime. Just keep the existing value if so. +*/ + ctime.tv_sec = inode->__i_ctime.tv_sec; +if (timespec64_compare (&ctime, &now) >0 ) +return ctime; + +/* +* Ctime updates are usually protected by the inode_lock, but +* we can still race with someone setting the QUERIED flag. +* Try to swap the new nsec value into place. If it's changed +* in the interim, then just go with a fine-grained timestamp. +*/ +if (cmpxchg (&inode->__i_ctime.tv_nsec, ctime.tv_nsec, + now.tv_nsec) != ctime.tv_nsec) + goto fine_grained; + inode->__i_ctime.tv_sec = now.tv_sec; +return now; + } +fine_grained: +ktime_get_real_ts64 (&now); +inode_set_ctime_to_ts (inode,timestamp_truncate (now, inode));return now; }EXPORT_SYMBOL (inode_set_ctime_current);
fs/stat.c +39 -2
53 lines not on this page · raw message
include/linux/fs.h +44 -2
80 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v7 09/13] fs: add infrastructure for multigrain timestamps
Quoted 30 lines · Jeff Layton
The VFS always uses coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes.
Unfortunately, this has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide to invalidate the cache. Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problems with timestamp granularity. Other applications have similar issues with timestamps (e.g backup applications).
If we were to always use fine-grained timestamps, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates.
What we need is a way to only use fine-grained timestamps when they are being actively queried.
POSIX generally mandates that when the the mtime changes, the ctime must also change. The kernel always stores normalized ctime values, so only the first 30 bits of the
tv_nsecfield are ever used.Use the 31st bit of the ctime
tv_nsecfield to indicate that something has queried the inode for the mtime or ctime. When this flag is set, on the next mtime or ctime update, the kernel will fetch a fine-grained timestamp instead of the usual coarse-grained one.
Quoted 8 lines
Filesytems can opt into this behavior by setting the
FS_MGTIMEflag in the fstype. Filesystems that don't set this flag will continue to use coarse-grained timestamps.Later patches will convert individual filesystems to use the new infrastructure.
Signed-off-by Jeff Layton <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 261 lines
--- fs/inode.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/stat.c | 41 +++++++++++++++++++++++++-- include/linux/fs.h | 46 ++++++++++++++++++++++++++++-- 3 files changed, 162 insertions(+), 7 deletions(-)fs/inode.c +79
-3@@ -2118,10 +2118,52 @@ int file_remove_privs(struct file *file) }EXPORT_SYMBOL (file_remove_privs); +/** +* current_mgtime - Return FS time (possibly fine-grained) +* @inode: inode. +* +* Return the current time truncated to the time granularity supported by +* the fs, as suitable for a ctime/mtime change. If the ctime is flagged +* as having been QUERIED, get a fine-grained timestamp. +*/ +struct timespec64 current_mgtime (struct inode *inode) +{ +struct timespec64 now, ctime; +atomic_long_t *pnsec = (atomic_long_t *)&inode->__i_ctime.tv_nsec; +long nsec =atomic_long_read (pnsec); + +if (nsec &I_CTIME_QUERIED ) { +ktime_get_real_ts64 (&now); +return timestamp_truncate (now, inode); + } + +ktime_get_coarse_real_ts64 (&now); + now =timestamp_truncate (now, inode); + +/* +* If we've recently fetched a fine-grained timestamp +* then the coarse-grained one may still be earlier than the +* existing ctime. Just keep the existing value if so. +*/ + ctime =inode_get_ctime (inode); +if (timespec64_compare (&ctime, &now) >0 ) + now = ctime; + +return now; +} +EXPORT_SYMBOL (current_mgtime); + +static struct timespec64 current_ctime (struct inode *inode) +{ +if (is_mgtime (inode)) +return current_mgtime (inode); +return current_time (inode); +} +static int inode_needs_update_time (struct inode *inode) {int sync_it =0 ; -struct timespec64 now =current_time (inode); +struct timespec64 now =current_ctime (inode);struct timespec64 ctime;/* First try to exhaust all avenues to not sync */ @@ -2552,9 +2594,43 @@ EXPORT_SYMBOL(current_time);*/ struct timespec64 inode_set_ctime_current (struct inode *inode) { -struct timespec64 now =current_time (inode); +struct timespec64 now; +struct timespec64 ctime; + + ctime.tv_nsec =READ_ONCE (inode->__i_ctime.tv_nsec); +if (!(ctime.tv_nsec &I_CTIME_QUERIED )) { + now =current_time (inode); -inode_set_ctime (inode, now.tv_sec, now.tv_nsec); +/* Just copy it into place if it's not multigrain */ +if (!is_mgtime (inode)) { +inode_set_ctime_to_ts (inode, now); +return now; + } + +/* +* If we've recently updated with a fine-grained timestamp, +* then the coarse-grained one may still be earlier than the +* existing ctime. Just keep the existing value if so. +*/ + ctime.tv_sec = inode->__i_ctime.tv_sec; +if (timespec64_compare (&ctime, &now) >0 ) +return ctime; + +/* +* Ctime updates are usually protected by the inode_lock, but +* we can still race with someone setting the QUERIED flag. +* Try to swap the new nsec value into place. If it's changed +* in the interim, then just go with a fine-grained timestamp. +*/ +if (cmpxchg (&inode->__i_ctime.tv_nsec, ctime.tv_nsec, + now.tv_nsec) != ctime.tv_nsec) + goto fine_grained; + inode->__i_ctime.tv_sec = now.tv_sec; +return now; + } +fine_grained: +ktime_get_real_ts64 (&now); +inode_set_ctime_to_ts (inode,timestamp_truncate (now, inode));return now; }EXPORT_SYMBOL (inode_set_ctime_current);fs/stat.c +39
-2@@ -26,6 +26,37 @@#include "internal.h" #include "mount.h" +/** +* fill_mg_cmtime - Fill in the mtime and ctime and flag ctime as QUERIED +* @stat: where to store the resulting values +* @request_mask: STATX_* values requested +* @inode: inode from which to grab the c/mtime +* +* Given @inode, grab the ctime and mtime out if it and store the result +* in @stat. When fetching the value, flag it as queried so the next write +* will use a fine-grained timestamp. +*/ +void fill_mg_cmtime (struct kstat *stat,u32 request_mask,struct inode *inode) +{ +atomic_long_t *pnsec = (atomic_long_t *)&inode->__i_ctime.tv_nsec; + +/* If neither time was requested, then don't report them */ +if (!(request_mask & (STATX_CTIME |STATX_MTIME ))) { + stat->result_mask &= ~(STATX_CTIME |STATX_MTIME ); +return ; + } + + stat->mtime = inode->i_mtime; + stat->ctime.tv_sec = inode->__i_ctime.tv_sec; +/* +* Atomically set the QUERIED flag and fetch the new value with +* the flag masked off. +*/ + stat->ctime.tv_nsec =atomic_long_fetch_or (I_CTIME_QUERIED , pnsec) & + ~I_CTIME_QUERIED ; +} +EXPORT_SYMBOL (fill_mg_cmtime); +/** * generic_fillattr - Fill in the basic attributes from the inode struct * @idmap: idmap of the mount the inode was found from @@ -58,8 +89,14 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->rdev = inode->i_rdev; stat->size =i_size_read (inode); stat->atime = inode->i_atime; - stat->mtime = inode->i_mtime; - stat->ctime =inode_get_ctime (inode); + +if (is_mgtime (inode)) { +fill_mg_cmtime (stat, request_mask, inode); + }else { + stat->mtime = inode->i_mtime; + stat->ctime =inode_get_ctime (inode); + } + stat->blksize =i_blocksize (inode); stat->blocks = inode->i_blocks;include/linux/fs.h +44
-2@@ -1474,18 +1474,47 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb,kgid_has_mapping (fs_userns, kgid); } +struct timespec64 current_mgtime (struct inode *inode);struct timespec64 current_time (struct inode *inode);struct timespec64 inode_set_ctime_current (struct inode *inode); +/* +* Multigrain timestamps +* +* Conditionally use fine-grained ctime and mtime timestamps when there +* are users actively observing them via getattr. The primary use-case +* for this is NFS clients that use the ctime to distinguish between +* different states of the file, and that are often fooled by multiple +* operations that occur in the same coarse-grained timer tick. +* +* The kernel always keeps normalized struct timespec64 values in the ctime, +* which means that only the first 30 bits of the value are used. Use the +* 31st bit of the ctime's tv_nsec field as a flag to indicate that the value +* has been queried since it was last updated. +*/ +#define I_CTIME_QUERIED (1L<<30) +/** * inode_get_ctime - fetch the current ctime from the inode * @inode: inode from which to fetch ctime * -* Grab the current ctime from the inode and return it. +* Grab the current ctime tv_nsec field from the inode, mask off the +* I_CTIME_QUERIED flag and return it. This is mostly intended for use by +* internal consumers of the ctime that aren't concerned with ensuring a +* fine-grained update on the next change (e.g. when preparing to store +* the value in the backing store for later retrieval). +* +* This is safe to call regardless of whether the underlying filesystem +* is using multigrain timestamps. */ static inline struct timespec64 inode_get_ctime (const struct inode *inode) { -return inode->__i_ctime; +struct timespec64 ctime; + + ctime.tv_sec = inode->__i_ctime.tv_sec; + ctime.tv_nsec = inode->__i_ctime.tv_nsec & ~I_CTIME_QUERIED ; + +return ctime; }/** @@ -2259,6 +2288,7 @@ struct file_system_type {#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM 16/* Disable fanotify permission events */ #define FS_ALLOW_IDMAP 32/* FS has been updated to handle vfs idmappings. */ +#define FS_MGTIME 64/* FS uses multigrain timestamps */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ int (*init_fs_context)(struct fs_context *);const struct fs_parameter_spec *parameters;@@ -2282,6 +2312,17 @@ struct file_system_type {#define MODULE_ALIAS_FS (NAME ) MODULE_ALIAS("fs-" NAME) +/** +* is_mgtime: is this inode using multigrain timestamps +* @inode: inode to test for multigrain timestamps +* +* Return true if the inode uses multigrain timestamps, false otherwise. +*/ +static inline bool is_mgtime (const struct inode *inode) +{ +return inode->i_sb->s_type->fs_flags &FS_MGTIME ; +} +extern struct dentry *mount_bdev (struct file_system_type *fs_type,int flags,const char *dev_name,void *data,int (*fill_super)(struct super_block *,void *,int ));@@ -2918,6 +2959,7 @@ extern void page_put_link(void *);extern int page_symlink (struct inode *inode,const char *symname,int len);extern const struct inode_operations page_symlink_inode_operations;extern void kfree_link (void *); +void fill_mg_cmtime (struct kstat *stat,u32 request_mask,struct inode *inode);void generic_fillattr (struct mnt_idmap *,u32 ,struct inode *,struct kstat *);void generic_fill_statx_attr (struct inode *inode,struct kstat *stat);extern int vfs_getattr_nosec (const struct path *,struct kstat *,u32 ,unsigned int );Signature · 2 lines
-- 2.41.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerPATCH v7 10/13 tmpfs: add support for multigrain timestamps
In reply to Jeff LaytonEnable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
tmpfs only requires the FS_MGTIME flag.
--- mm/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
@@ -4220,7 +4220,7 @@ static struct file_system_type shmem_fs_type = {#endif .kill_sb = kill_litter_super,#ifdef CONFIG_SHMEM - .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP, + .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, #else .fs_flags = FS_USERNS_MOUNT,#endif
Signature · 1 line
2.41.0
Jeff Layton
maintainerPATCH v7 11/13 xfs: switch to multigrain timestamps
In reply to Jeff LaytonEnable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
Also, anytime the mtime changes, the ctime must also change, and those are now the only two options for xfs_trans_ichgtime. Have that function unconditionally bump the ctime, and ASSERT that XFS_ICHGTIME_CHG is always set.
--- fs/xfs/libxfs/xfs_trans_inode.c | 6 +++--- fs/xfs/xfs_iops.c | 8 ++++---- fs/xfs/xfs_super.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_trans_inode.c +3 -3
@@ -62,12 +62,12 @@ xfs_trans_ichgtime(ASSERT (tp);ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); - tv =current_time (inode); +/* If the mtime changes, then ctime must also change */ +ASSERT (flags &XFS_ICHGTIME_CHG ); + tv =inode_set_ctime_current (inode);if (flags &XFS_ICHGTIME_MOD ) inode->i_mtime = tv; -if (flags &XFS_ICHGTIME_CHG ) -inode_set_ctime_to_ts (inode, tv);if (flags &XFS_ICHGTIME_CREATE ) ip->i_crtime = tv; }
fs/xfs/xfs_iops.c +4 -4
@@ -573,10 +573,10 @@ xfs_vn_getattr( stat->gid =vfsgid_into_kgid (vfsgid); stat->ino = ip->i_ino; stat->atime = inode->i_atime; - stat->mtime = inode->i_mtime; - stat->ctime =inode_get_ctime (inode); stat->blocks =XFS_FSB_TO_BB (mp, ip->i_nblocks + ip->i_delayed_blks); +fill_mg_cmtime (stat, request_mask, inode); +if (xfs_has_v3inodes (mp)) {if (request_mask &STATX_BTIME ) { stat->result_mask |=STATX_BTIME ;
@@ -917,7 +917,7 @@ xfs_setattr_size(if (newsize != oldsize && !(iattr->ia_valid & (ATTR_CTIME |ATTR_MTIME ))) { iattr->ia_ctime = iattr->ia_mtime = -current_time (inode); +current_mgtime (inode); iattr->ia_valid |=ATTR_CTIME |ATTR_MTIME ; }
@@ -1036,7 +1036,7 @@ xfs_vn_update_time(int log_flags =XFS_ILOG_TIMESTAMP ;struct xfs_trans *tp;int error; -struct timespec64 now =current_time (inode); +struct timespec64 now;trace_xfs_update_time (ip);
fs/xfs/xfs_super.c +1 -1
@@ -2009,7 +2009,7 @@ static struct file_system_type xfs_fs_type = { .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, };MODULE_ALIAS_FS ("xfs" );
Signature · 1 line
2.41.0
Jeff Layton
maintainerPATCH v7 12/13 ext4: switch to multigrain timestamps
In reply to Jeff LaytonEnable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
For ext4, we only need to enable the FS_MGTIME flag.
--- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/super.c +1 -1
@@ -7279,7 +7279,7 @@ static struct file_system_type ext4_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME, };MODULE_ALIAS_FS ("ext4" );
Signature · 1 line
2.41.0
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 5 lines · Jeff Layton
Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
For ext4, we only need to enable the
FS_MGTIMEflag.
Hi Jeff,
This patch causes a gnulib test failure:
$ ~/sources/lfs/grep-3.11/gnulib-tests/test-stat-time test-stat-time.c:141: assertion 'statinfo[0].st_mtime < statinfo[2].st_mtime || (statinfo[0].st_mtime == statinfo[2].st_mtime && (get_stat_mtime_ns (&statinfo[0]) < get_stat_mtime_ns (&statinfo[2])))' failed Aborted (core dumped)
The source code of the test:
https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-stat-time.c
Is this an expected change?
Quoted 22 lines
Acked-by Theodore Ts'o <[email protected]>Reviewed-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/ext4/super.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/ext4/super.c +1
-1@@ -7279,7 +7279,7 @@ static struct file_system_type ext4_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP |FS_MGTIME , }; MODULE_ALIAS_FS("ext4");
Jan Kara
reviewerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 11 lines · Xi Ruoyao
Quoted 5 lines · Jeff Layton
Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
For ext4, we only need to enable the
FS_MGTIMEflag.Hi Jeff,
This patch causes a gnulib test failure:
Quoted 8 lines
$ ~/sources/lfs/grep-3.11/gnulib-tests/test-stat-time test-stat-time.c:141: assertion 'statinfo[0].st_mtime < statinfo[2].st_mtime || (statinfo[0].st_mtime == statinfo[2].st_mtime && (get_stat_mtime_ns (&statinfo[0]) < get_stat_mtime_ns (&statinfo[2])))' failed Aborted (core dumped)The source code of the test:
https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-stat-time.cIs this an expected change?
Kind of yes. The test first tries to estimate filesystem timestamp granularity in nap() function - due to this patch, the detected granularity will likely be 1 ns so effectively all the test calls will happen immediately one after another. But we don't bother setting the timestamps with more than 1 jiffy (usually 4 ms) precision unless we think someone is watching. So as a result timestamps of all stamp1 and stamp2 files are going to be equal which makes the test fail.
The ultimate problem is that a sequence like:
write(f1)
stat(f2)
write(f2)
stat(f2)
write(f1)
stat(f1)
can result in f1 timestamp to be (slightly) lower than the final f2 timestamp because the second write to f1 didn't bother updating the timestamp. That can indeed be a bit confusing to programs if they compare timestamps between two files. Jeff?
Honza
Quoted 23 lines
Quoted 22 lines
Acked-by Theodore Ts'o <[email protected]>Reviewed-by Jan Kara <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/ext4/super.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/ext4/super.c +1
-1@@ -7279,7 +7279,7 @@ static struct file_system_type ext4_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP |FS_MGTIME , }; MODULE_ALIAS_FS("ext4");
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 21 lines · Jan Kara
Quoted 11 lines · Xi Ruoyao
Quoted 5 lines · Jeff Layton
Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
For ext4, we only need to enable the
FS_MGTIMEflag.Hi Jeff,
This patch causes a gnulib test failure:
Quoted 8 lines
$ ~/sources/lfs/grep-3.11/gnulib-tests/test-stat-time test-stat-time.c:141: assertion 'statinfo[0].st_mtime < statinfo[2].st_mtime || (statinfo[0].st_mtime == statinfo[2].st_mtime && (get_stat_mtime_ns (&statinfo[0]) < get_stat_mtime_ns (&statinfo[2])))' failed Aborted (core dumped)The source code of the test:
https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-stat-time.cIs this an expected change?
Quoted 8 lines
Kind of yes. The test first tries to estimate filesystem timestamp granularity in
nap()function - due to this patch, the detected granularity will likely be 1 ns so effectively all the test calls will happen immediately one after another. But we don't bother setting the timestamps with more than 1 jiffy (usually 4 ms) precision unless we think someone is watching. So as a result timestamps of all stamp1 and stamp2 files are going to be equal which makes the test fail.
That was my take too. The multigrain ctime changes are probably causing nap() to settle on too small a time delta.
Quoted 9 lines
The ultimate problem is that a sequence like:
write(f1)
stat(f2)
write(f2)
stat(f2)
write(f1)
stat(f1)
Quoted 5 lines
can result in f1 timestamp to be (slightly) lower than the final f2 timestamp because the second write to f1 didn't bother updating the timestamp. That can indeed be a bit confusing to programs if they compare timestamps between two files. Jeff?
Basically yes. When there is no stat() call issued on the file in between writes, the kernel will use coarse-grained timestamps when updating it (since no one is watching).
I'm not sure what we can do for this test. The nap() function is making an assumption that the timestamp granularity will be constant, and that isn't necessarily the case now.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 3 lines · Jeff Layton
I'm not sure what we can do for this test. The
nap()function is making an assumption that the timestamp granularity will be constant, and that isn't necessarily the case now.
This is only of secondary importance, because the scenario by Jan Kara shows a much more fundamental breakage:
Quoted 9 lines
Quoted 9 lines
The ultimate problem is that a sequence like:
write(f1)
stat(f2)
write(f2)
stat(f2)
write(f1)
stat(f1)
Quoted 7 lines
Quoted 5 lines
can result in f1 timestamp to be (slightly) lower than the final f2 timestamp because the second write to f1 didn't bother updating the timestamp. That can indeed be a bit confusing to programs if they compare timestamps between two files. Jeff?
Basically yes.
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
Bruno
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 23 lines · Bruno Haible
Quoted 3 lines · Jeff Layton
I'm not sure what we can do for this test. The
nap()function is making an assumption that the timestamp granularity will be constant, and that isn't necessarily the case now.This is only of secondary importance, because the scenario by Jan Kara shows a much more fundamental breakage:
Quoted 15 lines
Quoted 14 lines
The ultimate problem is that a sequence like:
write(f1)
stat(f2)
write(f2)
stat(f2)
write(f1)
stat(f1)can result in f1 timestamp to be (slightly) lower than the final f2 timestamp because the second write to f1 didn't bother updating the timestamp. That can indeed be a bit confusing to programs if they compare timestamps between two files. Jeff?
Quoted 8 lines
Quoted 1 line
Basically yes.
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained current_time whenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files that were written within the same jiffy could see more inode transactions logged, but that still might not be _too_ awful.
I'll keep thinking about it for now.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 4 lines · Jeff Layton
The typical case for make
timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior?
I vaguely remember running into problems with 'make' a while ago (perhaps with a BSDish system) when filesystem timestamps were arbitrarily truncated in some cases but not others. These files would look older than they really were, so 'make' would think they were up-to-date when they weren't, and 'make' would omit actions that it should have done, thus screwing up the build.
File timestamps can be close together with 'make -j' on fast hosts. Sometimes a shell script (or 'make' itself) will run 'make', then modify a file F, then immediately run 'make' again; the latter 'make' won't work if F's timestamp is mistakenly older than targets that depend on it.
Although 'make'-like apps are the biggest canaries in this coal mine, the issue also affects 'find -newer' (as Bruno mentioned), 'rsync -u', 'mv -u', 'tar -u', Emacs file-newer-than-file-p, and surely many other places. For example, any app that creates a timestamp file, then backs up all files newer than that file, would be at risk.
Quoted 3 lines
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp?
Wouldn't this need to be done globally, that is, not just on a per-file or per-filesystem basis? If so, I don't see how we'd avoid locking performance issues.
PS. Although I'm no expert in the Linux inode code I hope you don't mind my asking a question about this part of inode_set_ctime_current:
/* * If we've recently updated with a fine-grained timestamp, * then the coarse-grained one may still be earlier than the * existing ctime. Just keep the existing value if so. */ ctime.tv_sec = inode->__i_ctime.tv_sec; if (timespec64_compare(&ctime, &now) > 0) return ctime;
Suppose root used clock_settime to set the clock backwards. Won't this code incorrectly refuse to update the file's timestamp afterwards? That is, shouldn't the last line be "goto fine_grained;" rather than "return ctime;", with the comment changed from "keep the existing value" to "use a fine-grained value"?
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 25 lines · Paul Eggert
Quoted 4 lines · Jeff Layton
The typical case for make
timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior?I vaguely remember running into problems with 'make' a while ago (perhaps with a BSDish system) when filesystem timestamps were arbitrarily truncated in some cases but not others. These files would look older than they really were, so 'make' would think they were up-to-date when they weren't, and 'make' would omit actions that it should have done, thus screwing up the build.
File timestamps can be close together with 'make -j' on fast hosts. Sometimes a shell script (or 'make' itself) will run 'make', then modify a file F, then immediately run 'make' again; the latter 'make' won't work if F's timestamp is mistakenly older than targets that depend on it.
Although 'make'-like apps are the biggest canaries in this coal mine, the issue also affects 'find -newer' (as Bruno mentioned), 'rsync -u', 'mv -u', 'tar -u', Emacs file-newer-than-file-p, and surely many other places. For example, any app that creates a timestamp file, then backs up all files newer than that file, would be at risk.
Quoted 8 lines
Quoted 3 lines
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp?Wouldn't this need to be done globally, that is, not just on a per-file or per-filesystem basis? If so, I don't see how we'd avoid locking performance issues.
Maybe. Another idea might be to introduce a new timekeeper for multigrain filesystems, but all of those would likely have to share the same coarse-grained clock source.
So yeah, if you stat an inode and then update it, any inode written on a multigrain filesystem within the same jiffy-sized window would have to log an extra transaction to write out the inode. That's what I meant when I was talking about write amplification.
Quoted 13 lines
PS. Although I'm no expert in the Linux inode code I hope you don't mind my asking a question about this part of
inode_set_ctime_current:/* * If we've recently updated with a fine-grained timestamp, * then the coarse-grained one may still be earlier than the * existing ctime. Just keep the existing value if so. */ ctime.tv_sec = inode->__i_ctime.tv_sec; if (timespec64_compare(&ctime, &now) > 0) return ctime;
Quoted 5 lines
Suppose root used
clock_settimeto set the clock backwards. Won't this code incorrectly refuse to update the file's timestamp afterwards? That is, shouldn't the last line be "gotofine_grained;" rather than "return ctime;", with the comment changed from "keep the existing value" to "use a fine-grained value"?
It is a problem, and Linus pointed that out yesterday, which is why I sent this earlier today:
https://lore.kernel.org/linux-fsdevel/[email protected]/T/#u
Bear in mind that we're not dealing with a situation where the value has not been queried since its last update, so we don't need to use a fine grained timestamp there (and really, it's preferable not to do so). A coarse one should be fine in this case.
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Jeff LaytonQuoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files that
Less than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From cb14add421967f6e374eb77c36cc4a0526b10d17 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount option
While we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
--- fs/fs_context.c | 18 ++++++++++++++++++ fs/inode.c | 4 ++-- fs/proc_namespace.c | 1 + fs/stat.c | 2 +- include/linux/fs.h | 4 +++- 5 files changed, 25 insertions(+), 4 deletions(-)
fs/fs_context.c +18 -0
@@ -44,6 +44,7 @@ static const struct constant_table common_set_sb_flag[] = { { "mand", SB_MANDLOCK }, { "ro", SB_RDONLY }, { "sync", SB_SYNCHRONOUS }, + { "mgtime", SB_MGTIME }, { }, };
@@ -52,18 +53,32 @@ static const struct constant_table common_clear_sb_flag[] = { { "nolazytime", SB_LAZYTIME }, { "nomand", SB_MANDLOCK }, { "rw", SB_RDONLY }, + { "nomgtime", SB_MGTIME }, { }, }; +static inline int check_mgtime (unsigned int token,const struct fs_context *fc) +{ +if (token !=SB_MGTIME ) +return 0 ; +if (!(fc->fs_type->fs_flags &FS_MGTIME )) +return invalf (fc,"Filesystem doesn't support multi-grain timestamps" ); +return 0 ; +} +/* * Check for a common mount option that manipulates s_flags. */ static int vfs_parse_sb_flag (struct fs_context *fc,const char *key) {unsigned int token; +int ret; token =lookup_constant (common_set_sb_flag, key,0 );if (token) { + ret =check_mgtime (token, fc); +if (ret) +return ret; fc->sb_flags |= token; fc->sb_flags_mask |= token;return 0 ;
@@ -71,6 +86,9 @@ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key) token =lookup_constant (common_clear_sb_flag, key,0 );if (token) { + ret =check_mgtime (token, fc); +if (ret) +return ret; fc->sb_flags &= ~token; fc->sb_flags_mask |= token;return 0 ;
fs/inode.c +2 -2
@@ -2141,7 +2141,7 @@ EXPORT_SYMBOL(current_mgtime);static struct timespec64 current_ctime (struct inode *inode) { -if (is_mgtime (inode)) +if (IS_MGTIME (inode))return current_mgtime (inode);return current_time (inode); }
@@ -2588,7 +2588,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) now =current_time (inode);/* Just copy it into place if it's not multigrain */ -if (!is_mgtime (inode)) { +if (!IS_MGTIME (inode)) {inode_set_ctime_to_ts (inode, now);return now; }
fs/proc_namespace.c +1 -0
@@ -49,6 +49,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) { SB_DIRSYNC, ",dirsync" }, { SB_MANDLOCK, ",mand" }, { SB_LAZYTIME, ",lazytime" }, + { SB_MGTIME, ",mgtime" }, { 0, NULL } };const struct proc_fs_opts *fs_infop;
fs/stat.c +1 -1
@@ -90,7 +90,7 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->size =i_size_read (inode); stat->atime = inode->i_atime; -if (is_mgtime (inode)) { +if (IS_MGTIME (inode)) {fill_mg_cmtime (stat, request_mask, inode); }else { stat->mtime = inode->i_mtime;
include/linux/fs.h +3 -1
@@ -1114,6 +1114,7 @@ extern int send_sigurg(struct fown_struct *fown);#define SB_NODEV BIT(2)/* Disallow access to device special files */ #define SB_NOEXEC BIT(3)/* Disallow program execution */ #define SB_SYNCHRONOUS BIT(4)/* Writes are synced at once */ +#define SB_MGTIME BIT(5)/* Use multi-grain timestamps */ #define SB_MANDLOCK BIT(6)/* Allow mandatory locks on an FS */ #define SB_DIRSYNC BIT(7)/* Directory modifications are synchronous */ #define SB_NOATIME BIT(10)/* Do not update access times. */
@@ -2105,6 +2106,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))#define IS_MANDLOCK (inode) __IS_FLG(inode, SB_MANDLOCK)#define IS_NOATIME (inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME) +#define IS_MGTIME (inode) __IS_FLG(inode, SB_MGTIME)#define IS_I_VERSION (inode) __IS_FLG(inode, SB_I_VERSION)#define IS_NOQUOTA (inode) ((inode)->i_flags & S_NOQUOTA)
@@ -2366,7 +2368,7 @@ struct file_system_type {*/ static inline bool is_mgtime (const struct inode *inode) { -return inode->i_sb->s_type->fs_flags &FS_MGTIME ; +return inode->i_sb->s_flags &SB_MGTIME ; } extern struct dentry *mount_bdev(struct file_system_type *fs_type,
Signature · 1 line
2.34.1
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 44 lines · Christian Brauner
Quoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files thatLess than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From
cb14add421967f6e374eb77c36cc4a0526b10d17Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount option
Quoted 4 lines
While we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
I agree with this solution.
You can add some metainfo:
Quoted 140 lines
Signed-off-by Christian Brauner <[email protected]>---
fs/fs_context.c | 18 ++++++++++++++++++
fs/inode.c | 4 ++--
fs/proc_namespace.c | 1 +
fs/stat.c | 2 +-
include/linux/fs.h | 4 +++-5 files changed, 25 insertions(+), 4 deletions(-)fs/fs_context.c +1
-0@@ -44,6 +44,7 @@ static const struct constant_table common_set_sb_flag[] = { { "mand", SB_MANDLOCK }, { "ro", SB_RDONLY }, { "sync", SB_SYNCHRONOUS }, + { "mgtime", SB_MGTIME }, { }, };fs/fs_context.c +1
-0@@ -52,18 +53,32 @@ static const struct constant_table common_clear_sb_flag[] = { { "nolazytime", SB_LAZYTIME }, { "nomand", SB_MANDLOCK }, { "rw", SB_RDONLY }, + { "nomgtime", SB_MGTIME }, { }, };fs/fs_context.c +9
-0+static inline int check_mgtime (unsigned int token,const struct fs_context *fc) +{ +if (token !=SB_MGTIME ) +return 0 ; +if (!(fc->fs_type->fs_flags &FS_MGTIME )) +return invalf (fc,"Filesystem doesn't support multi-grain timestamps" ); +return 0 ; +} +/*
* Check for a common mount option that manipulatess_flags. */
static intvfs_parse_sb_flag(struct fs_context *fc, const char *key){
unsigned int token;fs/fs_context.c +1
-0+int ret;
token =lookup_constant(common_set_sb_flag, key, 0); if (token) {fs/fs_context.c +3
-0+ ret =check_mgtime (token, fc); +if (ret) +return ret;
fc->sb_flags|= token;
fc->sb_flags_mask|= token;
return 0;fs/fs_context.c +0
-0@@ -71,6 +86,9 @@ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key)
token =lookup_constant(common_clear_sb_flag, key, 0); if (token) {fs/fs_context.c +3
-0+ ret =check_mgtime (token, fc); +if (ret) +return ret;
fc->sb_flags&= ~token;
fc->sb_flags_mask|= token;
return 0;fs/inode.c +0
-0@@ -2141,7 +2141,7 @@ EXPORT_SYMBOL(current_mgtime);
static struct timespec64current_ctime(struct inode *inode){fs/inode.c +1
-1-if (is_mgtime (inode)) +if (IS_MGTIME (inode))return
current_mgtime(inode);
returncurrent_time(inode);
}fs/inode.c +0
-0@@ -2588,7 +2588,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) now = current_time(inode);
/* Just copy it into place if it's not multigrain */fs/inode.c +1
-1-if (!is_mgtime (inode)) { +if (!IS_MGTIME (inode)) {
inode_set_ctime_to_ts(inode, now); return now;
}fs/proc_namespace.c +1
-0@@ -49,6 +49,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) { SB_DIRSYNC, ",dirsync" }, { SB_MANDLOCK, ",mand" }, { SB_LAZYTIME, ",lazytime" }, + { SB_MGTIME, ",mgtime" }, { 0, NULL } }; const struct proc_fs_opts *fs_infop;fs/stat.c +0
-0@@ -90,7 +90,7 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->size = i_size_read(inode); stat->atime = inode->i_atime;fs/stat.c +1
-1-if (is_mgtime (inode)) { +if (IS_MGTIME (inode)) {
fill_mg_cmtime(stat, request_mask, inode); } else {
stat->mtime=inode->i_mtime;include/linux/fs.h +2
-0@@ -1114,6 +1114,7 @@ extern int send_sigurg(struct fown_struct *fown); #define SB_NODEV BIT(2) /* Disallow access to device special files */ #define SB_NOEXEC BIT(3) /* Disallow program execution */ #define SB_SYNCHRONOUS BIT(4) /* Writes are synced at once */ +#define SB_MGTIME BIT(5)/* Use multi-grain timestamps */ #define SB_MANDLOCK BIT(6) /* Allow mandatory locks on an FS */ #define SB_DIRSYNC BIT(7) /* Directory modifications are synchronous */ #define SB_NOATIME BIT(10) /* Do not update access times. */@@ -2105,6 +2106,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) #define IS_MANDLOCK(inode) __IS_FLG(inode, SB_MANDLOCK) #define IS_NOATIME(inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME) +#define IS_MGTIME (inode) __IS_FLG(inode, SB_MGTIME) #define IS_I_VERSION(inode) __IS_FLG(inode, SB_I_VERSION)
#defineIS_NOQUOTA(inode)((inode)->i_flags &S_NOQUOTA)include/linux/fs.h +1
-1@@ -2366,7 +2368,7 @@ struct file_system_type {*/ static inline bool is_mgtime(const struct inode *inode) { -return inode->i_sb->s_type->fs_flags &FS_MGTIME ; +return inode->i_sb->s_flags &SB_MGTIME ; }
extern struct dentry *mount_bdev(structfile_system_type*fs_type,
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Christian BraunerQuoted 197 lines · Christian Brauner
Quoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files thatLess than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From
cb14add421967f6e374eb77c36cc4a0526b10d17Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount optionWhile we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Signed-off-by Christian Brauner <[email protected]>---
fs/fs_context.c | 18 ++++++++++++++++++ fs/inode.c | 4 ++-- fs/proc_namespace.c | 1 + fs/stat.c | 2 +- include/linux/fs.h | 4 +++- 5 files changed, 25 insertions(+), 4 deletions(-)fs/fs_context.c +1
-0@@ -44,6 +44,7 @@ static const struct constant_table common_set_sb_flag[] = { { "mand", SB_MANDLOCK }, { "ro", SB_RDONLY }, { "sync", SB_SYNCHRONOUS }, + { "mgtime", SB_MGTIME }, { }, };fs/fs_context.c +1
-0@@ -52,18 +53,32 @@ static const struct constant_table common_clear_sb_flag[] = { { "nolazytime", SB_LAZYTIME }, { "nomand", SB_MANDLOCK }, { "rw", SB_RDONLY }, + { "nomgtime", SB_MGTIME }, { }, };fs/fs_context.c +9
-0+static inline int check_mgtime (unsigned int token,const struct fs_context *fc) +{ +if (token !=SB_MGTIME ) +return 0 ; +if (!(fc->fs_type->fs_flags &FS_MGTIME )) +return invalf (fc,"Filesystem doesn't support multi-grain timestamps" ); +return 0 ; +} +/*
* Check for a common mount option that manipulatess_flags. */
static intvfs_parse_sb_flag(struct fs_context *fc, const char *key){
unsigned int token;fs/fs_context.c +1
-0+int ret;token =
lookup_constant(common_set_sb_flag, key, 0); if (token) {fs/fs_context.c +3
-0+ ret =check_mgtime (token, fc); +if (ret) +return ret;
fc->sb_flags|= token;
fc->sb_flags_mask|= token;
return 0;fs/fs_context.c +0
-0@@ -71,6 +86,9 @@ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key)token =
lookup_constant(common_clear_sb_flag, key, 0); if (token) {fs/fs_context.c +3
-0+ ret =check_mgtime (token, fc); +if (ret) +return ret;
fc->sb_flags&= ~token;
fc->sb_flags_mask|= token;
return 0;fs/inode.c +0
-0@@ -2141,7 +2141,7 @@ EXPORT_SYMBOL(current_mgtime);static struct timespec64
current_ctime(struct inode *inode){fs/inode.c +1
-1-if (is_mgtime (inode)) +if (IS_MGTIME (inode))return
current_mgtime(inode);
returncurrent_time(inode);
}fs/inode.c +0
-0@@ -2588,7 +2588,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) now = current_time(inode);/* Just copy it into place if it's not multigrain */
fs/inode.c +1
-1-if (!is_mgtime (inode)) { +if (!IS_MGTIME (inode)) {
inode_set_ctime_to_ts(inode, now); return now;
}fs/proc_namespace.c +1
-0@@ -49,6 +49,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) { SB_DIRSYNC, ",dirsync" }, { SB_MANDLOCK, ",mand" }, { SB_LAZYTIME, ",lazytime" }, + { SB_MGTIME, ",mgtime" }, { 0, NULL } }; const struct proc_fs_opts *fs_infop;fs/stat.c +0
-0@@ -90,7 +90,7 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->size = i_size_read(inode); stat->atime = inode->i_atime;fs/stat.c +1
-1-if (is_mgtime (inode)) { +if (IS_MGTIME (inode)) {
fill_mg_cmtime(stat, request_mask, inode); } else {
stat->mtime=inode->i_mtime;include/linux/fs.h +2
-0@@ -1114,6 +1114,7 @@ extern int send_sigurg(struct fown_struct *fown); #define SB_NODEV BIT(2) /* Disallow access to device special files */ #define SB_NOEXEC BIT(3) /* Disallow program execution */ #define SB_SYNCHRONOUS BIT(4) /* Writes are synced at once */ +#define SB_MGTIME BIT(5)/* Use multi-grain timestamps */ #define SB_MANDLOCK BIT(6) /* Allow mandatory locks on an FS */ #define SB_DIRSYNC BIT(7) /* Directory modifications are synchronous */ #define SB_NOATIME BIT(10) /* Do not update access times. */@@ -2105,6 +2106,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) #define IS_MANDLOCK(inode) __IS_FLG(inode, SB_MANDLOCK) #define IS_NOATIME(inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME) +#define IS_MGTIME (inode) __IS_FLG(inode, SB_MGTIME) #define IS_I_VERSION(inode) __IS_FLG(inode, SB_I_VERSION)#define
IS_NOQUOTA(inode)((inode)->i_flags &S_NOQUOTA)include/linux/fs.h +1
-1@@ -2366,7 +2368,7 @@ struct file_system_type {*/ static inline bool is_mgtime(const struct inode *inode) { -return inode->i_sb->s_type->fs_flags &FS_MGTIME ; +return inode->i_sb->s_flags &SB_MGTIME ; }
Quoted 1 line
extern struct dentry *mount_bdev(struct
file_system_type*fs_type,
The mount option looks reasonable. Thanks for throwing together the patch. Maybe in the future we can come up with a way to mitigate the problems and do this unconditionally?
Jan Kara
reviewerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Christian BraunerQuoted 44 lines · Christian Brauner
Quoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files thatLess than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From
cb14add421967f6e374eb77c36cc4a0526b10d17Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount option
Quoted 6 lines
While we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Signed-off-by Christian Brauner <[email protected]>
Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight... If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Honza
Quoted 142 lines
--- fs/fs_context.c | 18 ++++++++++++++++++ fs/inode.c | 4 ++-- fs/proc_namespace.c | 1 + fs/stat.c | 2 +- include/linux/fs.h | 4 +++- 5 files changed, 25 insertions(+), 4 deletions(-)fs/fs_context.c +18
-0@@ -44,6 +44,7 @@ static const struct constant_table common_set_sb_flag[] = { { "mand", SB_MANDLOCK }, { "ro", SB_RDONLY }, { "sync", SB_SYNCHRONOUS }, + { "mgtime", SB_MGTIME }, { }, };@@ -52,18 +53,32 @@ static const struct constant_table common_clear_sb_flag[] = { { "nolazytime", SB_LAZYTIME }, { "nomand", SB_MANDLOCK }, { "rw", SB_RDONLY }, + { "nomgtime", SB_MGTIME }, { }, }; +static inline int check_mgtime (unsigned int token,const struct fs_context *fc) +{ +if (token !=SB_MGTIME ) +return 0 ; +if (!(fc->fs_type->fs_flags &FS_MGTIME )) +return invalf (fc,"Filesystem doesn't support multi-grain timestamps" ); +return 0 ; +} +/* * Check for a common mount option that manipulates s_flags. */ static int vfs_parse_sb_flag (struct fs_context *fc,const char *key) {unsigned int token; +int ret; token =lookup_constant (common_set_sb_flag, key,0 );if (token) { + ret =check_mgtime (token, fc); +if (ret) +return ret; fc->sb_flags |= token; fc->sb_flags_mask |= token;return 0 ;@@ -71,6 +86,9 @@ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key) token =lookup_constant (common_clear_sb_flag, key,0 );if (token) { + ret =check_mgtime (token, fc); +if (ret) +return ret; fc->sb_flags &= ~token; fc->sb_flags_mask |= token;return 0 ;fs/inode.c +2
-2@@ -2141,7 +2141,7 @@ EXPORT_SYMBOL(current_mgtime);static struct timespec64 current_ctime (struct inode *inode) { -if (is_mgtime (inode)) +if (IS_MGTIME (inode))return current_mgtime (inode);return current_time (inode); }@@ -2588,7 +2588,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) now =current_time (inode);/* Just copy it into place if it's not multigrain */ -if (!is_mgtime (inode)) { +if (!IS_MGTIME (inode)) {inode_set_ctime_to_ts (inode, now);return now; }fs/proc_namespace.c +1
-0@@ -49,6 +49,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) { SB_DIRSYNC, ",dirsync" }, { SB_MANDLOCK, ",mand" }, { SB_LAZYTIME, ",lazytime" }, + { SB_MGTIME, ",mgtime" }, { 0, NULL } };const struct proc_fs_opts *fs_infop;fs/stat.c +1
-1@@ -90,7 +90,7 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->size =i_size_read (inode); stat->atime = inode->i_atime; -if (is_mgtime (inode)) { +if (IS_MGTIME (inode)) {fill_mg_cmtime (stat, request_mask, inode); }else { stat->mtime = inode->i_mtime;include/linux/fs.h +3
-1@@ -1114,6 +1114,7 @@ extern int send_sigurg(struct fown_struct *fown);#define SB_NODEV BIT(2)/* Disallow access to device special files */ #define SB_NOEXEC BIT(3)/* Disallow program execution */ #define SB_SYNCHRONOUS BIT(4)/* Writes are synced at once */ +#define SB_MGTIME BIT(5)/* Use multi-grain timestamps */ #define SB_MANDLOCK BIT(6)/* Allow mandatory locks on an FS */ #define SB_DIRSYNC BIT(7)/* Directory modifications are synchronous */ #define SB_NOATIME BIT(10)/* Do not update access times. */ @@ -2105,6 +2106,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))#define IS_MANDLOCK (inode) __IS_FLG(inode, SB_MANDLOCK)#define IS_NOATIME (inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME) +#define IS_MGTIME (inode) __IS_FLG(inode, SB_MGTIME)#define IS_I_VERSION (inode) __IS_FLG(inode, SB_I_VERSION)#define IS_NOQUOTA (inode) ((inode)->i_flags & S_NOQUOTA)@@ -2366,7 +2368,7 @@ struct file_system_type {*/ static inline bool is_mgtime (const struct inode *inode) { -return inode->i_sb->s_type->fs_flags &FS_MGTIME ; +return inode->i_sb->s_flags &SB_MGTIME ; } extern struct dentry *mount_bdev(struct file_system_type *fs_type,Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 50 lines · Jan Kara
Quoted 49 lines · Christian Brauner
Quoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files thatLess than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From
cb14add421967f6e374eb77c36cc4a0526b10d17Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount optionWhile we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Quoted 7 lines
Quoted 1 line
Signed-off-by Christian Brauner <[email protected]>Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight... If I were a sysadmin, I'd rather opt for something like
I think you'll basically enable this because you want to export a filesystem via NFS.
Quoted 2 lines
finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps
That would work with this patch, no? Or are you saying it would need something else?
Quoted 6 lines
as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
What would changes would be involved for that?
If this is invasive work and we decide this is something that we want to do then we should remove FS_MGTIME from btrfs, xfs, ext4, and tmpfs for v6.6.
Jan Kara
reviewerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 53 lines · Christian Brauner
Quoted 52 lines · Jan Kara
Quoted 50 lines · Christian Brauner
Quoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files thatLess than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From
cb14add421967f6e374eb77c36cc4a0526b10d17Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount optionWhile we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Signed-off-by Christian Brauner <[email protected]>
Quoted 8 lines
Quoted 5 lines
Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight... If I were a sysadmin, I'd rather opt for something like
I think you'll basically enable this because you want to export a filesystem via NFS.
OK, that's what I thought but then you have to make a tough choice between:
1) Possibly inconsistent NFS caches on frequent changes.
2) Possibly broken builds on NFS.
Pick your poison ;)
Quoted 5 lines
Quoted 2 lines
finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps
That would work with this patch, no? Or are you saying it would need something else?
Sorry, I was not really precise here. What I meant was that instead of having multigrain timestamps, I (as a sysadmin) would want the filesystem to set sb->s_time_gran to 1 ns and use lazytime to remove the IO overhead of the frequent timestamp updates. But that is just me brainstorming possible solutions of the original NFS problem.
Quoted 8 lines
Quoted 6 lines
as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
What would changes would be involved for that?
See my other email. It should be fairly small...
Quoted 3 lines
If this is invasive work and we decide this is something that we want to do then we should remove
FS_MGTIMEfrom btrfs, xfs, ext4, and tmpfs for v6.6.
.. but let's see what Jeff thinks. I can miss some problem with the solution.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Jan KaraQuoted 50 lines · Jan Kara
Quoted 49 lines · Christian Brauner
Quoted 21 lines
Quoted 6 lines
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
Quoted 8 lines
As to potential fixes if this is a real problem:
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files thatLess than ideal imho.
If this risks breaking existing workloads by enabling it unconditionally and there isn't a clear way to detect and handle these situations without risk of regression then we should move this behind a mount option.
So how about the following:
From
cb14add421967f6e374eb77c36cc4a0526b10d17Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 20 Sep 2023 10:00:08 +0200
Subject: [PATCH] vfs: move multi-grain timestamps behind a mount optionWhile we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Quoted 8 lines
Quoted 1 line
Signed-off-by Christian Brauner <[email protected]>Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight...
That's the main reason I really didn't want to go with a mount option. Documenting that may be difficult. While there is some pessimism around it, I may still take a stab at just advancing the coarse clock whenever we fetch a fine-grained timestamp. It'd be nice to remove this option in the future if that turns out to be feasible.
Quoted 10 lines
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
Quoted 142 lines
Quoted 142 lines
--- fs/fs_context.c | 18 ++++++++++++++++++ fs/inode.c | 4 ++-- fs/proc_namespace.c | 1 + fs/stat.c | 2 +- include/linux/fs.h | 4 +++- 5 files changed, 25 insertions(+), 4 deletions(-)fs/fs_context.c +18
-0@@ -44,6 +44,7 @@ static const struct constant_table common_set_sb_flag[] = { { "mand", SB_MANDLOCK }, { "ro", SB_RDONLY }, { "sync", SB_SYNCHRONOUS }, + { "mgtime", SB_MGTIME }, { }, };@@ -52,18 +53,32 @@ static const struct constant_table common_clear_sb_flag[] = { { "nolazytime", SB_LAZYTIME }, { "nomand", SB_MANDLOCK }, { "rw", SB_RDONLY }, + { "nomgtime", SB_MGTIME }, { }, }; +static inline int check_mgtime (unsigned int token,const struct fs_context *fc) +{ +if (token !=SB_MGTIME ) +return 0 ; +if (!(fc->fs_type->fs_flags &FS_MGTIME )) +return invalf (fc,"Filesystem doesn't support multi-grain timestamps" ); +return 0 ; +} +/* * Check for a common mount option that manipulates s_flags. */ static int vfs_parse_sb_flag (struct fs_context *fc,const char *key) {unsigned int token; +int ret; token =lookup_constant (common_set_sb_flag, key,0 );if (token) { + ret =check_mgtime (token, fc); +if (ret) +return ret; fc->sb_flags |= token; fc->sb_flags_mask |= token;return 0 ;@@ -71,6 +86,9 @@ static int vfs_parse_sb_flag(struct fs_context *fc, const char *key) token =lookup_constant (common_clear_sb_flag, key,0 );if (token) { + ret =check_mgtime (token, fc); +if (ret) +return ret; fc->sb_flags &= ~token; fc->sb_flags_mask |= token;return 0 ;fs/inode.c +2
-2@@ -2141,7 +2141,7 @@ EXPORT_SYMBOL(current_mgtime);static struct timespec64 current_ctime (struct inode *inode) { -if (is_mgtime (inode)) +if (IS_MGTIME (inode))return current_mgtime (inode);return current_time (inode); }@@ -2588,7 +2588,7 @@ struct timespec64 inode_set_ctime_current(struct inode *inode) now =current_time (inode);/* Just copy it into place if it's not multigrain */ -if (!is_mgtime (inode)) { +if (!IS_MGTIME (inode)) {inode_set_ctime_to_ts (inode, now);return now; }fs/proc_namespace.c +1
-0@@ -49,6 +49,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb) { SB_DIRSYNC, ",dirsync" }, { SB_MANDLOCK, ",mand" }, { SB_LAZYTIME, ",lazytime" }, + { SB_MGTIME, ",mgtime" }, { 0, NULL } };const struct proc_fs_opts *fs_infop;fs/stat.c +1
-1@@ -90,7 +90,7 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->size =i_size_read (inode); stat->atime = inode->i_atime; -if (is_mgtime (inode)) { +if (IS_MGTIME (inode)) {fill_mg_cmtime (stat, request_mask, inode); }else { stat->mtime = inode->i_mtime;include/linux/fs.h +3
-1@@ -1114,6 +1114,7 @@ extern int send_sigurg(struct fown_struct *fown);#define SB_NODEV BIT(2)/* Disallow access to device special files */ #define SB_NOEXEC BIT(3)/* Disallow program execution */ #define SB_SYNCHRONOUS BIT(4)/* Writes are synced at once */ +#define SB_MGTIME BIT(5)/* Use multi-grain timestamps */ #define SB_MANDLOCK BIT(6)/* Allow mandatory locks on an FS */ #define SB_DIRSYNC BIT(7)/* Directory modifications are synchronous */ #define SB_NOATIME BIT(10)/* Do not update access times. */ @@ -2105,6 +2106,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))#define IS_MANDLOCK (inode) __IS_FLG(inode, SB_MANDLOCK)#define IS_NOATIME (inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME) +#define IS_MGTIME (inode) __IS_FLG(inode, SB_MGTIME)#define IS_I_VERSION (inode) __IS_FLG(inode, SB_I_VERSION)#define IS_NOQUOTA (inode) ((inode)->i_flags & S_NOQUOTA)@@ -2366,7 +2368,7 @@ struct file_system_type {*/ static inline bool is_mgtime (const struct inode *inode) { -return inode->i_sb->s_type->fs_flags &FS_MGTIME ; +return inode->i_sb->s_flags &SB_MGTIME ; } extern struct dentry *mount_bdev(struct file_system_type *fs_type,Signature · 1 line
2.34.1
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 29 lines
Quoted 11 lines
Quoted 4 lines
While we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight...
That's the main reason I really didn't want to go with a mount option. Documenting that may be difficult. While there is some pessimism around it, I may still take a stab at just advancing the coarse clock whenever we fetch a fine-grained timestamp. It'd be nice to remove this option in the future if that turns out to be feasible.
Quoted 10 lines
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Quoted 4 lines
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
As far as I can tell we have two options. The first one is to make this into a mount option which I really think isn't a big deal and lets us avoid this whole problem while allowing filesytems exposed via NFS to make use of this feature for change tracking.
The second option is that we turn off fine-grained finestamps for v6.6 and you get to explore other options.
It isn't a big deal regressions like this were always to be expected but v6.6 needs to stabilize so anything that requires more significant work is not an option.
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 39 lines · Christian Brauner
Quoted 29 lines
Quoted 11 lines
Quoted 4 lines
While we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight...
That's the main reason I really didn't want to go with a mount option. Documenting that may be difficult. While there is some pessimism around it, I may still take a stab at just advancing the coarse clock whenever we fetch a fine-grained timestamp. It'd be nice to remove this option in the future if that turns out to be feasible.
Quoted 10 lines
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Quoted 4 lines
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
As far as I can tell we have two options. The first one is to make this into a mount option which I really think isn't a big deal and lets us avoid this whole problem while allowing filesytems exposed via NFS to make use of this feature for change tracking.
Quoted 6 lines
The second option is that we turn off fine-grained finestamps for v6.6 and you get to explore other options.
It isn't a big deal regressions like this were always to be expected but v6.6 needs to stabilize so anything that requires more significant work is not an option.
Oh, absolutely.
I wasn't proposing to do that work for v6.6. For that, we absolutely either need the mount option or to just revert the mgtime conversions.
My plan was to take a stab at doing this for a later kernel release. This is very much a "back to the drawing board" idea. It may not pan out after all, but if it does then we could consider removing the mount option at that point.
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 2 lines
I wasn't proposing to do that work for v6.6. For that, we absolutely either need the mount option or to just revert the mgtime conversions.
This sounds like you want me to do a full-on revert of your series but why? The conversion and changes support an actual use-case and are fine. It's a matter of whether we unconditionally expose it to users or not.
@Jan, what do you think?
Quoted 1 line
My plan was to take a stab at doing this for a later kernel release.
Ok.
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 7 lines · Christian Brauner
Quoted 2 lines
I wasn't proposing to do that work for v6.6. For that, we absolutely either need the mount option or to just revert the mgtime conversions.
This sounds like you want me to do a full-on revert of your series but why? The conversion and changes support an actual use-case and are fine. It's a matter of whether we unconditionally expose it to users or not.
I don't, actually. I'm just mentioning that it's possible if we find the mount option to be unpalatable.
Quoted 5 lines
@Jan, what do you think?
Quoted 1 line
My plan was to take a stab at doing this for a later kernel release.
Ok.
If it works out, then we may be able to eventually remove the mount option, but that is a separate project altogether.
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 2 lines
I don't, actually. I'm just mentioning that it's possible if we find the mount option to be unpalatable.
Ok.
Quoted 9 lines
Quoted 6 lines
@Jan, what do you think?
Quoted 1 line
My plan was to take a stab at doing this for a later kernel release.
Ok.
If it works out, then we may be able to eventually remove the mount option, but that is a separate project altogether.
It would just become a nop for anyone setting it which is fine by me.
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Christian BraunerQuoted 38 lines · Christian Brauner
Quoted 30 lines
Quoted 6 lines
Quoted 5 lines
While we initially thought we can do this unconditionally it turns out that this might break existing workloads that rely on timestamps in very specific ways and we always knew this was a possibility. Move multi-grain timestamps behind a vfs mount option.
Quoted 6 lines
Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight...
That's the main reason I really didn't want to go with a mount option. Documenting that may be difficult. While there is some pessimism around it, I may still take a stab at just advancing the coarse clock whenever we fetch a fine-grained timestamp. It'd be nice to remove this option in the future if that turns out to be feasible.
Quoted 10 lines
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Quoted 4 lines
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
Quoted 4 lines
As far as I can tell we have two options. The first one is to make this into a mount option which I really think isn't a big deal and lets us avoid this whole problem while allowing filesytems exposed via NFS to make use of this feature for change tracking.
A mount option isn't hard to implement, but I think it would be a mistake.
As Jan pointed out, the two alternative compromises are often very difficult to choose between. Tossing this decision to administrators doesn't seem like a responsible way to handle a question that might result in, at the least, unexpected behavior, and at worst, data corruption.
Plus, on Linux, often times files are accessed locally on NFS servers as well as remotely -- how does the server's administrator pick the correct setting in that case?
Quoted 2 lines
The second option is that we turn off fine-grained finestamps for v6.6 and you get to explore other options.
You could put it behind an EXPERIMENTAL Kconfig option so that the code stays in and can be used by the brave or foolish while it is still being refined.
Quoted 3 lines
It isn't a big deal regressions like this were always to be expected but v6.6 needs to stabilize so anything that requires more significant work is not an option.
--
Chuck Lever
Christian Brauner
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 3 lines
You could put it behind an EXPERIMENTAL
Kconfigoption so that the code stays in and can be used by the brave or foolish while it is still being refined.
Given that the discussion has now fully gone back to the drawing board and this is a regression the honest thing to do is to revert the five patches that introduce the infrastructure:
ffb6cf19e063 ("fs: add infrastructure for multigrain timestamps") d48c33972916 ("tmpfs: add support for multigrain timestamps") e44df2664746 ("xfs: switch to multigrain timestamps") 0269b585868e ("ext4: switch to multigrain timestamps") 50e9ceef1d4f ("btrfs: convert to multigrain timestamps")
The conversion to helpers and cleanups are sane and should stay and can be used for any solution that gets built on top of it.
I'd appreciate a look at the branch here:git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.ctime.revert
survives xfstests.
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 14 lines · Christian Brauner
Quoted 3 lines
You could put it behind an EXPERIMENTAL
Kconfigoption so that the code stays in and can be used by the brave or foolish while it is still being refined.Given that the discussion has now fully gone back to the drawing board and this is a regression the honest thing to do is to revert the five patches that introduce the infrastructure:
ffb6cf19e063("fs: add infrastructure for multigrain timestamps")d48c33972916("tmpfs: add support for multigrain timestamps")e44df2664746("xfs: switch to multigrain timestamps")0269b585868e("ext4: switch to multigrain timestamps")50e9ceef1d4f("btrfs: convert to multigrain timestamps")
Quoted 7 lines
The conversion to helpers and cleanups are sane and should stay and can be used for any solution that gets built on top of it.
I'd appreciate a look at the branch here:
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.gitvfs.ctime.revertsurvives xfstests.
I think that's probably the wisest course of action. I need some time to ponder the options for this series anyway, and another cycle in next wouldn't hurt.
The branch itself looks fine, but you might want to reverse the order of the patches in case someone lands there in the middle of a bisect. IOW, I think you want to revert the "convert to multigrain" patches before you revert the infrastructure.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Christian BraunerQuoted 14 lines · Christian Brauner
Quoted 3 lines
You could put it behind an EXPERIMENTAL
Kconfigoption so that the code stays in and can be used by the brave or foolish while it is still being refined.Given that the discussion has now fully gone back to the drawing board and this is a regression the honest thing to do is to revert the five patches that introduce the infrastructure:
ffb6cf19e063("fs: add infrastructure for multigrain timestamps")d48c33972916("tmpfs: add support for multigrain timestamps")e44df2664746("xfs: switch to multigrain timestamps")0269b585868e("ext4: switch to multigrain timestamps")50e9ceef1d4f("btrfs: convert to multigrain timestamps")
Quoted 7 lines
The conversion to helpers and cleanups are sane and should stay and can be used for any solution that gets built on top of it.
I'd appreciate a look at the branch here:
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.gitvfs.ctime.revertsurvives xfstests.
Agreed. I think most of ffb6cf19e063 ("fs: add infrastructure for multigrain timestamps") will be needed anyway but there's no problem in reintroducing it in the new solution. I've checked the branch and the reverts look good to me. Feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Jeff LaytonQuoted 12 lines · Jeff Layton
Quoted 10 lines · Jan Kara
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Quoted 4 lines
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
So what I had in mind (and I definitely miss all the NFS intricacies so the idea may be bogus) was that inode->i_ctime would be maintained exactly as is now. There will be new (kernel internal at least for now) STATX flag STATX_MULTIGRAIN_TS. fill_mg_cmtime() will return timestamp truncated to sb->s_time_gran unless STATX_MULTIGRAIN_TS is set. Hence unless you set STATX_MULTIGRAIN_TS, there is no difference in the returned timestamps compared to the state before multigrain timestamps were introduced. With STATX_MULTIGRAIN_TS we return full precision timestamp as stored in the inode. Then NFS in fh_fill_pre_attrs() and fh_fill_post_attrs() needs to make sure STATX_MULTIGRAIN_TS is set when calling vfs_getattr() to get multigrain time.
I agree nfsd may now be presenting slightly different timestamps than user is able to see with stat(2) directly on the filesystem. But is that a problem? Essentially it is a similar solution as the mgtime mount option but now sysadmin doesn't have to decide on filesystem mount how to report timestamps but the stat caller knowingly opts into possibly inconsistent (among files) but high precision timestamps. And in the particular NFS usecase where stat is called all the time anyway, timestamps will likely even be consistent among files.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 30 lines · Jan Kara
Quoted 12 lines · Jeff Layton
Quoted 10 lines · Jan Kara
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Quoted 4 lines
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
So what I had in mind (and I definitely miss all the NFS intricacies so the idea may be bogus) was that
inode->i_ctimewould be maintained exactly as is now. There will be new (kernel internal at least for now) STATX flagSTATX_MULTIGRAIN_TS.fill_mg_cmtime()will return timestamp truncated tosb->s_time_granunlessSTATX_MULTIGRAIN_TSis set. Hence unless you setSTATX_MULTIGRAIN_TS, there is no difference in the returned timestamps compared to the state before multigrain timestamps were introduced. WithSTATX_MULTIGRAIN_TSwe return full precision timestamp as stored in the inode. Then NFS infh_fill_pre_attrs()andfh_fill_post_attrs()needs to make sureSTATX_MULTIGRAIN_TSis set when callingvfs_getattr()to get multigrain time.
Quoted 9 lines
I agree nfsd may now be presenting slightly different timestamps than user is able to see with stat(2) directly on the filesystem. But is that a problem? Essentially it is a similar solution as the mgtime mount option but now sysadmin doesn't have to decide on filesystem mount how to report timestamps but the stat caller knowingly opts into possibly inconsistent (among files) but high precision timestamps. And in the particular NFS usecase where stat is called all the time anyway, timestamps will likely even be consistent among files.
I like this idea...
Would we also need to raise sb->s_time_gran to something corresponding to HZ on these filesystems? If we truncate the timestamps at a granularity corresponding to HZ before presenting them via statx and the like then that should work around the problem with programs that compare timestamps between inodes.
With NFSv4, when a filesystem doesn't report a STATX_CHANGE_COOKIE, nfsd will fake one up using the ctime. It's fine for that to use a full fine- grained timestamp since we don't expect to be able to compare that value with one of a different inode.
I think we'd want nfsd to present the mtime/ctime values as truncated, just like we would with a local fs. We could hit the same problem of an earlier-looking timestamp with NFS if we try to present the actual fine- grained values to the clients. IOW, I'm convinced that we need to avoid this behavior in most situations.
If we do this, then we technically don't need the mount option either. We could still add it though, and have it govern whether fill_mg_cmtime truncates the timestamps before storing them in the kstat.
Signature · 1 line
Jeff Layton <[email protected]>
Jan Kara
reviewerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
Quoted 41 lines · Jeff Layton
Quoted 30 lines · Jan Kara
Quoted 12 lines · Jeff Layton
Quoted 10 lines · Jan Kara
If I were a sysadmin, I'd rather opt for something like finegrained timestamps + lazytime (if I needed the finegrained timestamps functionality). That should avoid the IO overhead of finegrained timestamps as well and I'd know I can have problems with timestamps only after a system crash.
I've just got another idea how we could solve the problem: Couldn't we always just report coarsegrained timestamp to userspace and provide access to finegrained value only to NFS which should know what it's doing?
Quoted 4 lines
I think that'd be hard. First of all, where would we store the second timestamp? We can't just truncate the fine-grained ones to come up with a coarse-grained one. It might also be confusing having nfsd and local filesystems present different attributes.
So what I had in mind (and I definitely miss all the NFS intricacies so the idea may be bogus) was that
inode->i_ctimewould be maintained exactly as is now. There will be new (kernel internal at least for now) STATX flagSTATX_MULTIGRAIN_TS.fill_mg_cmtime()will return timestamp truncated tosb->s_time_granunlessSTATX_MULTIGRAIN_TSis set. Hence unless you setSTATX_MULTIGRAIN_TS, there is no difference in the returned timestamps compared to the state before multigrain timestamps were introduced. WithSTATX_MULTIGRAIN_TSwe return full precision timestamp as stored in the inode. Then NFS infh_fill_pre_attrs()andfh_fill_post_attrs()needs to make sureSTATX_MULTIGRAIN_TSis set when callingvfs_getattr()to get multigrain time.Quoted 9 lines
I agree nfsd may now be presenting slightly different timestamps than user is able to see with stat(2) directly on the filesystem. But is that a problem? Essentially it is a similar solution as the mgtime mount option but now sysadmin doesn't have to decide on filesystem mount how to report timestamps but the stat caller knowingly opts into possibly inconsistent (among files) but high precision timestamps. And in the particular NFS usecase where stat is called all the time anyway, timestamps will likely even be consistent among files.
Quoted 4 lines
I like this idea...
Would we also need to raise
sb->s_time_granto something corresponding to HZ on these filesystems?
I was actually confused a bit about how timestamp_truncate() works. The jiffie granularity is just direct consequence of current_time() using ktime_get_coarse_real_ts64() and not of timestamp_truncate(). sb->s_time_gran seems to be more about the on-disk format so it doesn't seem like a great idea to touch it. So probably we can just truncate timestamps in generic_fillattr() to HZ granularity unconditionally.
Quoted 3 lines
If we truncate the timestamps at a granularity corresponding to HZ before presenting them via statx and the like then that should work around the problem with programs that compare timestamps between inodes.
Exactly.
Quoted 4 lines
With NFSv4, when a filesystem doesn't report a
STATX_CHANGE_COOKIE, nfsd will fake one up using the ctime. It's fine for that to use a full fine- grained timestamp since we don't expect to be able to compare that value with one of a different inode.
Yes.
Quoted 5 lines
I think we'd want nfsd to present the mtime/ctime values as truncated, just like we would with a local fs. We could hit the same problem of an earlier-looking timestamp with NFS if we try to present the actual fine- grained values to the clients. IOW, I'm convinced that we need to avoid this behavior in most situations.
I wasn't sure if there's a way to do this within NFS - i.e., if the value communicated via NFSv3 protocol (I know v4 has a special change cookie field for it) that gets used for detecting need to revalidate file contents isn't the one presented to client's userspace as ctime. If there's a way to do this then great, I'm all for presenting truncated timestamps even for NFS.
Quoted 1 line
If we do this, then we technically don't need the mount option either.
Yes, that was my hope.
Quoted 2 lines
We could still add it though, and have it govern whether
fill_mg_cmtimetruncates the timestamps before storing them in the kstat.
Well, if we decide these timestamps are useful for userspace as well, I'd rather make that a userspace visible STATX flag than a mount option. So applications aware of the pitfalls can get high precision timestamps without possibly breaking unaware applications.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Jeff LaytonQuoted 8 lines · Jeff Layton
Quoted 5 lines
Surely this is a safe choice as it moves the responsibility to the sysadmin and the cases where finegrained timestamps are required. But I kind of wonder how is the sysadmin going to decide whether mgtime is safe for his system or not? Because the possible breakage needn't be obvious at the first sight...
That's the main reason I really didn't want to go with a mount option. Documenting that may be difficult.
You could document it like this:
The mgtime option enables more precise modification times (mtime) on some files, together with an optimization that limits the amount of metadata changes.
Note that this option may, in some cases, after writing to file F1 and then writing to file F2, report a lower mtime for F2 than for F2. Enabling this option may be useful on file systems shared via NFS. The safe choice is to disable this option.
For me as a user, there's no need to go into more details than that.
It's important to have this mount option, for people who want maximum reliability. Personally, I always enable the 'strictatime' option on all ext4 mounts, since 'relatime' optimizes too much for my use-cases. If I fear wrong results of "make" runs, I will definitely opt for the safe choice regarding mgtime as well — since I don't want to spend hours debugging binaries that were built incorrectly from correct source code.
Bruno
Jan Kara
reviewerRe: [PATCH v7 12/13] ext4: switch to multigrain timestamps
In reply to Jeff LaytonQuoted 34 lines · Jeff Layton
Quoted 23 lines · Bruno Haible
Quoted 3 lines · Jeff Layton
I'm not sure what we can do for this test. The
nap()function is making an assumption that the timestamp granularity will be constant, and that isn't necessarily the case now.This is only of secondary importance, because the scenario by Jan Kara shows a much more fundamental breakage:
Quoted 15 lines
Quoted 14 lines
The ultimate problem is that a sequence like:
write(f1)
stat(f2)
write(f2)
stat(f2)
write(f1)
stat(f1)can result in f1 timestamp to be (slightly) lower than the final f2 timestamp because the second write to f1 didn't bother updating the timestamp. That can indeed be a bit confusing to programs if they compare timestamps between two files. Jeff?
Quoted 8 lines
Quoted 1 line
Basically yes.
f1 was last written to *after* f2 was last written to. If the timestamp of f1 is then lower than the timestamp of f2, timestamps are fundamentally broken.
Many things in user-space depend on timestamps, such as build system centered around 'make', but also 'find ... -newer ...'.
Quoted 7 lines
What does breakage with make look like in this situation? The "fuzz" here is going to be on the order of a jiffy. The typical case for make timestamp comparisons is comparing source files vs. a build target. If those are being written nearly simultaneously, then that could be an issue, but is that a typical behavior? It seems like it would be hard to rely on that anyway, esp. given filesystems like NFS that can do lazy writeback.
TL;DR I don't think we can just wave away the change as "the problem has always been there".
Firstly, the fact that something is not quite reliable on NFS doesn't mean people don't rely on the behavior on local filesystems. NFS has a historical reputation of being a bit weird ;). Secondly, I agree that the same problems can manifest currently for files on two filesystems with different timestamp granularity. But again that is something that is rare - widely used filesystems have a granularity of a jiffy and in most cases build and source files are on the same filesystem anyway. So yes, in principle the problems could happen even before multigrain timestamps but having different granularity per inode just made them manifest in much much more setups and that matters because setups that were perfectly fine before are not anymore.
Quoted 6 lines
One of the operating principles with this series is that timestamps can be of varying granularity between different files. Note that Linux already violates this assumption when you're working across filesystems of different types.
As to potential fixes if this is a real problem:
Regarding whether the problem is real: I wouldn't worry too much about the particular test that started this thread. That seems like something very special. But the build system issues could be real - as you wrote in your motivation for the series - a lot can happen in a jiffy on contemporary computers. I can imagine build product having newer timestamp than build source because the modification of source managed to squeeze into the same jiffy and still use a coarse-grained timestamp. Or some other producer-consumer type of setup... Sure usually there would be enough stat(2) calls on both sides to force finegrained timestamps on both files but if there are not in some corner case, debugging the problem is really tough.
Quoted 8 lines
I don't really want to put this behind a mount or mkfs option (a'la relatime, etc.), but that is one possibility.
I wonder if it would be feasible to just advance the coarse-grained
current_timewhenever we end up updating a ctime with a fine-grained timestamp? It might produce some inode write amplification. Files that were written within the same jiffy could see more inode transactions logged, but that still might not be _too_ awful.
From a first glance I'd guess the performance overhead will be too big for a busy filesystem to enable this unconditionally. But I could be wrong...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jeff Layton
maintainerPATCH v7 13/13 btrfs: convert to multigrain timestamps
In reply to Jeff LaytonEnable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
Beyond enabling the FS_MGTIME flag, this patch eliminates update_time_for_write, which goes to great pains to avoid in-memory stores. Just have it overwrite the timestamps unconditionally.
--- fs/btrfs/file.c | 24 ++++-------------------- fs/btrfs/super.c | 5 +++-- 2 files changed, 7 insertions(+), 22 deletions(-)
fs/btrfs/file.c +4 -20
@@ -1106,25 +1106,6 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode)btrfs_drew_write_unlock (&inode->root->snapshot_lock); } -static void update_time_for_write (struct inode *inode) -{ -struct timespec64 now, ctime; - -if (IS_NOCMTIME (inode)) -return ; - - now =current_time (inode); -if (!timespec64_equal (&inode->i_mtime, &now)) - inode->i_mtime = now; - - ctime =inode_get_ctime (inode); -if (!timespec64_equal (&ctime, &now)) -inode_set_ctime_to_ts (inode, now); - -if (IS_I_VERSION (inode)) -inode_inc_iversion (inode); -} -static int btrfs_write_check (struct kiocb *iocb,struct iov_iter *from,size_t count) {
@@ -1156,7 +1137,10 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,* need to start yet another transaction to update the inode as we will * update the inode when we finish writing whatever data we write. */ -update_time_for_write (inode); +if (!IS_NOCMTIME (inode)) { + inode->i_mtime =inode_set_ctime_current (inode); +inode_inc_iversion (inode); + } start_pos =round_down (pos, fs_info->sectorsize); oldsize =i_size_read (inode);
fs/btrfs/super.c +3 -2
@@ -2144,7 +2144,7 @@ static struct file_system_type btrfs_fs_type = { .name = "btrfs", .mount = btrfs_mount, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_MGTIME, };static struct file_system_type btrfs_root_fs_type = {
@@ -2152,7 +2152,8 @@ static struct file_system_type btrfs_root_fs_type = { .name = "btrfs", .mount = btrfs_mount_root, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | + FS_ALLOW_IDMAP | FS_MGTIME, };MODULE_ALIAS_FS ("btrfs" );
Signature · 1 line
2.41.0
Re: [PATCH v7 13/13] btrfs: convert to multigrain timestamps
Quoted 10 lines · Jeff Layton
Enable multigrain timestamps, which should ensure that there is an apparent change to the timestamp whenever it has been written after being actively observed via getattr.
Beyond enabling the
FS_MGTIMEflag, this patch eliminatesupdate_time_for_write, which goes to great pains to avoid in-memory stores. Just have it overwrite the timestamps unconditionally.Signed-off-by Jeff Layton <[email protected]>Acked-by David Sterba <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 74 lines
--- fs/btrfs/file.c | 24 ++++-------------------- fs/btrfs/super.c | 5 +++-- 2 files changed, 7 insertions(+), 22 deletions(-)fs/btrfs/file.c +4
-20@@ -1106,25 +1106,6 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode)btrfs_drew_write_unlock (&inode->root->snapshot_lock); } -static void update_time_for_write (struct inode *inode) -{ -struct timespec64 now, ctime; - -if (IS_NOCMTIME (inode)) -return ; - - now =current_time (inode); -if (!timespec64_equal (&inode->i_mtime, &now)) - inode->i_mtime = now; - - ctime =inode_get_ctime (inode); -if (!timespec64_equal (&ctime, &now)) -inode_set_ctime_to_ts (inode, now); - -if (IS_I_VERSION (inode)) -inode_inc_iversion (inode); -} -static int btrfs_write_check (struct kiocb *iocb,struct iov_iter *from,size_t count) {@@ -1156,7 +1137,10 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,* need to start yet another transaction to update the inode as we will * update the inode when we finish writing whatever data we write. */ -update_time_for_write (inode); +if (!IS_NOCMTIME (inode)) { + inode->i_mtime =inode_set_ctime_current (inode); +inode_inc_iversion (inode); + } start_pos =round_down (pos, fs_info->sectorsize); oldsize =i_size_read (inode);fs/btrfs/super.c +3
-2@@ -2144,7 +2144,7 @@ static struct file_system_type btrfs_fs_type = { .name = "btrfs", .mount = btrfs_mount, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_MGTIME, };static struct file_system_type btrfs_root_fs_type = {@@ -2152,7 +2152,8 @@ static struct file_system_type btrfs_root_fs_type = { .name = "btrfs", .mount = btrfs_mount_root, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | + FS_ALLOW_IDMAP | FS_MGTIME, };MODULE_ALIAS_FS ("btrfs" );Signature · 2 lines
-- 2.41.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 11 lines · Jeff Layton
The VFS always uses coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes.
Unfortunately, this coarseness has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide to invalidate the cache.
[...]
Applied to the vfs.ctime branch of the vfs/vfs.git tree. Patches in the vfs.ctime branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.ctime
[01/13] fs: remove silly warning from current_time
https://git.kernel.org/vfs/vfs/c/562bcab11bf4 [02/13] fs: pass the request_mask to generic_fillattr https://git.kernel.org/vfs/vfs/c/3592165f4378 [03/13] fs: drop the timespec64 arg from generic_update_time https://git.kernel.org/vfs/vfs/c/32586bb50943 [04/13] btrfs: have it use inode_update_timestamps https://git.kernel.org/vfs/vfs/c/51fc38e7c7d1 [05/13] fat: make fat_update_time get its own timestamp https://git.kernel.org/vfs/vfs/c/d6e7faae82dc [06/13] ubifs: have ubifs_update_time use inode_update_timestamps https://git.kernel.org/vfs/vfs/c/853ff59b434a [07/13] xfs: have xfs_vn_update_time gets its own timestamp https://git.kernel.org/vfs/vfs/c/7ad056c2cf36 [08/13] fs: drop the timespec64 argument from update_time https://git.kernel.org/vfs/vfs/c/3beae086b71f [09/13] fs: add infrastructure for multigrain timestamps https://git.kernel.org/vfs/vfs/c/b16956ed812f [10/13] tmpfs: add support for multigrain timestamps https://git.kernel.org/vfs/vfs/c/bd21ec574f16 [11/13] xfs: switch to multigrain timestamps https://git.kernel.org/vfs/vfs/c/fb9812d2c39e [12/13] ext4: switch to multigrain timestamps https://git.kernel.org/vfs/vfs/c/7fdf02299f5d [13/13] btrfs: convert to multigrain timestamps https://git.kernel.org/vfs/vfs/c/2ebbf04988b9
This series was applied to jaegeuk/f2fs.git (dev) by Christian Brauner <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Christian Brauner <[email protected]>:
Quoted 11 lines · On Mon, 07 Aug 2023 15:38:31 -0400 you wrote:
The VFS always uses coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes.
Unfortunately, this coarseness has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide to invalidate the cache.
[...]
Here is the summary with links:
- [f2fs-dev,v7,01/13] fs: remove silly warning from current_time
https://git.kernel.org/jaegeuk/f2fs/c/b3030e4f2344 - [f2fs-dev,v7,02/13] fs: pass the request_mask to generic_fillattr https://git.kernel.org/jaegeuk/f2fs/c/0d72b92883c6 - [f2fs-dev,v7,03/13] fs: drop the timespec64 arg from generic_update_time https://git.kernel.org/jaegeuk/f2fs/c/541d4c798a59 - [f2fs-dev,v7,04/13] btrfs: have it use inode_update_timestamps https://git.kernel.org/jaegeuk/f2fs/c/bb7cc0a62e47 - [f2fs-dev,v7,05/13] fat: make fat_update_time get its own timestamp (no matching commit) - [f2fs-dev,v7,06/13] ubifs: have ubifs_update_time use inode_update_timestamps (no matching commit) - [f2fs-dev,v7,07/13] xfs: have xfs_vn_update_time gets its own timestamp (no matching commit) - [f2fs-dev,v7,08/13] fs: drop the timespec64 argument from update_time (no matching commit) - [f2fs-dev,v7,09/13] fs: add infrastructure for multigrain timestamps https://git.kernel.org/jaegeuk/f2fs/c/ffb6cf19e063 - [f2fs-dev,v7,10/13] tmpfs: add support for multigrain timestamps https://git.kernel.org/jaegeuk/f2fs/c/d48c33972916 - [f2fs-dev,v7,11/13] xfs: switch to multigrain timestamps (no matching commit) - [f2fs-dev,v7,12/13] ext4: switch to multigrain timestamps https://git.kernel.org/jaegeuk/f2fs/c/0269b585868e - [f2fs-dev,v7,13/13] btrfs: convert to multigrain timestamps https://git.kernel.org/jaegeuk/f2fs/c/50e9ceef1d4f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html