Skip to contentSkip to conversation

fs: don't overwrite the nsec field if I_CTIME_QUERIED is already set

PATCH In review Jeff Layton 2 participants 4 messages Aug 9, 2024 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: don't overwrite the nsec field if I_CTIME_QUERIED is already set

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.

---
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 <[email protected]>
To: Christian Brauner <[email protected]>
To: Jan Kara <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 fs/stat.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/stat.c +6 -3
index f2bf7cca64b2..9eb6d9b2d010 100644
@@ -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,

Signature · 1 line
Jeff Layton <[email protected]>
#1 lore raw
Quoted 4 lines · Jeff Layton

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.

Quoted 8 lines

---
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").

Squashed it. Can you double-check that things look correct?

#2 lore raw
Quoted 12 lines · Christian Brauner
Quoted 11 lines · Jeff Layton

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.

---
I'm running tests on this now, but I don't expect any problems.

Quoted 7 lines
Quoted 5 lines

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").

Squashed it. Can you double-check that things look correct?

One minor issue in fill_mg_cmtime:

-------------8<-----------------

        if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED))
                stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn));
        trace_fill_mg_cmtime(inode, &stat->ctime, &stat->mtime);
        stat->ctime.tv_nsec &= ~I_CTIME_QUERIED;
}

-------------8<-----------------

I'd swap the last two lines of the function. We print the ctime in the tracepoint as a timestamp, so if the QUERIED bit is present it's going to look funny. We _know_ that it's flagged after this function, so leaving it set is not terribly helpful.

Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw
Quoted 29 lines · Jeff Layton
Quoted 12 lines · Christian Brauner
Quoted 11 lines · Jeff Layton

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.

---
I'm running tests on this now, but I don't expect any problems.

Quoted 7 lines
Quoted 5 lines

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").

Squashed it. Can you double-check that things look correct?

One minor issue in fill_mg_cmtime:

-------------8<-----------------

        if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED))
                stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn));
        trace_fill_mg_cmtime(inode, &stat->ctime, &stat->mtime);
        stat->ctime.tv_nsec &= ~I_CTIME_QUERIED;
}
Quoted 6 lines

-------------8<-----------------

I'd swap the last two lines of the function. We print the ctime in the tracepoint as a timestamp, so if the QUERIED bit is present it's going to look funny. We _know_ that it's flagged after this function, so leaving it set is not terribly helpful.

Bah, fat-fingered on my end. I did intend to place it after. Thanks!