From: Max Kellermann <max.kellermann@ionos.com>
To: tytso@mit.edu, adilger.kernel@dilger.ca,
libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com,
ritesh.list@gmail.com, yi.zhang@huawei.com,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Max Kellermann <max.kellermann@ionos.com>
Subject: [PATCH 3/3] ext4: store creation time in separate seconds and nanoseconds
Date: Wed, 11 Nov 2026 13:52:42 +0100 [thread overview]
Message-ID: <20261111125242.1078620-4-max.kellermann@ionos.com> (raw)
In-Reply-To: <20261111125242.1078620-1-max.kellermann@ionos.com>
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@ionos.com>
---
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
next prev parent reply other threads:[~2026-11-11 12:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:52 [PATCH 0/3] ext4: reduce per-inode memory overhead Max Kellermann
2026-11-11 12:52 ` [PATCH 1/3] ext4: make fast commit support optional Max Kellermann
2026-11-11 13:15 ` sashiko-bot
2026-11-11 13:44 ` Max Kellermann
2026-11-11 12:52 ` [PATCH 2/3] ext4: make bigalloc " Max Kellermann
2026-11-11 13:12 ` sashiko-bot
2026-11-11 12:52 ` Max Kellermann [this message]
2026-11-11 13:09 ` [PATCH 3/3] ext4: store creation time in separate seconds and nanoseconds sashiko-bot
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=20261111125242.1078620-4-max.kellermann@ionos.com \
--to=max.kellermann@ionos.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.