[PATCH 02/12] fs/ceph/super: make field `i_truncate_pagecache_size` optional

From: Max Kellermann

Date: Fri Jun 12 2026 - 12:53:04 EST


This field is only used with CONFIG_FS_ENCRYPTION; without it, it
always equals `i_truncate_size`.

This reduces the size of `struct ceph_inode_info` by 8 bytes on
kernels that have filesystem encryption disabled.

Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
fs/ceph/inode.c | 8 ++++++--
fs/ceph/super.h | 11 +++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 22c7da1ea61c..1504b889622c 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -680,7 +680,9 @@ struct inode *ceph_alloc_inode(struct super_block *sb)
ci->i_truncate_seq = 0;
ci->i_truncate_size = 0;
ci->i_truncate_pending = 0;
+#ifdef CONFIG_FS_ENCRYPTION
ci->i_truncate_pagecache_size = 0;
+#endif

ci->i_max_size = 0;
ci->i_reported_size = 0;
@@ -865,6 +867,7 @@ int ceph_fill_file_size(struct inode *inode, int issued,

ci->i_truncate_size = truncate_size;

+#ifdef CONFIG_FS_ENCRYPTION
if (IS_ENCRYPTED(inode)) {
doutc(cl, "truncate_pagecache_size %lld -> %llu\n",
ci->i_truncate_pagecache_size, size);
@@ -872,6 +875,7 @@ int ceph_fill_file_size(struct inode *inode, int issued,
} else {
ci->i_truncate_pagecache_size = truncate_size;
}
+#endif
}
return queue_trunc;
}
@@ -2331,7 +2335,7 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)
/* there should be no reader or writer */
WARN_ON_ONCE(ci->i_rd_ref || ci->i_wr_ref);

- to = ci->i_truncate_pagecache_size;
+ to = ceph_get_truncate_pagecache_size(ci);
wrbuffer_refs = ci->i_wrbuffer_ref;
doutc(cl, "%p %llx.%llx (%d) to %lld\n", inode, ceph_vinop(inode),
ci->i_truncate_pending, to);
@@ -2341,7 +2345,7 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)
truncate_pagecache(inode, to);

spin_lock(&ci->i_ceph_lock);
- if (to == ci->i_truncate_pagecache_size) {
+ if (to == ceph_get_truncate_pagecache_size(ci)) {
ci->i_truncate_pending = 0;
finish = 1;
}
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 6aec40955387..f0f03aeb5b19 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -461,11 +461,14 @@ struct ceph_inode_info {
u32 i_truncate_seq; /* last truncate to smaller size */
u64 i_truncate_size; /* and the size we last truncated down to */
int i_truncate_pending; /* still need to call vmtruncate */
+
+#ifdef CONFIG_FS_ENCRYPTION
/*
* For none fscrypt case it equals to i_truncate_size or it will
* equals to fscrypt_file_size
*/
u64 i_truncate_pagecache_size;
+#endif

u64 i_max_size; /* max file size authorized by mds */
u64 i_reported_size; /* (max_)size reported to or requested of mds */
@@ -660,6 +663,14 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,
return ilookup5(sb, (unsigned long)vino.ino, ceph_ino_compare, &vino);
}

+static inline u64 ceph_get_truncate_pagecache_size(const struct ceph_inode_info *ci)
+{
+#ifdef CONFIG_CEPH_FS_SNAPSHOTS
+ return ci->i_truncate_pagecache_size;
+#else
+ return ci->i_truncate_size;
+#endif
+}

/*
* Ceph inode.
--
2.47.3