[PATCH 3/3] ext4: store creation time in separate seconds and nanoseconds
From: Max Kellermann
Date: Wed Nov 11 2026 - 07:54:10 EST
Keep 64-bit seconds and 32-bit nanoseconds and place the latter next
to i_raw_lock. Preserve the existing on-disk encoding and timestamp
range while saving 8 bytes per inode without fast commit.
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ext4/ext4.h | 18 +++++++++++++-----
fs/ext4/ialloc.c | 3 ++-
fs/ext4/inode.c | 4 ++--
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index c2c242f60700..9b6df2632fdd 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -930,9 +930,15 @@ do { \
EXT4_INODE_SET_XTIME_VAL(i_ctime, inode, raw_inode, inode_get_ctime(inode))
#define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
+do { \
+ struct timespec64 ts = { \
+ .tv_sec = (einode)->xtime ## _sec, \
+ .tv_nsec = (einode)->xtime ## _nsec, \
+ }; \
if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
EXT4_INODE_SET_XTIME_VAL(xtime, &((einode)->vfs_inode), \
- raw_inode, (einode)->xtime)
+ raw_inode, ts); \
+} while (0)
#define EXT4_INODE_GET_XTIME_VAL(xtime, inode, raw_inode) \
(EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra) ? \
@@ -962,12 +968,13 @@ do { \
#define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \
do { \
+ struct timespec64 ts = { 0, 0 }; \
if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
- (einode)->xtime = \
+ ts = \
EXT4_INODE_GET_XTIME_VAL(xtime, &(einode->vfs_inode), \
raw_inode); \
- else \
- (einode)->xtime = (struct timespec64){0, 0}; \
+ (einode)->xtime ## _sec = ts.tv_sec; \
+ (einode)->xtime ## _nsec = ts.tv_nsec; \
} while (0)
#define i_disk_version osd1.linux1.l_i_version
@@ -1123,6 +1130,7 @@ struct ext4_inode_info {
#endif
spinlock_t i_raw_lock; /* protects updates to the raw inode */
+ u32 i_crtime_nsec;
#ifdef CONFIG_EXT4_FS_FAST_COMMIT
/*
@@ -1168,7 +1176,7 @@ struct ext4_inode_info {
* File creation time. Its function is same as that of
* struct timespec64 i_{a,c,m}time in the generic inode.
*/
- struct timespec64 i_crtime;
+ time64_t i_crtime_sec;
/* mballoc */
atomic_t i_prealloc_active;
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 527f1f703c3e..1d73dd35e000 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -1261,7 +1261,8 @@ struct inode *__ext4_new_inode(const struct mnt_idmap *idmap,
/* This is the optimal IO size (for stat), not the fs block size */
inode->i_blocks = 0;
simple_inode_init_ts(inode);
- ei->i_crtime = inode_get_mtime(inode);
+ ei->i_crtime_sec = inode_get_mtime_sec(inode);
+ ei->i_crtime_nsec = inode_get_mtime_nsec(inode);
memset(ei->i_data, 0, sizeof(ei->i_data));
ei->i_dir_start_lookup = 0;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 829095aedbe6..5dc22f8747ff 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -7190,8 +7190,8 @@ int ext4_getattr(const struct mnt_idmap *idmap, const struct path *path,
if ((request_mask & STATX_BTIME) &&
EXT4_FITS_IN_INODE(raw_inode, ei, i_crtime)) {
stat->result_mask |= STATX_BTIME;
- stat->btime.tv_sec = ei->i_crtime.tv_sec;
- stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
+ stat->btime.tv_sec = ei->i_crtime_sec;
+ stat->btime.tv_nsec = ei->i_crtime_nsec;
}
/* Return the DIO alignment restrictions if requested. */
--
2.53.0