Skip to contentSkip to conversation

f2fs: skip filesystem level truncate when size isn't changed

PATCH In review Kinglong Mee 2 participants 3 messages Feb 28, 2017 – Mar 1, 2017 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: skip filesystem level truncate when size isn't changed

When size isn't changed, it's needless to do f2fs level truncate.

---
 fs/f2fs/file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/f2fs/file.c +5 -4
index c6ca00c..d144aa3 100644
@@ -676,6 +676,7 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr)
 int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
+	loff_t old_size = i_size_read(inode);
 	int err;
 	bool size_changed = false;
 
@@ -688,12 +689,13 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 				fscrypt_get_encryption_info(inode))
 			return -EACCES;
 
-		if (attr->ia_size <= i_size_read(inode)) {
+		if (attr->ia_size < old_size) {
 			truncate_setsize(inode, attr->ia_size);
 			err = f2fs_truncate(inode);
 			if (err)
 				return err;
-		} else {
+			size_changed = true;
+		} else if (attr->ia_size > old_size) {
 			/*
 			 * do not trim all blocks after i_size if target size is
 			 * larger than i_size.
@@ -707,9 +709,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 					return err;
 			}
 			inode->i_mtime = inode->i_ctime = current_time(inode);
+			size_changed = true;
 		}
-
-		size_changed = true;
 	}
 
 	__setattr_copy(inode, attr);
Signature · 6 lines
2.9.3


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#1 lore raw
Quoted 1 line · Kinglong Mee

When size isn't changed, it's needless to do f2fs level truncate.

I think it needs to do this.

Please take a look at commit 3c4541452748 ("f2fs: do not trim preallocated blocks when truncating after i_size") and generic/092 of fstests.

Thanks,

Quoted 36 lines
---
 fs/f2fs/file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/f2fs/file.c +4 -2
index c6ca00c..d144aa3 100644
@@ -676,6 +676,7 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr)
 int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
+	loff_t old_size = i_size_read(inode);
 	int err;
 	bool size_changed = false;
 
@@ -688,12 +689,13 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 				fscrypt_get_encryption_info(inode))
 			return -EACCES;
 
-		if (attr->ia_size <= i_size_read(inode)) {
+		if (attr->ia_size < old_size) {
 			truncate_setsize(inode, attr->ia_size);
 			err = f2fs_truncate(inode);
 			if (err)
 				return err;
-		} else {
+			size_changed = true;
+		} else if (attr->ia_size > old_size) {
 			/*
 			 * do not trim all blocks after i_size if target size is
 			 * larger than i_size.

fs/f2fs/file.c int f2fs_setattr(struct dentry *dentry, struct iattr *attr) · line 716

Quoted 10 lines
fs/f2fs/file.c +1 -2
@@ -707,9 +709,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 					return err;
 			}
 			inode->i_mtime = inode->i_ctime = current_time(inode);
+			size_changed = true;
 		}
-
-		size_changed = true;
 	}
 
 	__setattr_copy(inode, attr);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot

#2 lore raw
Quoted 7 lines · Chao Yu
Quoted 1 line · Kinglong Mee

When size isn't changed, it's needless to do f2fs level truncate.

I think it needs to do this.

Please take a look at commit 3c4541452748 ("f2fs: do not trim preallocated blocks when truncating after i_size") and generic/092 of fstests.

Got it, thanks!

thanks,
Kinglong Mee

Quoted 46 lines

Thanks,

Quoted 44 lines
---
 fs/f2fs/file.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/f2fs/file.c +5 -4
index c6ca00c..d144aa3 100644
@@ -676,6 +676,7 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr)
 int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 {
 	struct inode *inode = d_inode(dentry);
+	loff_t old_size = i_size_read(inode);
 	int err;
 	bool size_changed = false;
 
@@ -688,12 +689,13 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 				fscrypt_get_encryption_info(inode))
 			return -EACCES;
 
-		if (attr->ia_size <= i_size_read(inode)) {
+		if (attr->ia_size < old_size) {
 			truncate_setsize(inode, attr->ia_size);
 			err = f2fs_truncate(inode);
 			if (err)
 				return err;
-		} else {
+			size_changed = true;
+		} else if (attr->ia_size > old_size) {
 			/*
 			 * do not trim all blocks after i_size if target size is
 			 * larger than i_size.
@@ -707,9 +709,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 					return err;
 			}
 			inode->i_mtime = inode->i_ctime = current_time(inode);
+			size_changed = true;
 		}
-
-		size_changed = true;
 	}
 
Quoted 4 lines

fs/f2fs/file.c int f2fs_setattr(struct dentry *dentry, struct iattr *attr) · line 716

Quoted 2 lines
fs/f2fs/file.c +0 -0
 	__setattr_copy(inode, attr);

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot