Skip to contentSkip to conversation

f2fs: do not trim preallocated blocks when truncating after i_size

PATCH Superseded Chao Yu 2 participants 3 messages Jun 5, 2015 – Jun 9, 2015 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: do not trim preallocated blocks when truncating after i_size

When we perform generic/092 in xfstests, output is like below:

     XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
     0: [0..10239]: data
     0: [0..10239]: data
    -1: [10240..20479]: unwritten
    +1: [10240..14335]: unwritten

This is because with this testcase, we redefine the regulation for truncate in perallocated space past i_size as below:

"There was some confused about what the fs was supposed to do when you truncate at i_size with preallocated space past i_size. We decided on the following things.

1) truncate(i_size) will trim all blocks past i_size.
2) truncate(x) where x > i_size will not trim all blocks past i_size. "

This method is used in xfs, and then ext4/btrfs will follow the rule.

This patch fixes to follow the new rule for f2fs.

---
 fs/f2fs/file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/file.c +4 -4
index 4d42d66..85f97af 100644
@@ -651,16 +651,16 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 				f2fs_get_encryption_info(inode))
 			return -EACCES;
 
-		if (attr->ia_size != i_size_read(inode)) {
+		if (attr->ia_size <= i_size_read(inode)) {
 			truncate_setsize(inode, attr->ia_size);
 			f2fs_truncate(inode);
 			f2fs_balance_fs(F2FS_I_SB(inode));
 		} else {
 			/*
-			 * giving a chance to truncate blocks past EOF which
-			 * are fallocated with FALLOC_FL_KEEP_SIZE.
+			 * do not trim all blocks after i_size if target size is
+			 * larger than i_size.
 			 */
-			f2fs_truncate(inode);
+			truncate_setsize(inode, attr->ia_size);
 		}
 	}
 
Signature · 1 line
2.4.2
maintainer
#1 lore raw
Quoted 40 lines · Chao Yu

When we perform generic/092 in xfstests, output is like below:

     XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
     0: [0..10239]: data
     0: [0..10239]: data
    -1: [10240..20479]: unwritten
    +1: [10240..14335]: unwritten

This is because with this testcase, we redefine the regulation for truncate in perallocated space past i_size as below:

"There was some confused about what the fs was supposed to do when you truncate at i_size with preallocated space past i_size. We decided on the following things.

1) truncate(i_size) will trim all blocks past i_size.
2) truncate(x) where x > i_size will not trim all blocks past i_size. "

This method is used in xfs, and then ext4/btrfs will follow the rule.

This patch fixes to follow the new rule for f2fs.

---
 fs/f2fs/file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/file.c +1 -1
index 4d42d66..85f97af 100644
@@ -651,16 +651,16 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 				f2fs_get_encryption_info(inode))
 			return -EACCES;
 
-		if (attr->ia_size != i_size_read(inode)) {
+		if (attr->ia_size <= i_size_read(inode)) {
 			truncate_setsize(inode, attr->ia_size);
 			f2fs_truncate(inode);

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

Quoted 10 lines
fs/f2fs/file.c +3 -3
 			f2fs_balance_fs(F2FS_I_SB(inode));
 		} else {
 			/*
-			 * giving a chance to truncate blocks past EOF which
-			 * are fallocated with FALLOC_FL_KEEP_SIZE.
+			 * do not trim all blocks after i_size if target size is
+			 * larger than i_size.
 			 */
-			f2fs_truncate(inode);
+			truncate_setsize(inode, attr->ia_size);

So, we can do:

		truncate_setsize();

		if (attr->ia_size <= i_size_read(inode)) {
			f2fs_truncate(inode);
			f2fs_balance_fs();
		}

Right?

Quoted 5 lines
fs/f2fs/file.c +0 -0
 		}
 	}
 
Signature · 1 line
2.4.2
author
#2 lore raw
Quoted 60 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, June 09, 2015 2:07 AM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] f2fs: do not trim preallocated blocks when truncating after i_size

Quoted 40 lines · Chao Yu

When we perform generic/092 in xfstests, output is like below:

     XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
     0: [0..10239]: data
     0: [0..10239]: data
    -1: [10240..20479]: unwritten
    +1: [10240..14335]: unwritten

This is because with this testcase, we redefine the regulation for truncate in perallocated space past i_size as below:

"There was some confused about what the fs was supposed to do when you truncate at i_size with preallocated space past i_size. We decided on the following things.

1) truncate(i_size) will trim all blocks past i_size.
2) truncate(x) where x > i_size will not trim all blocks past i_size. "

This method is used in xfs, and then ext4/btrfs will follow the rule.

This patch fixes to follow the new rule for f2fs.

---
 fs/f2fs/file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/file.c +1 -1
index 4d42d66..85f97af 100644
@@ -651,16 +651,16 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 				f2fs_get_encryption_info(inode))
 			return -EACCES;
 
-		if (attr->ia_size != i_size_read(inode)) {
+		if (attr->ia_size <= i_size_read(inode)) {
 			truncate_setsize(inode, attr->ia_size);
 			f2fs_truncate(inode);

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

Quoted 10 lines
fs/f2fs/file.c +3 -3
 			f2fs_balance_fs(F2FS_I_SB(inode));
 		} else {
 			/*
-			 * giving a chance to truncate blocks past EOF which
-			 * are fallocated with FALLOC_FL_KEEP_SIZE.
+			 * do not trim all blocks after i_size if target size is
+			 * larger than i_size.
 			 */
-			f2fs_truncate(inode);
+			truncate_setsize(inode, attr->ia_size);

So, we can do:

Quoted 8 lines
		truncate_setsize();

		if (attr->ia_size <= i_size_read(inode)) {
			f2fs_truncate(inode);
			f2fs_balance_fs();
		}

Right?

Yes, let me fix and resend the patch.

Thanks,

Quoted 6 lines
Quoted 6 lines
fs/f2fs/file.c +0 -1
 		}
 	}
 
--

2.4.2

------------------------------------------------------------------------------