Skip to contentSkip to conversation

Set a/m/c/crtime on inode creation

PATCH Applied Valerie Aurora 2 participants 8 messages Mar 10 – Mar 13

lore
Share & tools
lore
#0 lore raw

cover Set a/m/c/crtime on inode creation

Set the atime/mtime/ctime/crtime on inode creation. crtime is a little special because it is not kept in the VFS inode.

Valerie Aurora (2):
rpdfs: Set atime/mtime/ctime on inode creation
rpdfs: Set the inode creation time

 fs/rpdfs/dir.c   |  3 +++
 fs/rpdfs/inode.c | 22 ++++++++++++++++++++++
 fs/rpdfs/inode.h |  2 ++
 3 files changed, 27 insertions(+)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/2 rpdfs: Set atime/mtime/ctime on inode creation

Set the atime/mtime/ctime to the current time on inode creation.

---
 fs/rpdfs/inode.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/rpdfs/inode.c +5 -0
index 44f8cd515aa6..bdd31ce0b6da 100644
@@ -281,6 +281,7 @@ struct inode *rpdfs_iget(struct super_block *sb, struct rpdfs_ino_gen *ig)
 struct inode *rpdfs_new_inode(struct super_block *sb, struct rpdfs_ino_gen *ig)
 {
 	struct rpdfs_inode_info *ri;
+	struct timespec64 ts;
 	struct inode *inode;
 	int ret;
 
@@ -299,6 +300,10 @@ struct inode *rpdfs_new_inode(struct super_block *sb, struct rpdfs_ino_gen *ig)
 	ri->dirents.ref.alloc_counter = 0;
 	inode->i_ino = le64_to_cpu(ri->ig.ino);
 
+	ts = inode_set_ctime_current(inode);
+	inode_set_mtime_to_ts(inode, ts);
+	inode_set_atime_to_ts(inode, ts);
+
 	ret = insert_inode_locked4(inode, ig_hashval(ig), rpdfs_iget_test, ig);
 	if (ret < 0) {
 		discard_new_inode(inode);
Signature · 1 line
2.49.0
Applied
#2 lore raw

Re: [PATCH 1/2] rpdfs: Set atime/mtime/ctime on inode creation

Quoted 1 line · Valerie Aurora

Set the atime/mtime/ctime to the current time on inode creation.

Applied, thanks!

- z

#3 lore raw

PATCH 2/2 rpdfs: Set the inode creation time

In reply to Valerie Aurora

Setting inode creation time is slightly trickier than a/m/ctime because it's not tracked in the VFS inode. Add a function to set creation time at inode creation time.

---
 fs/rpdfs/dir.c   |  3 +++
 fs/rpdfs/inode.c | 17 +++++++++++++++++
 fs/rpdfs/inode.h |  2 ++
 3 files changed, 22 insertions(+)
fs/rpdfs/dir.c +3 -0
index 7d51c133cba0..71524e3f2839 100644
@@ -468,6 +468,9 @@ static struct inode *create_new_inode(struct mnt_idmap *idmap, struct inode *dir
 		apply_add_entry(rfi, &txn, dir, kd);
 	}
 
+	/* creation time is not tracked in the vfs inode so do it by hand */
+	rpdfs_inode_crtime_set(rfi, &txn, inode, inode_get_atime(inode));
+
 	/* sync changes to vfs inodes with inode blocks */
 	rpdfs_inode_txn_update(rfi, &txn, dir);
 	rpdfs_inode_txn_update(rfi, &txn, inode);
fs/rpdfs/inode.c +17 -0
index bdd31ce0b6da..4d24fa00512c 100644
@@ -359,6 +359,23 @@ void rpdfs_inode_txn_update(struct rpdfs_fs_info *rfi, struct rpdfs_transaction
 	ri->refresh_wcount = hnd->wcount;
 }
 
+/*
+ * Set the inode creation time.
+ */
+void rpdfs_inode_crtime_set(struct rpdfs_fs_info *rfi, struct rpdfs_transaction *txn,
+			    struct inode *inode, struct timespec64 ts)
+{
+	struct rpdfs_block_handle *hnd = NULL;
+	struct rpdfs_inode *rinode;
+	int ret;
+
+	ret = rpdfs_txn_use_prepared(rfi, txn, rpdfs_inode_bnr(inode), &hnd, RBAF_WRITE);
+	BUG_ON(ret < 0); /* caller must have prepared */
+
+	rinode = hnd->data;
+	rinode->crtime_nsec = cpu_ts64_to_le64_ns(ts);
+}
+
 /*
  * Start writing a previously dirtied vfs inode.
  *
fs/rpdfs/inode.h +2 -0
index 6b0fddb7f0fb..3ca3d248e338 100644
@@ -69,6 +69,8 @@ int rpdfs_inode_txn_prepare(struct rpdfs_fs_info *rfi, struct rpdfs_transaction
 			    struct inode *inode, rbaf_t rbaf);
 void rpdfs_inode_txn_update(struct rpdfs_fs_info *rfi, struct rpdfs_transaction *txn,
 			    struct inode *inode);
+void rpdfs_inode_crtime_set(struct rpdfs_fs_info *rfi, struct rpdfs_transaction *txn,
+			    struct inode *inode, struct timespec64 ts);
 
 int rpdfs_inode_init(void);
 void rpdfs_inode_exit(void);
Signature · 1 line
2.49.0
#4 lore raw

Re: [PATCH 2/2] rpdfs: Set the inode creation time

Quoted 6 lines · Valerie Aurora
fs/rpdfs/inode.c +6 -0
+/*
+ * Set the inode creation time.
+ */
+void rpdfs_inode_crtime_set(struct rpdfs_fs_info *rfi, struct rpdfs_transaction *txn,
+			    struct inode *inode, struct timespec64 ts)
+{

fs/rpdfs/inode.c void rpdfs_inode_txn_update(struct rpdfs_fs_info *rfi, struct rpdfs_transaction · line 377

Quoted 10 lines
fs/rpdfs/inode.c +10 -0
+	struct rpdfs_block_handle *hnd = NULL;
+	struct rpdfs_inode *rinode;
+	int ret;
+
+	ret = rpdfs_txn_use_prepared(rfi, txn, rpdfs_inode_bnr(inode), &hnd, RBAF_WRITE);
+	BUG_ON(ret < 0); /* caller must have prepared */
+
+	rinode = hnd->data;
+	rinode->crtime_nsec = cpu_ts64_to_le64_ns(ts);
+}

The pattern is that the in-memory inode (struct rpdfs_inode_info) is a struct that has private fs stuff along with the storage for the vfs inode. This is the FOO_I() pattern found all over fs/*. Refreshing the inode updates the in-memory version from the current block, and the "txn update" of the inode copies from memory to the block again.

So the way to do this is to have a local copy of the crtime in the rpdfs_inode_info. Copy it back and forth in copy_vfs_inode_to_rinode() and vice versa.

Then in the apply phase that wants to update crtime it updates the in-memory copy with something like:

	struct rpdfs_inode_info *ri = RPDFS_I(inode);
	ri->crtime_nsec = inode_atime_to_u64_nsec_or_whatever(inode);

This re-uses the current load from and store to the block and avoids another block hash lookup -- which is a bunch of rcu and spinlock barriers and will be a point of contention.

- z

#5 lore raw

Re: [PATCH 2/2] rpdfs: Set the inode creation time

Quoted 25 lines · Zach Brown
Quoted 6 lines · Valerie Aurora
fs/rpdfs/inode.c +6 -0
+/*
+ * Set the inode creation time.
+ */
+void rpdfs_inode_crtime_set(struct rpdfs_fs_info *rfi, struct rpdfs_transaction *txn,
+                         struct inode *inode, struct timespec64 ts)
+{

fs/rpdfs/inode.c void rpdfs_inode_txn_update(struct rpdfs_fs_info *rfi, struct rpdfs_transaction · line 377

Quoted 10 lines
fs/rpdfs/inode.c +10 -0
+     struct rpdfs_block_handle *hnd = NULL;
+     struct rpdfs_inode *rinode;
+     int ret;
+
+     ret = rpdfs_txn_use_prepared(rfi, txn, rpdfs_inode_bnr(inode), &hnd, RBAF_WRITE);
+     BUG_ON(ret < 0); /* caller must have prepared */
+
+     rinode = hnd->data;
+     rinode->crtime_nsec = cpu_ts64_to_le64_ns(ts);
+}

The pattern is that the in-memory inode (struct rpdfs_inode_info) is a struct that has private fs stuff along with the storage for the vfs inode. This is the FOO_I() pattern found all over fs/*. Refreshing the inode updates the in-memory version from the current block, and the "txn update" of the inode copies from memory to the block again.

Quoted 3 lines

So the way to do this is to have a local copy of the crtime in the rpdfs_inode_info. Copy it back and forth in copy_vfs_inode_to_rinode() and vice versa.

The reason I didn't do this is that creation time is only set at inode creation time and almost never read, so it seems like a waste of memory to put it in the rpdfs_inode_info. It's only accessed through getattr, so that needs to do its own separate block lookup anyway.

Quoted 9 lines

Then in the apply phase that wants to update crtime it updates the in-memory copy with something like:

        struct rpdfs_inode_info *ri = RPDFS_I(inode);
        ri->crtime_nsec = inode_atime_to_u64_nsec_or_whatever(inode);

This re-uses the current load from and store to the block and avoids another block hash lookup -- which is a bunch of rcu and spinlock barriers and will be a point of contention.

That's a good point. The other option I thought of is a rpdfs_inode_txn_update_create() that takes a creation time arg and is only used at inode creation.

But if you prefer, we can keep creation time in rpdfs_inode_info. Let me know what you want.

Valerie

#6 lore raw

Re: [PATCH 2/2] rpdfs: Set the inode creation time

Quoted 5 lines · Valerie Aurora

That's a good point. The other option I thought of is a rpdfs_inode_txn_update_create() that takes a creation time arg and is only used at inode creation.

Actually, instead of a creation time, just add a flag saying to set the creation time to the atime. Then the regular non-create() version just calls the create version with the don't-set-creation-time flag.

Valerie

#7 lore raw

Re: [PATCH 2/2] rpdfs: Set the inode creation time

In reply to Valerie Aurora
Quoted 7 lines · Valerie Aurora
Quoted 6 lines · Zach Brown
Quoted 3 lines · Valerie Aurora
fs/rpdfs/inode.c +3 -0
+     rinode = hnd->data;
+     rinode->crtime_nsec = cpu_ts64_to_le64_ns(ts);
+}

[...]

Quoted 8 lines
Quoted 3 lines

So the way to do this is to have a local copy of the crtime in the rpdfs_inode_info. Copy it back and forth in copy_vfs_inode_to_rinode() and vice versa.

The reason I didn't do this is that creation time is only set at inode creation time and almost never read, so it seems like a waste of memory to put it in the rpdfs_inode_info. It's only accessed through getattr, so that needs to do its own separate block lookup anyway.

I like the instinct but I think in this case the memory savings isn't worth the special case and additional code. VFS inodes are immense, I imagine we're down in the single digit percentages. (ish, yeah, say around 8/728)

There's also some forward-looking context that might not be obvious and which is probably nudging my preference.

While it takes a block lookup today to validate the cached inode contents, that's not necessarily always going to be the case. We're going to get cached vfs objects (dentries -> d_revalidate) where the validation frequency is so bonkers that we'll probably want to modify the cached object on invalidation rather than always doing block lookups. The revalidate test could be a local seqlock test, or something, rather than the global hash table lookup.

Quoted 2 lines

But if you prefer, we can keep creation time in rpdfs_inode_info. Let me know what you want.

Yes please! I like the consistency across this class of inode metadata.

- z