ceph: buffer the truncate when size won't change with Fx caps issued
PATCH 1/1 ceph: buffer the truncate when size won't change with Fx caps issued
From: Xiubo Li <[email protected]>
If the new size is the same with current size, the MDS will do nothing except changing the mtime/atime. We can just buffer the truncate in this case.
--- fs/ceph/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/inode.c +1 -1
@@ -2370,7 +2370,7 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *cloff_t isize =i_size_read (inode);dout ("setattr %p size %lld -> %lld\n" , inode, isize, attr->ia_size); -if ((issued &CEPH_CAP_FILE_EXCL ) && attr->ia_size > isize) { +if ((issued &CEPH_CAP_FILE_EXCL ) && attr->ia_size >= isize) {i_size_write (inode, attr->ia_size); inode->i_blocks =calc_inode_blocks (attr->ia_size); ci->i_reported_size = attr->ia_size;
Signature · 1 line
2.27.0
Quoted 16 lines · On Sat, 2021-09-25 at 16:51 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
If the new size is the same with current size, the MDS will do nothing except changing the mtime/atime. We can just buffer the truncate in this case.
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ceph/inode.c +0
-0
fs/ceph/inode.c int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *c · line 2376
Quoted 8 lines
fs/ceph/inode.c +1
-1@@ -2370,7 +2370,7 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *cloff_t isize =i_size_read (inode);dout ("setattr %p size %lld -> %lld\n" , inode, isize, attr->ia_size); -if ((issued &CEPH_CAP_FILE_EXCL ) && attr->ia_size > isize) { +if ((issued &CEPH_CAP_FILE_EXCL ) && attr->ia_size >= isize) {i_size_write (inode, attr->ia_size); inode->i_blocks =calc_inode_blocks (attr->ia_size); ci->i_reported_size = attr->ia_size;
I wonder if we ought to just ignore the attr->ia_size == isize case altogether instead? Truncating to the same size should be a no-op, so we shouldn't even need to dirty caps or anything.
Thoughts?
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 29 lines · Jeff Layton
Quoted 16 lines · On Sat, 2021-09-25 at 16:51 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
If the new size is the same with current size, the MDS will do nothing except changing the mtime/atime. We can just buffer the truncate in this case.
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ceph/inode.c +0
-0fs/ceph/inode.c int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *c · line 2376
Quoted 8 lines
fs/ceph/inode.c +1
-1@@ -2370,7 +2370,7 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *cloff_t isize =i_size_read (inode);dout ("setattr %p size %lld -> %lld\n" , inode, isize, attr->ia_size); -if ((issued &CEPH_CAP_FILE_EXCL ) && attr->ia_size > isize) { +if ((issued &CEPH_CAP_FILE_EXCL ) && attr->ia_size >= isize) {i_size_write (inode, attr->ia_size); inode->i_blocks =calc_inode_blocks (attr->ia_size); ci->i_reported_size = attr->ia_size;I wonder if we ought to just ignore the
attr->ia_size== isize case altogether instead? Truncating to the same size should be a no-op, so we shouldn't even need to dirty caps or anything.
Quoted 1 line
Thoughts?
I agree with it. Really it's doing nothing except updating the atime/mtime. Currently this patch will just delay doing that.
In some filesystems they will ignore it by doing nothing in this case. And some others may will try to release the preallocated blocks in the lower layer in this case, this makes no sense for ceph.