f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite
PATCH 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.
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/f2fs/data.c +4 -0
@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err =0 ;
@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, *fsdata =NULL ; +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
Quoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>
Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 27 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c +4
-1@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, *fsdata =NULL ; +if (index >= end) + goto repeat; + ret =f2fs_prepare_compress_overwrite (inode, pagep, index, fsdata);if (ret <0 ) { --
Quoted 1 line
2.29.0
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate with keep size, when write data to expand area, f2fs_prepare_compress_overwrite always return 0, the behavior is same as my patch , apply my patch can avoid those check.
Is there anything else I haven't thought of?
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite
Quoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>
Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 27 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;fs/f2fs/data.c +3
-0int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ; +if (index >= end) + goto repeat; + ret =f2fs_prepare_compress_overwrite (inode, pagep, index, fsdata);
Quoted 3 lines
if (ret < 0) {
--
2.29.0
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check.
Is there anything else I haven't thought of?
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)
If that is fine, I have no problem about this, yet i_size here is generally somewhat risky since after post-EOF behavior changes (e.g. supporting FALLOC_FL_ZERO_RANGE with keep size later), it may cause some potential regression.
Quoted 42 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 22 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;fs/f2fs/data.c +0
-0int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ;
Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+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
Maybe I should have been clearer. This modification has nothing to do with cluster size, and test is ok.
For now, f2fs_prepare_compress_overwrite will calculate number of valid blocks in compressed cluster, then decide whether need to read out the old data, when write pos is bigger than inode size, it's obvious unnecessary to calculate, because it always return 0, so check pos first to avoid this condition. So in my opinion, as long as the node size matches the valid data there will be no problem.
I don't quite understand what you say post-EOF behavior changes, but I found compressed file not support FALLOC_FL_ZERO_RANGE flag in fallocate, is this ok ?
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 17:00
收件人: [email protected]
抄送: [email protected]; [email protected]; [email protected]
主题: Re: 答复: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate
with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check. Is there anything else I haven't thought of?
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k), but with a partial fallocate (e.g. 16k), and does it behave ok?
or some other corner cases/conditions are needed.)
If that is fine, I have no problem about this, yet i_size here is generally somewhat risky since after post-EOF behavior changes (e.g. supporting FALLOC_FL_ZERO_RANGE with keep size later), it may cause some potential regression.
Quoted 42 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 22 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;fs/f2fs/data.c +0
-0int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ;
Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+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
Quoted 7 lines · Gao Xiang
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check.
Is there anything else I haven't thought of?
Quoted 5 lines
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)
Xiang, sorry for late reply.
Now, f2fs triggers compression only if one cluster is fully written, e.g. cluster size is 16kb, isize is 8kb, then the first cluster is non-compressed one, so we don't need to prepare for compressed cluster overwrite during write_begin(). Also, blocks fallocated beyond isize should never be compressed, so we don't need to worry about that.
Thanks,
Quoted 66 lines
If that is fine, I have no problem about this, yet
i_sizehere is generally somewhat risky since after post-EOF behavior changes (e.g. supportingFALLOC_FL_ZERO_RANGEwith keep size later), it may cause some potential regression.Quoted 42 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 22 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err = 0;fs/f2fs/data.c +0
-0@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ;Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+if (index >= end) + goto repeat; + 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
Hi Chao,
Quoted 14 lines · Chao Yu
Quoted 7 lines · Gao Xiang
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check.
Is there anything else I haven't thought of?Quoted 5 lines
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)
Quoted 9 lines
Xiang, sorry for late reply.
Now, f2fs triggers compression only if one cluster is fully written, e.g. cluster size is 16kb, isize is 8kb, then the first cluster is non-compressed one, so we don't need to prepare for compressed cluster overwrite during
write_begin(). Also, blocks fallocated beyond isize should never be compressed, so we don't need to worry about that.
Yeah, that could make it unnoticable. but my main concern is actually not what the current runtime compression logic is, but what the on-disk compresion format actually is, or there could cause compatibility issue if some later kernel makes full use of this and use old kernels instead (also considering some corrupted compression indexes, which is not generated by the normal runtime compression logic.)
My own suggestion about this is still verifying compress indexes first rather than relying much on runtime logic constraint. (Except that this patch can show signifiant benefit performance numbers to prove it can improve performance a lot.) Just my own premature thoughts.
Thanks,
Gao Xiang
Quoted 75 lines
Thanks,
Quoted 66 lines
If that is fine, I have no problem about this, yet
i_sizehere is generally somewhat risky since after post-EOF behavior changes (e.g. supportingFALLOC_FL_ZERO_RANGEwith keep size later), it may cause some potential regression.Quoted 42 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 22 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err = 0;fs/f2fs/data.c +0
-0@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ;Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+if (index >= end) + goto repeat; + ret =f2fs_prepare_compress_overwrite (inode, pagep, index, fsdata);if (ret < 0) {
--
2.29.0Quoted 5 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
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
Hi Xiang,
Quoted 27 lines · Gao Xiang
Hi Chao,
Quoted 14 lines · Chao Yu
Quoted 7 lines · Gao Xiang
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check.
Is there anything else I haven't thought of?Quoted 5 lines
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)Quoted 9 lines
Xiang, sorry for late reply.
Now, f2fs triggers compression only if one cluster is fully written, e.g. cluster size is 16kb, isize is 8kb, then the first cluster is non-compressed one, so we don't need to prepare for compressed cluster overwrite during
write_begin(). Also, blocks fallocated beyond isize should never be compressed, so we don't need to worry about that.
Quoted 4 lines
Yeah, that could make it unnoticable. but my main concern is actually not what the current runtime compression logic is, but what the on-disk compresion format actually is, or there could cause compatibility issue if some later kernel makes full use of this and use old kernels
That's related, if there is layout v2 or we updated runtime compression policy later, it needs to reconsider newly introduced logic of this patch, I guess we need to add comments here to indicate why we can skip the preparation function.
Quoted 2 lines
instead (also considering some corrupted compression indexes, which is not generated by the normal runtime compression logic.)
Yes, that's good concern, but that was not done by f2fs_prepare_compress_overwrite(), another sanity check logic needs to be designed and implemented in separated patch.
Quoted 6 lines
My own suggestion about this is still verifying compress indexes first rather than relying much on runtime logic constraint. (Except that this patch can show signifiant benefit performance numbers to prove it can improve performance a lot.) Just my own premature thoughts.
Fengnan, could you please give some numbers to show how that check can impact performance?
Thanks,
Quoted 79 lines
Thanks,
Gao XiangQuoted 75 lines
Thanks,
Quoted 71 lines
If that is fine, I have no problem about this, yet
i_sizehere is generally somewhat risky since after post-EOF behavior changes (e.g. supportingFALLOC_FL_ZERO_RANGEwith keep size later), it may cause some potential regression.Quoted 42 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 22 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err = 0;fs/f2fs/data.c +0
-0@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ;Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+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
Quoted 6 lines
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
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% .
-----邮件原件-----
发件人: Chao Yu <[email protected]>
发送时间: 2021年5月6日 18:38
收件人: Gao Xiang <[email protected]>
抄送: Gao Xiang <[email protected]>; [email protected]; [email protected]; [email protected] 主题: Re: [f2fs-dev] 答复: [PATCH] f2fs: compress: avoid unnecessary check in f2fs_prepare_compress_overwrite
Hi Xiang,
Quoted 27 lines · Gao Xiang
Hi Chao,
Quoted 14 lines · Chao Yu
Quoted 7 lines · Gao Xiang
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate
with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check. Is there anything else I haven't thought of?Quoted 5 lines
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)Quoted 9 lines
Xiang, sorry for late reply.
Now, f2fs triggers compression only if one cluster is fully written, e.g. cluster size is 16kb, isize is 8kb, then the first cluster is non-compressed one, so we don't need to prepare for compressed cluster overwrite during
write_begin(). Also, blocks fallocated beyond isize should never be compressed, so we don't need to worry about that.
Quoted 5 lines
Yeah, that could make it unnoticable. but my main concern is actually not what the current runtime compression logic is, but what the on-disk compresion format actually is, or there could cause compatibility issue if some later kernel makes full use of this and use old kernels
That's related, if there is layout v2 or we updated runtime compression policy later, it needs to reconsider newly introduced logic of this patch, I guess we need to add comments here to indicate why we can skip the preparation function.
Quoted 2 lines
instead (also considering some corrupted compression indexes, which is not generated by the normal runtime compression logic.)
Yes, that's good concern, but that was not done by f2fs_prepare_compress_overwrite(), another sanity check logic needs to be designed and implemented in separated patch.
Quoted 5 lines
My own suggestion about this is still verifying compress indexes first rather than relying much on runtime logic constraint. (Except that this patch can show signifiant benefit performance numbers to prove it can improve performance a lot.) Just my own premature thoughts.
Fengnan, could you please give some numbers to show how that check can impact performance?
Thanks,
Quoted 80 lines
Thanks,
Gao XiangQuoted 76 lines
Thanks,
Quoted 72 lines
If that is fine, I have no problem about this, yet
i_sizehere is generally somewhat risky since after post-EOF behavior changes (e.g. supportingFALLOC_FL_ZERO_RANGEwith keep size later), it may cause some potential regression.Quoted 43 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 23 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +2
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >> +PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, *fsdata =NULL ;Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+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
Quoted 6 lines
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
Quoted 5 lines · On Thu, May 06, 2021 at 08:15:40PM +0800, [email protected] wrote:
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%.
Ok, so considering this, my suggestion is that it'd be better to add your own configuration and raw test results to the commit message to show the reason why we need this constraint here.
Also, adding some inline comments about this sounds better.
Thanks,
Gao Xiang
Quoted 53 lines
-----邮件原件-----
发件人: Chao Yu <[email protected]>
发送时间: 2021年5月6日 18:38
收件人: Gao Xiang <[email protected]>
抄送: Gao Xiang <[email protected]>; [email protected]; [email protected]; [email protected] 主题: Re: [f2fs-dev] 答复: [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteHi Xiang,
Quoted 27 lines · Gao Xiang
Hi Chao,
Quoted 14 lines · Chao Yu
Quoted 7 lines · Gao Xiang
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate
with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check. Is there anything else I haven't thought of?Quoted 5 lines
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)Quoted 9 lines
Xiang, sorry for late reply.
Now, f2fs triggers compression only if one cluster is fully written, e.g. cluster size is 16kb, isize is 8kb, then the first cluster is non-compressed one, so we don't need to prepare for compressed cluster overwrite during
write_begin(). Also, blocks fallocated beyond isize should never be compressed, so we don't need to worry about that.Quoted 5 lines
Yeah, that could make it unnoticable. but my main concern is actually not what the current runtime compression logic is, but what the on-disk compresion format actually is, or there could cause compatibility issue if some later kernel makes full use of this and use old kernels
That's related, if there is layout v2 or we updated runtime compression policy later, it needs to reconsider newly introduced logic of this patch, I guess we need to add comments here to indicate why we can skip the preparation function.
Quoted 2 lines
instead (also considering some corrupted compression indexes, which is not generated by the normal runtime compression logic.)
Yes, that's good concern, but that was not done by
f2fs_prepare_compress_overwrite(), another sanity check logic needs to be designed and implemented in separated patch.Quoted 1 line
Quoted 97 lines
Quoted 4 lines
My own suggestion about this is still verifying compress indexes first rather than relying much on runtime logic constraint. (Except that this patch can show signifiant benefit performance numbers to prove it can improve performance a lot.) Just my own premature thoughts.
Fengnan, could you please give some numbers to show how that check can impact performance?
Thanks,
Quoted 86 lines
Thanks,
Gao XiangQuoted 76 lines
Thanks,
Quoted 67 lines
If that is fine, I have no problem about this, yet
i_sizehere is generally somewhat risky since after post-EOF behavior changes (e.g. supportingFALLOC_FL_ZERO_RANGEwith keep size later), it may cause some potential regression.Quoted 43 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 23 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +2
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >> +PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, *fsdata =NULL ;Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+if (index >= end) + goto repeat; + ret =f2fs_prepare_compress_overwrite (inode, pagep, index, fsdata);if (ret < 0) {--
2.29.0Quoted 5 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-develQuoted 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
Quoted 35 lines · Chao Yu
Hi Xiang,
Quoted 27 lines · Gao Xiang
Hi Chao,
Quoted 14 lines · Chao Yu
Quoted 7 lines · Gao Xiang
Quoted 5 lines · On Mon, Apr 26, 2021 at 04:42:20PM +0800, [email protected] wrote:
Thank you for the reminder, I hadn't thought about fallocate before.
I have done some tests and the results are as expected.
Here is my test method, create a compressed file, and use fallocate with keep size, when write data to expand area,f2fs_prepare_compress_overwritealways return 0, the behavior is same as my patch , apply my patch can avoid those check.
Is there anything else I haven't thought of?Quoted 5 lines
Nope, I didn't look into the implementation. Just a wild guess.
(I just wondered if the cluster size is somewhat large (e.g. 64k),
but with a partial fallocate (e.g. 16k), and does it behave ok? or some other corner cases/conditions are needed.)Quoted 9 lines
Xiang, sorry for late reply.
Now, f2fs triggers compression only if one cluster is fully written, e.g. cluster size is 16kb, isize is 8kb, then the first cluster is non-compressed one, so we don't need to prepare for compressed cluster overwrite during
write_begin(). Also, blocks fallocated beyond isize should never be compressed, so we don't need to worry about that.Quoted 4 lines
Yeah, that could make it unnoticable. but my main concern is actually not what the current runtime compression logic is, but what the on-disk compresion format actually is, or there could cause compatibility issue if some later kernel makes full use of this and use old kernels
Quoted 4 lines
That's related, if there is layout v2 or we updated runtime compression policy later, it needs to reconsider newly introduced logic of this patch, I guess we need to add comments here to indicate why we can skip the preparation function.
Anyway, my thoughts is mainly to distinguish the current runtime compression logic and the proposal on-disk format by design. If it's easy to support reading partial written clusters and post-EOF cases in practice with a few lines, so the later compression logic could use compat feature (or at least ro_compat feature) to update, which is much better than an incompat feature for older kernels.
But if it's somewhat hard to add simply, that makes no difference so v2 may need to be introduced instead.
Quoted 9 lines
Quoted 3 lines
instead (also considering some corrupted compression indexes, which is not generated by the normal runtime compression logic.)
Yes, that's good concern, but that was not done by
f2fs_prepare_compress_overwrite(), another sanity check logic needs to be designed and implemented in separated patch.Quoted 1 line
Quoted 8 lines
Quoted 5 lines
My own suggestion about this is still verifying compress indexes first rather than relying much on runtime logic constraint. (Except that this patch can show signifiant benefit performance numbers to prove it can improve performance a lot.) Just my own premature thoughts.
Fengnan, could you please give some numbers to show how that check can impact performance?
IMO, it'd be better to show some real numbers to add more constraint like this, if it can be measureable, that is another story indeed.
Thanks,
Gao Xiang
Quoted 88 lines
Thanks,
Quoted 85 lines
Thanks,
Gao XiangQuoted 75 lines
Thanks,
Quoted 66 lines
If that is fine, I have no problem about this, yet
i_sizehere is generally somewhat risky since after post-EOF behavior changes (e.g. supportingFALLOC_FL_ZERO_RANGEwith keep size later), it may cause some potential regression.Quoted 42 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2021年4月26日 11:19
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [PATCH] f2fs: compress: avoid unnecessary check inf2fs_prepare_compress_overwriteQuoted 5 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>Even though I didn't look into the whole thing, my reaction here is roughly how to handle fallocate with keep size? Does it work as expected?
Quoted 22 lines
--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c index renamed from fs/f2fs/data.c +0
-0
cf935474ffba..9c3b0849f35e100644fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, struct f2fs_sb_info *sbi = F2FS_I_SB(inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err = 0;fs/f2fs/data.c +0
-0@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file,struct address_space *mapping, *fsdata =NULL ;Quoted 15 lines
Quoted 8 lines
fs/f2fs/data.c +3
-0+if (index >= end) + goto repeat; + ret =f2fs_prepare_compress_overwrite (inode, pagep, index, fsdata);if (ret < 0) {--
2.29.0Quoted 5 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-develQuoted 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
Quoted 14 lines · Fengnan Chang
when write compressed file with
O_TRUNC, there will be a lot of unnecessary check valid blocks inf2fs_prepare_compress_overwrite, especially when written in page size, remove it.Signed-off-by Fengnan Chang <[email protected]>--- fs/f2fs/data.c | 4 ++++ 1 file changed, 4 insertions(+)fs/f2fs/data.c +0
-0
fs/f2fs/data.c static int f2fs_write_begin(struct file *file, struct address_space *mapping, · line 3273
Quoted 4 lines
fs/f2fs/data.c +1
-0@@ -3270,6 +3270,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct page *page =NULL ;pgoff_t index = ((unsigned long long ) pos) >>PAGE_SHIFT ; +pgoff_t end = (i_size_read (inode) +PAGE_SIZE -1 ) >>PAGE_SHIFT ;
Should define this under compression macro, otherwise it may cause compile warning.
Quoted 18 lines
fs/f2fs/data.c +3
-1bool need_balance = false, drop_atomic = false;block_t blkaddr =NULL_ADDR ;int err =0 ;@@ -3306,6 +3307,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, *fsdata =NULL ; +if (index >= end) + goto repeat; + ret =f2fs_prepare_compress_overwrite (inode, pagep, index, fsdata);if (ret <0 ) { --2.29.0
Quoted 6 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