Skip to contentSkip to conversation

f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

PATCH In review Fengnan Chang 5 participants 11 messages May 7, 2021 – May 18, 2021 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved about 0.5%.

---
 fs/f2fs/data.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/f2fs/data.c +8 -0
index cf935474ffba..b9ec7b182f45 100644
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (f2fs_compressed_file(inode)) {
 		int ret;
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
 		*fsdata = NULL;
 
+		/*
+		 * when write pos is bigger than inode size ,f2fs_prepare_compress_overwrite
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;
+
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
 							index, fsdata);
 		if (ret < 0) {

--
2.29.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#1 lore raw
Quoted 22 lines · Fengnan Chang

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved about 0.5%.

---
 fs/f2fs/data.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/f2fs/data.c +0 -0
index cf935474ffba..b9ec7b182f45 100644
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (f2fs_compressed_file(inode)) {
 		int ret;

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3315

Quoted 10 lines
fs/f2fs/data.c +7 -0
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
 		*fsdata = NULL;
 
+		/*
+		 * when write pos is bigger than inode size ,f2fs_prepare_compress_overwrite
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;

What if there're existing clusters beyond i_size? Given performance impacts, do we really need this?

Quoted 6 lines
fs/f2fs/data.c +1 -1
+
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
 							index, fsdata);
 		if (ret < 0) {
--

2.29.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

Thanks.

-----邮件原件-----
发件人: Jaegeuk Kim <[email protected]>
发送时间: 2021年5月10日 23:44
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected] 主题: Re: [PATCH v4] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

Quoted 8 lines · Fengnan Chang

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved

about 0.5%.

Quoted 12 lines
---
 fs/f2fs/data.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/f2fs/data.c index renamed from fs/f2fs/data.c +0 -0

cf935474ffba..b9ec7b182f45 100644

fs/f2fs/data.c +0 -0
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file, 

struct address_space *mapping, #ifdef CONFIG_F2FS_FS_COMPRESSION

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping,

Quoted 3 lines
fs/f2fs/data.c +1 -0
 	if (f2fs_compressed_file(inode)) {
 		int ret;
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >>

PAGE_SHIFT;

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping,

Quoted 5 lines
fs/f2fs/data.c +2 -0
 		*fsdata = NULL;
 
+		/*
+		 * when write pos is bigger than inode size

,f2fs_prepare_compress_overwrite

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3315

Quoted 4 lines
fs/f2fs/data.c +4 -0
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;

What if there're existing clusters beyond i_size? Given performance impacts, do we really need this?

Quoted 6 lines
fs/f2fs/data.c +1 -1
+
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
 							index, fsdata);
 		if (ret < 0) {
--

2.29.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#3 lore raw
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

Quoted 43 lines

Thanks.

-----邮件原件-----
发件人: Jaegeuk Kim <[email protected]>
发送时间: 2021年5月10日 23:44
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected] 主题: Re: [PATCH v4] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

Quoted 8 lines · Fengnan Chang

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved

about 0.5%.

Quoted 12 lines
---
 fs/f2fs/data.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/f2fs/data.c index renamed from fs/f2fs/data.c +0 -0

cf935474ffba..b9ec7b182f45 100644

fs/f2fs/data.c +0 -0
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file, 

struct address_space *mapping, #ifdef CONFIG_F2FS_FS_COMPRESSION

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping,

Quoted 3 lines
fs/f2fs/data.c +1 -0
 	if (f2fs_compressed_file(inode)) {
 		int ret;
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >>

PAGE_SHIFT;

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping,

Quoted 5 lines
fs/f2fs/data.c +2 -0
 		*fsdata = NULL;
 
+		/*
+		 * when write pos is bigger than inode size

,f2fs_prepare_compress_overwrite

Quoted 15 lines

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3315

Quoted 4 lines
fs/f2fs/data.c +4 -0
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;

What if there're existing clusters beyond i_size? Given performance impacts, do we really need this?

Quoted 6 lines
fs/f2fs/data.c +1 -1
+
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
 							index, fsdata);
 		if (ret < 0) {
--

2.29.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

Hmmm.. Again, it's still unclear what's the on-disk format like when post-EOF. Also, corrupted/crafted/malicious on-disk data needs to be handled at least to make sure it cannot crash the kernel and corrupt the fs itself even further, especially some optimization patch like this targeted on the specific logic to challenge the stablility.

So without details, in the beginning, it smelled somewhat dangerous to me anyway. But considering some performance impact, I just leave some message here.

Thanks,
Gao Xiang

Quoted 61 lines
Quoted 44 lines

Thanks.

-----邮件原件-----
发件人: Jaegeuk Kim <[email protected]>
发送时间: 2021年5月10日 23:44
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected] 主题: Re: [PATCH v4] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

Quoted 8 lines · Fengnan Chang

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved

about 0.5%.

Quoted 12 lines
---
 fs/f2fs/data.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/f2fs/data.c index renamed from fs/f2fs/data.c +0 -0

cf935474ffba..b9ec7b182f45 100644

fs/f2fs/data.c +0 -0
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file, 

struct address_space *mapping, #ifdef CONFIG_F2FS_FS_COMPRESSION

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping,

Quoted 3 lines
fs/f2fs/data.c +1 -0
 	if (f2fs_compressed_file(inode)) {
 		int ret;
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >>

PAGE_SHIFT;

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping,

Quoted 5 lines
fs/f2fs/data.c +2 -0
 		*fsdata = NULL;
 
+		/*
+		 * when write pos is bigger than inode size

,f2fs_prepare_compress_overwrite

Quoted 15 lines

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3315

Quoted 4 lines
fs/f2fs/data.c +4 -0
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;

What if there're existing clusters beyond i_size? Given performance impacts, do we really need this?

Quoted 6 lines
fs/f2fs/data.c +1 -1
+
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
 							index, fsdata);
 		if (ret < 0) {
--

2.29.0

Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#5 lore raw
In reply to Jaegeuk Kim
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

I can't image a case that compressed cluster may cross filesize, it looks it's a bug if that happened, but I'm not sure I have considered all cases. So, I prefer to add a check condition as below, then testing w/ xfstest/por_fsstress for a while.

Subject: [PATCH] f2fs: compress: compressed cluster should not cross i_size

---
 fs/f2fs/data.c | 2 ++
 1 file changed, 2 insertions(+)
fs/f2fs/data.c +2 -0
index 06d1e58d3882..9acca358d578 100644
@@ -3325,6 +3325,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 			err = ret;
 			goto fail;
 		} else if (ret) {
+			f2fs_bug_on(sbi, index >=
+				DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
 			return 0;
 		}
 	}
Signature · 1 line
2.29.2
Quoted 61 lines
Quoted 44 lines

Thanks.

-----邮件原件-----
发件人: Jaegeuk Kim <[email protected]>
发送时间: 2021年5月10日 23:44
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected] 主题: Re: [PATCH v4] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

Quoted 8 lines · Fengnan Chang

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved

about 0.5%.

Quoted 14 lines
---
  fs/f2fs/data.c | 8 ++++++++
  1 file changed, 8 insertions(+)
fs/f2fs/data.c index renamed from fs/f2fs/data.c +0 -0

cf935474ffba..b9ec7b182f45 100644

fs/f2fs/data.c +0 -0
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file,

struct address_space *mapping, #ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_compressed_file(inode)) {
int ret;

fs/f2fs/data.c

Quoted 1 line
fs/f2fs/data.c +1 -0
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >>

PAGE_SHIFT;

fs/f2fs/data.c

Quoted 5 lines
  		*fsdata = NULL;
fs/f2fs/data.c +2 -0
+		/*
+		 * when write pos is bigger than inode size

,f2fs_prepare_compress_overwrite

Quoted 15 lines

fs/f2fs/data.c

Quoted 4 lines
fs/f2fs/data.c +4 -0
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;

What if there're existing clusters beyond i_size? Given performance impacts, do we really need this?

Quoted 6 lines

+
ret = f2fs_prepare_compress_overwrite(inode, pagep,
index, fsdata);
if (ret < 0) {
--
2.29.0

Quoted 5 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#6 lore raw

I agree with this plan, I will also test this patch also.

Thanks

-----邮件原件-----
发件人: Chao Yu <[email protected]>
发送时间: 2021年5月12日 9:52
收件人: Jaegeuk Kim <[email protected]>; [email protected]
抄送: [email protected]
主题: Re: [f2fs-dev] 答复: [PATCH v4] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

I can't image a case that compressed cluster may cross filesize, it looks it's a bug if that happened, but I'm not sure I have considered all cases. So, I prefer to add a check condition as below, then testing w/ xfstest/por_fsstress for a while.

Subject: [PATCH] f2fs: compress: compressed cluster should not cross i_size

---
  fs/f2fs/data.c | 2 ++
  1 file changed, 2 insertions(+)
fs/f2fs/data.c +2 -0
@@ -3325,6 +3325,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
  			err = ret;
  			goto fail;
  		} else if (ret) {
+			f2fs_bug_on(sbi, index >=
+				DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
  			return 0;
  		}
  	}

--
2.29.2

Quoted 61 lines
Quoted 44 lines

Thanks.

-----邮件原件-----
发件人: Jaegeuk Kim <[email protected]>
发送时间: 2021年5月10日 23:44
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected] 主题: Re: [PATCH v4] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite

Quoted 8 lines · Fengnan Chang

when write compressed file with O_TRUNC, there will be a lot of unnecessary check valid blocks in f2fs_prepare_compress_overwrite, especially when written in page size, remove it.

This patch will not bring significant performance improvements, I test this on mobile phone, use androbench, the sequential write test case was open file with O_TRUNC, set write size to 4KB, performance improved about 2%-3%. If write size set to 32MB, performance improved

about 0.5%.

Quoted 14 lines
---
  fs/f2fs/data.c | 8 ++++++++
  1 file changed, 8 insertions(+)
fs/f2fs/data.c index renamed from fs/f2fs/data.c +0 -0

cf935474ffba..b9ec7b182f45 100644

fs/f2fs/data.c +0 -0
@@ -3303,9 +3303,17 @@ static int f2fs_write_begin(struct file *file,

struct address_space *mapping, #ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_compressed_file(inode)) {
int ret;

fs/f2fs/data.c

Quoted 1 line
fs/f2fs/data.c +1 -0
+		pgoff_t end = (i_size_read(inode) + PAGE_SIZE - 1) >>

PAGE_SHIFT;

fs/f2fs/data.c

Quoted 5 lines
  		*fsdata = NULL;
fs/f2fs/data.c +2 -0
+		/*
+		 * when write pos is bigger than inode size

,f2fs_prepare_compress_overwrite

Quoted 15 lines

fs/f2fs/data.c

Quoted 4 lines
fs/f2fs/data.c +4 -0
+		 * always return 0, so check pos first to avoid this.
+		 */
+		if (index >= end)
+			goto repeat;

What if there're existing clusters beyond i_size? Given performance impacts, do we really need this?

Quoted 6 lines

+
ret = f2fs_prepare_compress_overwrite(inode, pagep,
index, fsdata);
if (ret < 0) {
--
2.29.0

Quoted 5 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#7 lore raw
In reply to Chao Yu
Quoted 27 lines · Chao Yu
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

I can't image a case that compressed cluster may cross filesize, it looks it's a bug if that happened, but I'm not sure I have considered all cases. So, I prefer to add a check condition as below, then testing w/ xfstest/por_fsstress for a while.

Subject: [PATCH] f2fs: compress: compressed cluster should not cross i_size

---
 fs/f2fs/data.c | 2 ++
 1 file changed, 2 insertions(+)
fs/f2fs/data.c +0 -0
index 06d1e58d3882..9acca358d578 100644

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3332

Quoted 8 lines
fs/f2fs/data.c +2 -0
@@ -3325,6 +3325,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 			err = ret;
 			goto fail;
 		} else if (ret) {
+			f2fs_bug_on(sbi, index >=
+				DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
 			return 0;
 		}
 	}

If a file has both fs-verity and compression enabled, it can have compressed clusters past i_size.

- Eric

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#8 lore raw
Quoted 23 lines · Eric Biggers
Quoted 22 lines · Chao Yu
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

I can't image a case that compressed cluster may cross filesize, it looks it's a bug if that happened, but I'm not sure I have considered all cases. So, I prefer to add a check condition as below, then testing w/ xfstest/por_fsstress for a while.

Subject: [PATCH] f2fs: compress: compressed cluster should not cross i_size

---
  fs/f2fs/data.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 16 lines

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3332

Quoted 13 lines
fs/f2fs/data.c +2 -0
index 06d1e58d3882..9acca358d578 100644
@@ -3325,6 +3325,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
  			err = ret;
  			goto fail;
  		} else if (ret) {
+			f2fs_bug_on(sbi, index >=
+				DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
  			return 0;
  		}
  	}

