Linux Documentation
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Christian Brauner <brauner@kernel.org>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Jan Kara <jack@suse.cz>,  Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>
Cc: linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	 Jeff Layton <jlayton@kernel.org>
Subject: [PATCH] fs: use multigrain timestamps only with nanosecond granularity
Date: Thu, 19 Nov 2026 16:41:01 -0800	[thread overview]
Message-ID: <20261119-mgtime-v1-1-fd28399a5557@kernel.org> (raw)

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.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
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(-)

diff --git a/Documentation/filesystems/multigrain-ts.rst b/Documentation/filesystems/multigrain-ts.rst
index c779e47284e8..81ea632c7a4b 100644
--- a/Documentation/filesystems/multigrain-ts.rst
+++ b/Documentation/filesystems/multigrain-ts.rst
@@ -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.
diff --git a/fs/inode.c b/fs/inode.c
index de207f2f95a9..9cc28306feda 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -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,
-- 
Jeff Layton <jlayton@kernel.org>


                 reply	other threads:[~2026-11-20  0:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119-mgtime-v1-1-fd28399a5557@kernel.org \
    --to=jlayton@kernel.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=jack@suse.cz \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox