fs: rename i_atime and i_mtime fields to __i_atime and __i_mtime
Subsystems (26)
Jeff Layton
maintainerPATCH 85/87 fs: rename i_atime and i_mtime fields to __i_atime and __i_mtime
Make it clear that these fields are private now, and that the accessors should be used instead.
--- include/linux/fs.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
include/linux/fs.h +7 -7
@@ -671,9 +671,9 @@ struct inode { };dev_t i_rdev;loff_t i_size; -struct timespec64 i_atime; -struct timespec64 i_mtime; -struct timespec64 __i_ctime;/* use inode_*_ctime accessors! */ +struct timespec64 __i_atime;/* use inode_*_atime accessors */ +struct timespec64 __i_mtime;/* use inode_*_mtime accessors */ +struct timespec64 __i_ctime;/* use inode_*_ctime accessors */ spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes;u8 i_blkbits;
@@ -1555,13 +1555,13 @@ static inline struct timespec64 inode_set_ctime(struct inode *inode,static inline struct timespec64 inode_get_atime (const struct inode *inode) { -return inode->i_atime; +return inode->__i_atime; }static inline struct timespec64 inode_set_atime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->i_atime = ts; + inode->__i_atime = ts;return ts; }
@@ -1575,13 +1575,13 @@ static inline struct timespec64 inode_set_atime(struct inode *inode,static inline struct timespec64 inode_get_mtime (const struct inode *inode) { -return inode->i_mtime; +return inode->__i_mtime; }static inline struct timespec64 inode_set_mtime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->i_mtime = ts; + inode->__i_mtime = ts;return ts; }
Signature · 1 line
2.41.0
Jeff Layton
maintainerPATCH 86/87 fs: switch timespec64 fields in inode to discrete integers
This shaves 8 bytes off struct inode, according to pahole.
--- include/linux/fs.h | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)
include/linux/fs.h +23 -9
@@ -671,9 +671,12 @@ struct inode { };dev_t i_rdev;loff_t i_size; -struct timespec64 __i_atime;/* use inode_*_atime accessors */ -struct timespec64 __i_mtime;/* use inode_*_mtime accessors */ -struct timespec64 __i_ctime;/* use inode_*_ctime accessors */ +time64_t i_atime_sec; +time64_t i_mtime_sec; +time64_t i_ctime_sec; +u32 i_atime_nsec; +u32 i_mtime_nsec; +u32 i_ctime_nsec;spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes;u8 i_blkbits;
@@ -1519,7 +1522,9 @@ struct timespec64 inode_set_ctime_current(struct inode *inode);*/ static inline struct timespec64 inode_get_ctime (const struct inode *inode) { -return inode->__i_ctime; +struct timespec64 ts = { .tv_sec = inode->i_ctime_sec, + .tv_nsec = inode->i_ctime_nsec }; +return ts; }/**
@@ -1532,7 +1537,8 @@ static inline struct timespec64 inode_get_ctime(const struct inode *inode)static inline struct timespec64 inode_set_ctime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->__i_ctime = ts; + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_sec;return ts; }
@@ -1555,13 +1561,17 @@ static inline struct timespec64 inode_set_ctime(struct inode *inode,static inline struct timespec64 inode_get_atime (const struct inode *inode) { -return inode->__i_atime; +struct timespec64 ts = { .tv_sec = inode->i_atime_sec, + .tv_nsec = inode->i_atime_nsec }; + +return ts; }static inline struct timespec64 inode_set_atime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->__i_atime = ts; + inode->i_atime_sec = ts.tv_sec; + inode->i_atime_nsec = ts.tv_sec;return ts; }
@@ -1575,13 +1585,17 @@ static inline struct timespec64 inode_set_atime(struct inode *inode,static inline struct timespec64 inode_get_mtime (const struct inode *inode) { -return inode->__i_mtime; +struct timespec64 ts = { .tv_sec = inode->i_mtime_sec, + .tv_nsec = inode->i_mtime_nsec }; + +return ts; }static inline struct timespec64 inode_set_mtime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->__i_mtime = ts; + inode->i_atime_sec = ts.tv_sec; + inode->i_atime_nsec = ts.tv_sec;return ts; }
Signature · 1 line
2.41.0
Jeff Layton
maintainerPATCH 87/87 fs: move i_blocks up a few places in struct inode
In reply to Jeff LaytonThe recent change to use discrete integers instead of struct timespec64 in struct inode shaved 8 bytes off of it, but it also moves the i_lock into the previous cacheline, away from the fields that it protects.
Move i_blocks up above the i_lock, which moves the new 4 byte hole to just after the timestamps, without changing the size of the structure.
--- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fs.h +1 -1
@@ -677,11 +677,11 @@ struct inode {u32 i_atime_nsec;u32 i_mtime_nsec;u32 i_ctime_nsec; +blkcnt_t i_blocks;spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes;u8 i_blkbits;u8 i_write_hint; -blkcnt_t i_blocks;#ifdef __NEED_I_SIZE_ORDEREDseqcount_t i_size_seqcount;
Signature · 1 line
2.41.0
Re: [PATCH 87/87] fs: move i_blocks up a few places in struct inode
Quoted 8 lines · On Thu, Sep 28, 2023 at 2:06 PM Jeff Layton <[email protected]> wrote:
The recent change to use discrete integers instead of struct timespec64 in struct inode shaved 8 bytes off of it, but it also moves the
i_lockinto the previous cacheline, away from the fields that it protects.Move
i_blocksup above thei_lock, which moves the new 4 byte hole to just after the timestamps, without changing the size of the structure.
Instead of creating an implicit hole, can you please move i_generation to fill the 4 bytes hole.
It makes sense in the same cache line with i_ino and I could use the vacant 4 bytes hole above i_fsnotify_mask to expand the mask to 64bit (the 32bit event mask space is running out).
Thanks,
Amir.
Quoted 25 lines
Signed-off-by Jeff Layton <[email protected]>--- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/fs.h +1
-2@@ -677,11 +677,11 @@ struct inode {u32 i_atime_nsec;u32 i_mtime_nsec;u32 i_ctime_nsec; +blkcnt_t i_blocks;spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes;u8 i_blkbits;u8 i_write_hint; -blkcnt_t i_blocks;#ifdef __NEED_I_SIZE_ORDEREDseqcount_t i_size_seqcount; --2.41.0
Jeff Layton
maintainerRe: [PATCH 87/87] fs: move i_blocks up a few places in struct inode
Quoted 13 lines · Amir Goldstein
Quoted 8 lines · On Thu, Sep 28, 2023 at 2:06 PM Jeff Layton <[email protected]> wrote:
The recent change to use discrete integers instead of struct timespec64 in struct inode shaved 8 bytes off of it, but it also moves the
i_lockinto the previous cacheline, away from the fields that it protects.Move
i_blocksup above thei_lock, which moves the new 4 byte hole to just after the timestamps, without changing the size of the structure.Instead of creating an implicit hole, can you please move
i_generationto fill the 4 bytes hole.
Quoted 7 lines
It makes sense in the same cache line with
i_inoand I could use the vacant 4 bytes hole abovei_fsnotify_maskto expand the mask to 64bit (the 32bit event mask space is running out).Thanks,
Amir.
Sounds like a plan. Resulting struct inode size is the same (616 bytes with my kdevops kconfig). BTW: all of these changes are in my "amtime" branch if anyone wants to pull them down.
--
Jeff Layton <[email protected]>
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 3 lines · Jeff Layton
This shaves 8 bytes off struct inode, according to pahole.
Signed-off-by Jeff Layton <[email protected]>
FWIW, this is similar to the approach that Deepa suggested back in 2016:
https://lore.kernel.org/lkml/[email protected]/
It was NaKed at the time because of the added complexity, though it would have been much easier to do it then, as we had to touch all the timespec references anyway.
The approach still seems ok to me, but I'm not sure it's worth doing it now if we didn't do it then.
Arnd
Jeff Layton
maintainerRe: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Jeff Layton
This shaves 8 bytes off struct inode, according to pahole.
Signed-off-by Jeff Layton <[email protected]>FWIW, this is similar to the approach that Deepa suggested back in 2016:
Quoted 9 lines
https://lore.kernel.org/lkml/[email protected]/
It was NaKed at the time because of the added complexity, though it would have been much easier to do it then, as we had to touch all the timespec references anyway.
The approach still seems ok to me, but I'm not sure it's worth doing it now if we didn't do it then.
I remember seeing those patches go by. I don't remember that change being NaK'ed, but I wasn't paying close attention at the time
Looking at it objectively now, I think it's worth it to recover 8 bytes per inode and open a 4 byte hole that Amir can use to grow the i_fsnotify_mask. We might even able to shave off another 12 bytes eventually if we can move to a single 64-bit word per timestamp.
It is a lot of churn though.
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerRe: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 41 lines · Jeff Layton
This shaves 8 bytes off struct inode, according to pahole.
Signed-off-by Jeff Layton <[email protected]>--- include/linux/fs.h | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-)include/linux/fs.h +9
-4@@ -671,9 +671,12 @@ struct inode { };dev_t i_rdev;loff_t i_size; -struct timespec64 __i_atime;/* use inode_*_atime accessors */ -struct timespec64 __i_mtime;/* use inode_*_mtime accessors */ -struct timespec64 __i_ctime;/* use inode_*_ctime accessors */ +time64_t i_atime_sec; +time64_t i_mtime_sec; +time64_t i_ctime_sec; +u32 i_atime_nsec; +u32 i_mtime_nsec; +u32 i_ctime_nsec;spinlock_t i_lock;/* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes;u8 i_blkbits;@@ -1519,7 +1522,9 @@ struct timespec64 inode_set_ctime_current(struct inode *inode);*/ static inline struct timespec64 inode_get_ctime (const struct inode *inode) { -return inode->__i_ctime; +struct timespec64 ts = { .tv_sec = inode->i_ctime_sec, + .tv_nsec = inode->i_ctime_nsec }; +return ts; }/**
include/linux/fs.h static inline struct timespec64 inode_get_ctime(const struct inode *inode) · line 1541
Quoted 6 lines
include/linux/fs.h +2
-1@@ -1532,7 +1537,8 @@ static inline struct timespec64 inode_get_ctime(const struct inode *inode)static inline struct timespec64 inode_set_ctime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->__i_ctime = ts; + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_sec;
Bug above and in the other inode_set_?time_to_ts() functions. This isn't setting the nsec field correctly.
Quoted 34 lines
include/linux/fs.h +8
-3return ts; }@@ -1555,13 +1561,17 @@ static inline struct timespec64 inode_set_ctime(struct inode *inode,static inline struct timespec64 inode_get_atime (const struct inode *inode) { -return inode->__i_atime; +struct timespec64 ts = { .tv_sec = inode->i_atime_sec, + .tv_nsec = inode->i_atime_nsec }; + +return ts; }static inline struct timespec64 inode_set_atime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->__i_atime = ts; + inode->i_atime_sec = ts.tv_sec; + inode->i_atime_nsec = ts.tv_sec;return ts; }@@ -1575,13 +1585,17 @@ static inline struct timespec64 inode_set_atime(struct inode *inode,static inline struct timespec64 inode_get_mtime (const struct inode *inode) { -return inode->__i_mtime; +struct timespec64 ts = { .tv_sec = inode->i_mtime_sec, + .tv_nsec = inode->i_mtime_nsec };
include/linux/fs.h static inline struct timespec64 inode_set_atime(struct inode *inode, · line 1598
Quoted 10 lines
include/linux/fs.h +4
-1+ +return ts; }static inline struct timespec64 inode_set_mtime_to_ts (struct inode *inode,struct timespec64 ts) { - inode->__i_mtime = ts; + inode->i_atime_sec = ts.tv_sec; + inode->i_atime_nsec = ts.tv_sec;
Doh! s/atime/mtime/ in the above lines.
include/linux/fs.h static inline struct timespec64 inode_get_ctime(const struct inode *inode) · line 1544
Quoted 3 lines
include/linux/fs.h +0
-0return ts; }
Both bugs are fixed in my tree.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 19 lines · Jeff Layton
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Jeff Layton
This shaves 8 bytes off struct inode, according to pahole.
Signed-off-by Jeff Layton <[email protected]>FWIW, this is similar to the approach that Deepa suggested back in 2016:
Quoted 9 lines
https://lore.kernel.org/lkml/[email protected]/
It was NaKed at the time because of the added complexity, though it would have been much easier to do it then, as we had to touch all the timespec references anyway.
The approach still seems ok to me, but I'm not sure it's worth doing it now if we didn't do it then.
Quoted 7 lines
I remember seeing those patches go by. I don't remember that change being NaK'ed, but I wasn't paying close attention at the time
Looking at it objectively now, I think it's worth it to recover 8 bytes per inode and open a 4 byte hole that Amir can use to grow the
i_fsnotify_mask. We might even able to shave off another 12 bytes eventually if we can move to a single 64-bit word per timestamp.
I don't think you can, since btrfs timestamps utilize s64 seconds counting in both directions from the Unix epoch. They also support ns resolution:
struct btrfs_timespec {
__le64 sec;
__le32 nsec;
} __attribute__ ((__packed__));--D
Quoted 3 lines
It is a lot of churn though.
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerRe: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
Quoted 28 lines · Darrick J. Wong
Quoted 19 lines · Jeff Layton
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Jeff Layton
This shaves 8 bytes off struct inode, according to pahole.
Signed-off-by Jeff Layton <[email protected]>FWIW, this is similar to the approach that Deepa suggested back in 2016:
Quoted 9 lines
https://lore.kernel.org/lkml/[email protected]/
It was NaKed at the time because of the added complexity, though it would have been much easier to do it then, as we had to touch all the timespec references anyway.
The approach still seems ok to me, but I'm not sure it's worth doing it now if we didn't do it then.
Quoted 7 lines
I remember seeing those patches go by. I don't remember that change being NaK'ed, but I wasn't paying close attention at the time
Looking at it objectively now, I think it's worth it to recover 8 bytes per inode and open a 4 byte hole that Amir can use to grow the
i_fsnotify_mask. We might even able to shave off another 12 bytes eventually if we can move to a single 64-bit word per timestamp.
Quoted 9 lines
I don't think you can, since btrfs timestamps utilize s64 seconds counting in both directions from the Unix epoch. They also support ns resolution:
struct btrfs_timespec { __le64 sec; __le32 nsec; } __attribute__ ((__packed__));
Correct. We'd lose some fidelity in currently stored timestamps, but as Linus and Ted pointed out, anything below ~100ns granularity is effectively just noise, as that's the floor overhead for calling into the kernel. It's hard to argue that any application needs that sort of timestamp resolution, at least with contemporary hardware.
Doing that would mean that tests that store specific values in the atime/mtime and expect to be able to fetch exactly that value back would break though, so we'd have to be OK with that if we want to try it. The good news is that it's relatively easy to experiment with new ways to store timestamps with these wrappers in place.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 87/87] fs: move i_blocks up a few places in struct inode
In reply to Jeff LaytonQuoted 3 lines · Jeff Layton
Move
i_blocksup above thei_lock, which moves the new 4 byte hole to just after the timestamps, without changing the size of the structure.
I'm sure others have mentioned this, but 'struct inode' is marked with __randomize_layout, so the actual layout may end up being very different.
I'm personally not convinced the whole structure randomization is worth it - it's easy enough to figure out for any distro kernel since the seed has to be the same across machines for modules to work, so even if the seed isn't "public", any layout is bound to be fairly easily discoverable.
So the whole randomization only really works for private kernel builds, and it adds this kind of pain where "optimizing" the structure layout is kind of pointless depending on various options.
I certainly *hope* no distro enables that pointless thing, but it's a worry.
Linus
Jeff Layton
maintainerRe: [PATCH 87/87] fs: move i_blocks up a few places in struct inode
Quoted 15 lines · Linus Torvalds
Quoted 3 lines · Jeff Layton
Move
i_blocksup above thei_lock, which moves the new 4 byte hole to just after the timestamps, without changing the size of the structure.I'm sure others have mentioned this, but 'struct inode' is marked with
__randomize_layout, so the actual layout may end up being very different.I'm personally not convinced the whole structure randomization is worth it - it's easy enough to figure out for any distro kernel since the seed has to be the same across machines for modules to work, so even if the seed isn't "public", any layout is bound to be fairly easily discoverable.
Quoted 6 lines
So the whole randomization only really works for private kernel builds, and it adds this kind of pain where "optimizing" the structure layout is kind of pointless depending on various options.
I certainly *hope* no distro enables that pointless thing, but it's a worry.
I've never enabled struct randomization and don't know anyone who does. I figure if you turn that on, you get to keep all of the pieces when you start seeing weird performance problems.
I think that we have to optimize for that being disabled. Even without that though, turning on and off options can change the layout...and then there are different arches, etc.
I'm using a config derived from the Fedora x86_64 kernel images and hope that represents a reasonably common configuration. The only conditional members before the timestamps are based on CONFIG_FS_POSIX_ACL and CONFIG_SECURITY, which are almost always turned on with most distros.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 20 lines · Jeff Layton
Quoted 9 lines · Darrick J. Wong
Quoted 8 lines
I remember seeing those patches go by. I don't remember that change being NaK'ed, but I wasn't paying close attention at the time
Looking at it objectively now, I think it's worth it to recover 8 bytes per inode and open a 4 byte hole that Amir can use to grow the
i_fsnotify_mask. We might even able to shave off another 12 bytes eventually if we can move to a single 64-bit word per timestamp.Quoted 9 lines
I don't think you can, since btrfs timestamps utilize s64 seconds counting in both directions from the Unix epoch. They also support ns resolution:
struct btrfs_timespec { __le64 sec; __le32 nsec; } __attribute__ ((__packed__));
Quoted 5 lines
Correct. We'd lose some fidelity in currently stored timestamps, but as Linus and Ted pointed out, anything below ~100ns granularity is effectively just noise, as that's the floor overhead for calling into the kernel. It's hard to argue that any application needs that sort of timestamp resolution, at least with contemporary hardware.
There are probably applications that have come up with creative ways to use the timestamp fields of file systems that 94 bits of data, with both the MSB of the seconds and the LSB of the nanoseconds carrying information that they expect to be preserved.
Dropping any information in the nanoseconds other than the top two bits would trivially change the 'ls -t' output when two files have the same timestamp in one kernel but slightly different timestamps in another one. For large values of 'tv_sec', there are fewer obvious things that break, but if current kernels are able to retrieve arbitrary times that were stored with utimensat(), then we should probably make sure future kernels can see the same.
Arnd
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 7 lines · Jeff Layton
Correct. We'd lose some fidelity in currently stored timestamps, but as Linus and Ted pointed out, anything below ~100ns granularity is effectively just noise, as that's the floor overhead for calling into the kernel. It's hard to argue that any application needs that sort of timestamp resolution, at least with contemporary hardware.
Quoted 5 lines
Doing that would mean that tests that store specific values in the atime/mtime and expect to be able to fetch exactly that value back would break though, so we'd have to be OK with that if we want to try it. The good news is that it's relatively easy to experiment with new ways to store timestamps with these wrappers in place.
The reason why we store 1ns granularity in ext4's on-disk format (and accept that we only support times only a couple of centuries into the future, as opposed shooting for an on-disk format good for several millennia :-), was in case there was userspace that might try to store a very fine-grained timestamp and want to be able to get it back bit-for-bit identical.
For example, what if someone was trying to implement some kind of steganographic scheme where they going store a secret message (or more likely, a 256-bit AES key) in the nanosecond fields of the file's {c,m,a,cr}time timestamps, "hiding in plain sight". Not that I think that we have to support something like that, since the field is for *timestamps* not cryptographic bits, so if we break someone who is doing that, do we care?
I don't think anyone will complain about breaking the userspace API --- especially since if, say, the CIA was using this for their spies' drop boxes, they probably wouldn't want to admit it. :-)
- Ted
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
Quoted 4 lines · Theodore Ts'o
I don't think anyone will complain about breaking the userspace API --- especially since if, say, the CIA was using this for their spies' drop boxes, they probably wouldn't want to admit it. :-)
Well, you will find that real apps do kind of of care.
Just to take a very real example, "git" will very much notice time granularity issues and care - because git will cache the 'stat' times in the index.
So if you get a different stat time (because the vfs layer has changed some granularity), git will then have to check the files carefully again and update the index.
You can simulate this "re-check all files" with something like this:
$ time git diff
real 0m0.040s
user 0m0.035s
sys 0m0.264s
$ rm .git/index && git read-tree HEAD
$ time git diff
real 0m9.595s
user 0m7.287s
sys 0m2.810sso the difference between just doing a "look, index information matches current 'stat' information" and "oops, index does not have the stat data" is "40 milliseconds" vs "10 seconds".
That's a big difference, and you'd see that each time the granularity changes. But then once the index file has been updated, it's back to the good case.
So yes, real programs to cache stat information, and it matters for performance.
But I don't think any actual reasonable program will have *correctness* issues, though - because there are certainly filesystems out there that don't do nanosecond resolution (and other operations like copying trees around will obviously also change times).
Anybody doing steganography in the timestamps is already not going to have a great time, really.
Linus
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Darrick J. WongQuoted 33 lines · On Thu, Sep 28, 2023 at 8:19 PM Darrick J. Wong <[email protected]> wrote:
Quoted 19 lines · Jeff Layton
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Jeff Layton
This shaves 8 bytes off struct inode, according to pahole.
Signed-off-by Jeff Layton <[email protected]>FWIW, this is similar to the approach that Deepa suggested back in 2016:
Quoted 9 lines
https://lore.kernel.org/lkml/[email protected]/
It was NaKed at the time because of the added complexity, though it would have been much easier to do it then, as we had to touch all the timespec references anyway.
The approach still seems ok to me, but I'm not sure it's worth doing it now if we didn't do it then.
Quoted 7 lines
I remember seeing those patches go by. I don't remember that change being NaK'ed, but I wasn't paying close attention at the time
Looking at it objectively now, I think it's worth it to recover 8 bytes per inode and open a 4 byte hole that Amir can use to grow the
i_fsnotify_mask. We might even able to shave off another 12 bytes eventually if we can move to a single 64-bit word per timestamp.I don't think you can, since btrfs timestamps utilize s64 seconds counting in both directions from the Unix epoch. They also support ns resolution:
Quoted 7 lines
struct btrfs_timespec { __le64 sec; __le32 nsec; } __attribute__ ((__packed__));--D
Sure we can.
That's what btrfs_inode is for.
vfs inode also does not store i_otime (birth time) and there is even a precedent of vfs/btrfs variable size mismatch:
/* full 64 bit generation number, struct vfs_inode doesn't have a big
* enough field for this.
*/
u64 generation;If we decide that vfs should use "bigtime", btrfs pre-historic timestamps are not a show stopper.
Thanks,
Amir.
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Linus TorvaldsOn Fri, Sep 29, 2023 at 3:19 AM Linus Torvalds
<[email protected]> wrote:
...
Quoted 4 lines
So yes, real programs to cache stat information, and it matters for performance.
But I don't think any actual reasonable program will have *correctness* issues, though -
I beg to disagree.
Quoted 7 lines
because there are certainly filesystems
out there that don't do nanosecond resolution (and other operations like copying trees around will obviously also change times).Anybody doing steganography in the timestamps is already not going to have a great time, really.
Your thesis implies that all applications are portable across different filesystems and all applications are expected to cope with copying trees around.
There are applications that work on specific filesystems and those applications are very much within sanity if they expect that past observed values of nsec will not to change if the file was not changed.
But even if we agree that will "only" hurt performance, your example of performance hit (10s of git diff) is nowhere close to the performance hit of invalidating the mtime cache of billions of files at once (i.e. after kernel upgrade), which means that rsync-like programs need to re-read all the data from remote locations.
I am not saying that filesystems cannot decide to *stop storing nsec granularity* from this day forth, but like btrfs pre-historic timestamps, those fs have an obligation to preserve existing metadata, unless users opted to throw it away.
OTOH, it is perfectly fine if the vfs wants to stop providing sub 100ns services to filesystems. It's just going to be the fs problem and the preserved pre-historic/fine-grained time on existing files would only need to be provided in getattr(). It does not need to be in __i_mtime.
Thanks,
Amir.
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 5 lines · Jeff Layton
Correct. We'd lose some fidelity in currently stored timestamps, but as Linus and Ted pointed out, anything below ~100ns granularity is effectively just noise, as that's the floor overhead for calling into the kernel. It's hard to argue that any application needs that sort of timestamp resolution, at least with contemporary hardware.
Albeit with the danger of making Steve French very happy;-), would it make sense to switch internally to Microsoft-style 64-bit timestamps with their 100ns granularity?
David
Christian Brauner
maintainerRe: [PATCH 87/87] fs: move i_blocks up a few places in struct inode
In reply to Linus TorvaldsQuoted 15 lines · Linus Torvalds
Quoted 3 lines · Jeff Layton
Move
i_blocksup above thei_lock, which moves the new 4 byte hole to just after the timestamps, without changing the size of the structure.I'm sure others have mentioned this, but 'struct inode' is marked with
__randomize_layout, so the actual layout may end up being very different.I'm personally not convinced the whole structure randomization is worth it - it's easy enough to figure out for any distro kernel since the seed has to be the same across machines for modules to work, so even if the seed isn't "public", any layout is bound to be fairly easily discoverable.
Quoted 5 lines
So the whole randomization only really works for private kernel builds, and it adds this kind of pain where "optimizing" the structure layout is kind of pointless depending on various options.
I certainly *hope* no distro enables that pointless thing, but it's a worry.
They don't last we checked. Just last cycle we moved stuff in struct file around to optimize things and we explicitly said we don't give a damn about struct randomization. Anyone who enables this will bleed performance pretty badly, I would reckon.
Christian Brauner
maintainerRe: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Jeff LaytonQuoted 1 line
It is a lot of churn though.
I think that i_{a,c,m}time shouldn't be accessed directly by filesystems same as no filesystem should really access i_{g,u}id which we also provide i_{g,u}id_{read,write}() accessors for. The mode is another example where really most often should use helpers because of all the set*id stripping that we need to do (and the bugs that we had because of this...).
The interdependency between ctime and mtime is enough to hide this in accessors. The other big advantage is simply grepability. So really I would like to see this change even without the type switch.
In other words, there's no need to lump the two changes together. Do the conversion part and we can argue about the switch to discrete integers separately.
The other adavantage is that we have a cycle to see any possible regression from the conversion.
Thoughts anyone?
Jeff Layton
maintainerRe: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
Quoted 13 lines · Christian Brauner
Quoted 1 line
It is a lot of churn though.
I think that i_{a,c,m}time shouldn't be accessed directly by filesystems same as no filesystem should really access i_{g,u}id which we also provide i_{g,u}id_{read,write}() accessors for. The mode is another example where really most often should use helpers because of all the set*id stripping that we need to do (and the bugs that we had because of this...).
The interdependency between ctime and mtime is enough to hide this in accessors. The other big advantage is simply grepability. So really I would like to see this change even without the type switch.
Quoted 8 lines
In other words, there's no need to lump the two changes together. Do the conversion part and we can argue about the switch to discrete integers separately.
The other adavantage is that we have a cycle to see any possible regression from the conversion.
Thoughts anyone?
That works for me, and sort of what I was planning anyway. I mostly just did the change to timestamp storage to see what it would look like afterward.
FWIW, I'm planning to do a v2 patchbomb early next week, with the changes that Chuck suggested (specific helpers for fetching the _sec and _nsec fields). For now, I'll drop the change from timespec64 to discrete fields. We can do that in a separate follow-on set.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to Amir GoldsteinQuoted 5 lines · Amir Goldstein
OTOH, it is perfectly fine if the vfs wants to stop providing sub 100ns services to filesystems. It's just going to be the fs problem and the preserved pre-historic/fine-grained time on existing files would only need to be provided in
getattr(). It does not need to be in__i_mtime.
Hmm. That sounds technically sane, but for one thing: if the aim is to try to do
(a) atomic timestamp access
(b) shrink the inode
then having the filesystem maintain its own timestamp for fine-grained data will break both of those goals.
Yes, we'd make 'struct inode' smaller if we pack the times into one 64-bit entity, but if btrfs responds by adding mtime fields to "struct btrfs_inode", we lost the size advantage and only made things worse.
And if ->getattr() then reads those fields without locking (and we definitely don't want locking in that path), then we lost the atomicity thing too.
So no. A "but the filesystem can maintain finer granularity" model is not acceptable, I think.
If we do require nanoseconds for compatibility, what we could possibly do is say "we guarantee nanosecond values for *legacy* dates", and say that future dates use 100ns resolution. We'd define "legacy dates" to be the traditional 32-bit signed time_t.
So with a 64-bit fstime_t, we'd have the "legacy format":
- top 32 bits are seconds, bottom 32 bits are ns
which gives us that ns format.
Then, because only 30 bits are needed for nanosecond resolution, we use the top two bits of that ns field as flags. '00' means that legacy format, and '01' would mean "we're not doing nanosecond resolution, we're doing 64ns resolution, and the low 6 bits of the ns field are actually bits 32-37 of the seconds field".
That still gives us some extensibility (unless the multi-grain code still wants to use the other top bit), and it gives us 40 bits of seconds, which is quite a lot.
And all the conversion functions will be simple bit field manipulations, so there are no expensive ops here.
Anyway, I agree with the "let's introduce the accessor functions first, we can do the 'pack into one word' decisions later".
Linus
Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
In reply to David HowellsQuoted 10 lines · On Fri, Sep 29, 2023 at 3:06 AM David Howells via samba-technical…
Quoted 5 lines · Jeff Layton
Correct. We'd lose some fidelity in currently stored timestamps, but as Linus and Ted pointed out, anything below ~100ns granularity is effectively just noise, as that's the floor overhead for calling into the kernel. It's hard to argue that any application needs that sort of timestamp resolution, at least with contemporary hardware.
Quoted 3 lines
Albeit with the danger of making Steve French very happy;-), would it make sense to switch internally to Microsoft-style 64-bit timestamps with their 100ns granularity?
100ns granularity does seem to make sense and IIRC was used by various DCE standards in the 90s and 2000s (not just used for SMB2/SMB3 protocol and various Windows filesystems)
Signature · 3 lines
Thanks, Steve
[OT] Re: [PATCH 86/87] fs: switch timespec64 fields in inode to discrete integers
Quoted 12 lines · Steve French
Quoted 10 lines · On Fri, Sep 29, 2023 at 3:06 AM David Howells via samba-technical…
Quoted 5 lines · Jeff Layton
Correct. We'd lose some fidelity in currently stored timestamps, but as Linus and Ted pointed out, anything below ~100ns granularity is effectively just noise, as that's the floor overhead for calling into the kernel. It's hard to argue that any application needs that sort of timestamp resolution, at least with contemporary hardware.
Quoted 7 lines
Quoted 3 lines
Albeit with the danger of making Steve French very happy;-), would it make sense to switch internally to Microsoft-style 64-bit timestamps with their 100ns granularity?
100ns granularity does seem to make sense and IIRC was used by various DCE standards in the 90s and 2000s (not just used for SMB2/SMB3 protocol and various Windows filesystems)
Historically it probably comes from VMS, where system time and file timestamps were a 64 bit integer counting in 100ns units starting on MJD 2400000.5 (Nov 17th 1858).
Gabriel
Quoted 6 lines
Signature · 4 lines
-- Thanks, Steve