From: Jeff Layton <jlayton@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Cc: Mateusz Guzik <mjguzik@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH] fs: don't overwrite the nsec field if I_CTIME_QUERIED is already set
Date: Fri, 09 Aug 2024 09:39:43 -0400 [thread overview]
Message-ID: <20240809-mgtime-v1-1-b2cab4f1558d@kernel.org> (raw)
When fetching the ctime's nsec value for a stat-like operation, do a
simple fetch first and avoid the atomic_fetch_or if the flag is already
set.
Suggested-by: Mateusz Guzik <mjguzik@gmail.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
I'm running tests on this now, but I don't expect any problems.
This is based on top of Christian's vfs.mgtime branch. It may be best to
squash this into 6feb43ecdd8e ("fs: add infrastructure for multigrain
timestamps").
---
To: Alexander Viro <viro@zeniv.linux.org.uk>
To: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
fs/stat.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/stat.c b/fs/stat.c
index f2bf7cca64b2..9eb6d9b2d010 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -35,8 +35,8 @@
* @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 ensure a distinct timestamp.
+ * in @stat. When fetching the value, flag it as QUERIED (if not already)
+ * so the next write will record a distinct timestamp.
*/
void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode)
{
@@ -50,7 +50,10 @@ void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode)
stat->mtime = inode_get_mtime(inode);
stat->ctime.tv_sec = inode->i_ctime_sec;
- stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)) & ~I_CTIME_QUERIED;
+ stat->ctime.tv_nsec = (u32)atomic_read(pcn);
+ if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED))
+ stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn));
+ stat->ctime.tv_nsec &= ~I_CTIME_QUERIED;
trace_fill_mg_cmtime(inode, &stat->ctime, &stat->mtime);
}
EXPORT_SYMBOL(fill_mg_cmtime);
---
base-commit: 9000eec2bdc08a0b9027427f9d3d9a3545694258
change-id: 20240809-mgtime-cbc2aa6dc0fe
Best regards,
--
Jeff Layton <jlayton@kernel.org>
next reply other threads:[~2024-08-09 13:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-09 13:39 Jeff Layton [this message]
2024-08-09 14:55 ` [PATCH] fs: don't overwrite the nsec field if I_CTIME_QUERIED is already set Christian Brauner
2024-08-09 15:05 ` Jeff Layton
2024-08-09 15:17 ` Christian Brauner
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=20240809-mgtime-v1-1-b2cab4f1558d@kernel.org \
--to=jlayton@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--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