fs: use multigrain timestamps only with nanosecond granularity
Subsystems (2)
PATCH 1/1 fs: use multigrain timestamps only with nanosecond granularity
Multigrain timestamps promise that a change after the ctime was queried shows a later ctime: inode_set_ctime_current() takes a fine-grained time when the coarse one isn't past the queried value. But it truncates that time to s_time_gran, and on a superblock with coarse granularity, such as ext4 with 128-byte inodes (one second), the truncated fine-grained time is no later than the coarse one, and the update is skipped. The inode is still flagged IOP_MGTIME, so a caller relying on is_mgtime() for that promise, such as nfsd deciding whether it can move the change attribute by moving ctime, is misled, and the multigrain machinery only costs a fine-grained clock read.
Set IOP_MGTIME only on a superblock whose s_time_gran is 1. Every FS_MGTIME filesystem (btrfs, ext4, f2fs, tmpfs, xfs) sets s_time_gran before it allocates an inode; document that it must.
---
When I originally did the multigrain timestamp work, I missed the fact that ext4 can have an s_time_gran of NSEC_PER_SEC. I think this is a very uncommon setup, so I don't see a need for a huge rush for this one. Please consider for v7.5.
--- Documentation/filesystems/multigrain-ts.rst | 6 ++++++ fs/inode.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
Documentation/filesystems/multigrain-ts.rst +6 -0
@@ -123,3 +123,9 @@ inode_set_ctime_current(). If the filesystem has a ->getattr routine that doesn't call generic_fillattr, then it should call fill_mg_cmtime() to fill those values. For setattr, it should use setattr_copy() to update the timestamps, or otherwise mimic its behavior. + +Multigrain timestamps are only enabled on a superblock whose s_time_gran is 1: +a fine-grained timestamp truncated to a coarser granularity can be no later +than the coarse-grained one, so the kernel can't guarantee a visible change. +The filesystem must set s_time_gran before it allocates any inode, since +whether an inode uses multigrain timestamps is decided when it is allocated.
fs/inode.c +1 -1
@@ -239,7 +239,7 @@ int inode_init_always_gfp(struct super_block *sb, struct inode *inode, gfp_t gfp inode->i_opflags =0 ;if (sb->s_xattr) inode->i_opflags |=IOP_XATTR ; -if (sb->s_type->fs_flags &FS_MGTIME ) +if ((sb->s_type->fs_flags &FS_MGTIME ) && sb->s_time_gran ==1 ) inode->i_opflags |=IOP_MGTIME ;i_uid_write (inode,0 );i_gid_write (inode,0 );
---
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
change-id: 20261119-mgtime-fc070b268bdf
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 11 lines · Jeff Layton
Multigrain timestamps promise that a change after the ctime was queried shows a later ctime:
inode_set_ctime_current()takes a fine-grained time when the coarse one isn't past the queried value. But it truncates that time tos_time_gran, and on a superblock with coarse granularity, such as ext4 with 128-byte inodes (one second), the truncated fine-grained time is no later than the coarse one, and the update is skipped. The inode is still flaggedIOP_MGTIME, so a caller relying onis_mgtime()for that promise, such as nfsd deciding whether it can move the change attribute by moving ctime, is misled, and the multigrain machinery only costs a fine-grained clock read.
Quoted 5 lines
Set
IOP_MGTIMEonly on a superblock whoses_time_granis 1. EveryFS_MGTIMEfilesystem (btrfs, ext4, f2fs, tmpfs, xfs) setss_time_granbefore it allocates an inode; document that it must.Signed-off-by Jeff Layton <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 46 lines
---
When I originally did the multigrain timestamp work, I missed the fact that ext4 can have ans_time_granofNSEC_PER_SEC. I think this is a very uncommon setup, so I don't see a need for a huge rush for this one. Please consider for v7.5.--- Documentation/filesystems/multigrain-ts.rst | 6 ++++++ fs/inode.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)Documentation/filesystems/multigrain-ts.rst +6
-0@@ -123,3 +123,9 @@ inode_set_ctime_current(). If the filesystem has a ->getattr routine that doesn't call generic_fillattr, then it should call fill_mg_cmtime() to fill those values. For setattr, it should use setattr_copy() to update the timestamps, or otherwise mimic its behavior. + +Multigrain timestamps are only enabled on a superblock whose s_time_gran is 1: +a fine-grained timestamp truncated to a coarser granularity can be no later +than the coarse-grained one, so the kernel can't guarantee a visible change. +The filesystem must set s_time_gran before it allocates any inode, since +whether an inode uses multigrain timestamps is decided when it is allocated.fs/inode.c +1
-2@@ -239,7 +239,7 @@ int inode_init_always_gfp(struct super_block *sb, struct inode *inode, gfp_t gfp inode->i_opflags =0 ;if (sb->s_xattr) inode->i_opflags |=IOP_XATTR ; -if (sb->s_type->fs_flags &FS_MGTIME ) +if ((sb->s_type->fs_flags &FS_MGTIME ) && sb->s_time_gran ==1 ) inode->i_opflags |=IOP_MGTIME ;i_uid_write (inode,0 );i_gid_write (inode,0 ); ---base-commit:
65e4fd942f72a9dba0e4e257290c4fa1aa756854
change-id: 20261119-mgtime-fc070b268bdfBest regards,
Signature · 1 line
Jeff Layton <[email protected]>
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR