From: Christian Brauner <brauner@kernel.org>
To: Jeff Layton <jlayton@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
"Darrick J. Wong" <djwong@kernel.org>,
Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Dave Chinner <david@fromorbit.com>,
Chuck Lever <chuck.lever@oracle.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-xfs@vger.kernel.org, linux-mm@kvack.org,
linux-nfs@vger.kernel.org
Subject: Re: [RFC PATCH 1/3][RESEND] fs: add infrastructure for opportunistic high-res ctime/mtime updates
Date: Tue, 11 Apr 2023 17:07:12 +0200 [thread overview]
Message-ID: <20230411-unwesen-prunk-cb7de3cc6cc8@brauner> (raw)
In-Reply-To: <20230411143702.64495-2-jlayton@kernel.org>
On Tue, Apr 11, 2023 at 10:37:00AM -0400, Jeff Layton wrote:
> The VFS always uses coarse-grained timestamp updates for filling out the
> ctime and mtime after a change. This has the benefit of allowing
> filesystems to optimize away metadata updates.
>
> Unfortunately, this has always been an issue when we're exporting via
> NFSv3, which relies on timestamps to validate caches. Even with NFSv4, a
> lot of exported filesystems don't properly support a change attribute
> and are subject to the same problem of timestamp granularity. Other
> applications have similar issues (e.g backup applications).
>
> Switching to always using high resolution timestamps would improve the
> situation for NFS, but that becomes rather expensive, as we'd have to
> log a lot more metadata updates.
>
> This patch grabs a new i_state bit to use as a flag that filesystems can
> set in their getattr routine to indicate that the mtime or ctime was
> queried since it was last updated.
>
> It then adds a new current_cmtime function that acts like the
> current_time helper, but will conditionally grab high-res timestamps
> when the i_state flag is set in the inode.
>
> This allows NFS and other applications to reap the benefits of high-res
> ctime and mtime timestamps, but at a substantially lower cost than
> fetching them every time.
>
> Cc: Dave Chinner <david@fromorbit.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
> fs/inode.c | 40 ++++++++++++++++++++++++++++++++++++++--
> fs/stat.c | 10 ++++++++++
> include/linux/fs.h | 5 ++++-
> 3 files changed, 52 insertions(+), 3 deletions(-)
>
> diff --git a/fs/inode.c b/fs/inode.c
> index 4558dc2f1355..3630f67fd042 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -2062,6 +2062,42 @@ static int __file_update_time(struct file *file, struct timespec64 *now,
> return ret;
> }
>
> +/**
> + * current_cmtime - Return FS time (possibly high-res)
> + * @inode: inode.
> + *
> + * Return the current time truncated to the time granularity supported by
> + * the fs, as suitable for a ctime or mtime change. If something recently
> + * fetched the ctime or mtime out of the inode via getattr, then get a
> + * high-resolution timestamp.
> + *
> + * Note that inode and inode->sb cannot be NULL.
> + * Otherwise, the function warns and returns coarse time without truncation.
> + */
> +struct timespec64 current_cmtime(struct inode *inode)
> +{
> + struct timespec64 now;
> +
> + if (unlikely(!inode->i_sb)) {
> + WARN(1, "%s() called with uninitialized super_block in the inode", __func__);
How would this happen? Seems weird to even bother checking this.
> + ktime_get_coarse_real_ts64(&now);
> + return now;
> + }
> +
> + /* Do a lockless check for the flag before taking the spinlock */
> + if (READ_ONCE(inode->i_state) & I_CMTIME_QUERIED) {
> + ktime_get_real_ts64(&now);
> + spin_lock(&inode->i_lock);
> + inode->i_state &= ~I_CMTIME_QUERIED;
> + spin_unlock(&inode->i_lock);
> + } else {
> + ktime_get_coarse_real_ts64(&now);
> + }
> +
> + return timestamp_truncate(now, inode);
> +}
> +EXPORT_SYMBOL(current_cmtime);
> +
> /**
> * file_update_time - update mtime and ctime time
> * @file: file accessed
> @@ -2080,7 +2116,7 @@ int file_update_time(struct file *file)
> {
> int ret;
> struct inode *inode = file_inode(file);
> - struct timespec64 now = current_time(inode);
> + struct timespec64 now = current_cmtime(inode);
>
> ret = inode_needs_update_time(inode, &now);
> if (ret <= 0)
> @@ -2109,7 +2145,7 @@ static int file_modified_flags(struct file *file, int flags)
> {
> int ret;
> struct inode *inode = file_inode(file);
> - struct timespec64 now = current_time(inode);
> + struct timespec64 now = current_cmtime(inode);
>
> /*
> * Clear the security bits if the process is not being run by root.
> diff --git a/fs/stat.c b/fs/stat.c
> index 7c238da22ef0..d8b80a2e36b7 100644
> --- a/fs/stat.c
> +++ b/fs/stat.c
> @@ -64,6 +64,16 @@ void generic_fillattr(struct mnt_idmap *idmap, struct inode *inode,
> }
> EXPORT_SYMBOL(generic_fillattr);
>
> +void fill_cmtime_and_mark(struct inode *inode, struct kstat *stat)
> +{
> + spin_lock(&inode->i_lock);
> + inode->i_state |= I_CMTIME_QUERIED;
> + stat->ctime = inode->i_ctime;
> + stat->mtime = inode->i_mtime;
> + spin_unlock(&inode->i_lock);
> +}
> +EXPORT_SYMBOL(fill_cmtime_and_mark);
So that means that each stat call would mark an inode for a
high-resolution update. There's some performance concerns here. Calling
stat() is super common and it would potentially make the next iop more
expensive. Recursively changing ownership in the container use-case come
to mind which are already expensive.
next prev parent reply other threads:[~2023-04-11 15:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 14:36 [RFC PATCH 0/3][RESEND] fs: opportunistic high-res file timestamps Jeff Layton
2023-04-11 14:37 ` [RFC PATCH 1/3][RESEND] fs: add infrastructure for opportunistic high-res ctime/mtime updates Jeff Layton
2023-04-11 14:42 ` Darrick J. Wong
2023-04-11 14:54 ` Jeff Layton
2023-04-11 15:07 ` Christian Brauner [this message]
2023-04-11 16:04 ` Jeff Layton
2023-04-21 10:23 ` Jan Kara
2023-04-11 14:37 ` [RFC PATCH 2/3][RESEND] shmem: mark for high-res timestamps on next update after getattr Jeff Layton
2023-04-24 7:20 ` kernel test robot
2023-04-11 14:37 ` [RFC PATCH 3/3][RESEND] xfs: mark the inode for high-res timestamp update in getattr Jeff Layton
2023-04-11 14:54 ` Darrick J. Wong
2023-04-11 15:15 ` Christian Brauner
2023-04-11 16:05 ` Jeff Layton
2023-04-11 15:58 ` Jeff Layton
2023-04-21 2:04 ` kernel test robot
2023-04-11 23:13 ` [RFC PATCH 0/3][RESEND] fs: opportunistic high-res file timestamps Dave Chinner
2023-04-15 11:35 ` Amir Goldstein
2023-04-15 12:13 ` Jeff Layton
2023-04-15 16:19 ` [RFC PATCH 0/3][RESEND] " Chuck Lever III
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=20230411-unwesen-prunk-cb7de3cc6cc8@brauner \
--to=brauner@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chuck.lever@oracle.com \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hughd@google.com \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).