If a file has both fs-verity and compression enabled, it can have compressed clusters past i_size.

Correct, any other case we missed for a writable file? let us know.

Thanks,

Quoted 4 lines

- Eric
.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#9 lore raw
Quoted 41 lines · Chao Yu
Quoted 23 lines · Eric Biggers
Quoted 22 lines · Chao Yu
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

I can't image a case that compressed cluster may cross filesize, it looks it's a bug if that happened, but I'm not sure I have considered all cases. So, I prefer to add a check condition as below, then testing w/ xfstest/por_fsstress for a while.

Subject: [PATCH] f2fs: compress: compressed cluster should not cross i_size

---
  fs/f2fs/data.c | 2 ++
  1 file changed, 2 insertions(+)
Quoted 16 lines

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3332

Quoted 13 lines
fs/f2fs/data.c +2 -0
index 06d1e58d3882..9acca358d578 100644
@@ -3325,6 +3325,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
  			err = ret;
  			goto fail;
  		} else if (ret) {
+			f2fs_bug_on(sbi, index >=
+				DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
  			return 0;
  		}
  	}

If a file has both fs-verity and compression enabled, it can have compressed clusters past i_size.

Quoted 4 lines

Correct, any other case we missed for a writable file? let us know.

Thanks,

Well, files become read-only once fs-verity is enabled on them, but that happens after the blocks past i_size are written in the first place. That part still uses ->write_begin(), ->write_end(), ->writepages(), etc.

- Eric

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#10 lore raw
Quoted 42 lines · Eric Biggers
Quoted 41 lines · Chao Yu
Quoted 39 lines · Eric Biggers
Quoted 27 lines · Chao Yu
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · On 05/11, [email protected] wrote:

Hi Jaegeuk:

If there're existing clusters beyond i_size, may cause data corruption, but will this happen in normal? maybe some error can cause this, if i_size is error the data beyond size still can't handle properly. Is there normal case can casue existing clusters beyond i_size?

We don't have a rule to sync between i_size and i_blocks.

I can't image a case that compressed cluster may cross filesize, it looks it's a bug if that happened, but I'm not sure I have considered all cases. So, I prefer to add a check condition as below, then testing w/ xfstest/por_fsstress for a while.

Subject: [PATCH] f2fs: compress: compressed cluster should not cross i_size

---
   fs/f2fs/data.c | 2 ++
   1 file changed, 2 insertions(+)
fs/f2fs/data.c +0 -0
index 06d1e58d3882..9acca358d578 100644

fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3332

Quoted 8 lines
fs/f2fs/data.c +2 -0
@@ -3325,6 +3325,8 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
   			err = ret;
   			goto fail;
   		} else if (ret) {
+			f2fs_bug_on(sbi, index >=
+				DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE));
   			return 0;
   		}
   	}

If a file has both fs-verity and compression enabled, it can have compressed clusters past i_size.

Quoted 8 lines
Quoted 4 lines

Correct, any other case we missed for a writable file? let us know.

Thanks,

Well, files become read-only once fs-verity is enabled on them, but that happens after the blocks past i_size are written in the first place. That part still uses ->write_begin(), ->write_end(), ->writepages(), etc.

Yup, the scenario we concern here is there is a writable file which has compressed cluster crossing filesize, and then it appends data starting from filesize.

Thanks,

Quoted 4 lines

- Eric
.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel