Skip to contentSkip to conversation

f2fs: compress: remove unneeded read when rewrite whole cluster

RFC PATCH Superseded Fengnan Chang 3 participants 7 messages May 18, 2021 – Jun 8, 2021 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 f2fs: compress: remove unneeded read when rewrite whole cluster

For now,when overwrite compressed file, we need read old data to page cache first and update pages.
But when we need overwrite whole cluster, we don't need old data anymore.
So, I think we can remove read data process in this case, I have made some simple changes to test, tests have shown that this can lead to significant performance improvements, the speed of sequential write up to 2x.

I haven't figured out the whole process yet,so the following modification is a simple and crude, any suggestions are welcome. I want to know if this idea is workable,if so, I will continue to improve this patch.
Thanks.

---
 fs/f2fs/compress.c | 12 ++++++------
 fs/f2fs/data.c     |  4 ++--
 fs/f2fs/f2fs.h     |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)
fs/f2fs/compress.c +6 -6
index 925a5ca3744a..7056c009ee9a 100644
@@ -990,7 +990,7 @@ static void set_cluster_dirty(struct compress_ctx *cc)
 }
 
 static int prepare_compress_overwrite(struct compress_ctx *cc,
-		struct page **pagep, pgoff_t index, void **fsdata)
+		struct page **pagep, pgoff_t index, void **fsdata, int len)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode);
 	struct address_space *mapping = cc->inode->i_mapping;
@@ -1007,6 +1007,8 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 	if (ret <= 0)
 		return ret;
 
+	if (len == PAGE_SIZE)
+		return 0;
 	/* compressed case */
 	prealloc = (ret < cc->cluster_size);
 
@@ -1045,7 +1047,6 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 		if (ret)
 			goto out;
 	}
-
 	for (i = 0; i < cc->cluster_size; i++) {
 		f2fs_bug_on(sbi, cc->rpages[i]);
 
@@ -1101,7 +1102,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 }
 
 int f2fs_prepare_compress_overwrite(struct inode *inode,
-		struct page **pagep, pgoff_t index, void **fsdata)
+		struct page **pagep, pgoff_t index, void **fsdata, int len)
 {
 	struct compress_ctx cc = {
 		.inode = inode,
@@ -1111,8 +1112,7 @@ int f2fs_prepare_compress_overwrite(struct inode *inode,
 		.rpages = NULL,
 		.nr_rpages = 0,
 	};
-
-	return prepare_compress_overwrite(&cc, pagep, index, fsdata);
+	return prepare_compress_overwrite(&cc, pagep, index, fsdata, len);
 }
 
 bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
@@ -1155,7 +1155,7 @@ int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock)
 
 	/* truncate compressed cluster */
 	err = f2fs_prepare_compress_overwrite(inode, &pagep,
-						start_idx, &fsdata);
+						start_idx, &fsdata, 0);
 
 	/* should not be a normal cluster */
 	f2fs_bug_on(F2FS_I_SB(inode), err == 0);
fs/f2fs/data.c +2 -2
index 009a09fb9d88..9a6b82d8f278 100644
@@ -2916,7 +2916,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
 
 					ret2 = f2fs_prepare_compress_overwrite(
 							inode, &pagep,
-							page->index, &fsdata);
+							page->index, &fsdata, 0);
 					if (ret2 < 0) {
 						ret = ret2;
 						done = 1;
@@ -3307,7 +3307,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 		*fsdata = NULL;
 
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
-							index, fsdata);
+							index, fsdata, len);
 		if (ret < 0) {
 			err = ret;
 			goto fail;
fs/f2fs/f2fs.h +1 -1
index c83d90125ebd..8d4fedf0291b 100644
@@ -3932,7 +3932,7 @@ static inline bool f2fs_post_read_required(struct inode *inode)
 bool f2fs_is_compressed_page(struct page *page);
 struct page *f2fs_compress_control_page(struct page *page);
 int f2fs_prepare_compress_overwrite(struct inode *inode,
-			struct page **pagep, pgoff_t index, void **fsdata);
+			struct page **pagep, pgoff_t index, void **fsdata, int len);
 bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
 					pgoff_t index, unsigned copied);
 int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock);
Signature · 8 lines
2.29.0



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

Hi:
Any comments for this?

Thanks.

-----邮件原件-----
发件人: Fengnan Chang <[email protected]>
发送时间: 2021年5月18日 20:51
收件人: [email protected]; [email protected]; [email protected]
抄送: Fengnan Chang <[email protected]>
主题: [RFC PATCH] f2fs: compress: remove unneeded read when rewrite whole cluster

For now,when overwrite compressed file, we need read old data to page cache first and update pages.
But when we need overwrite whole cluster, we don't need old data anymore. So, I think we can remove read data process in this case, I have made some simple changes to test, tests have shown that this can lead to significant performance improvements, the speed of sequential write up to 2x.

I haven't figured out the whole process yet,so the following modification is a simple and crude, any suggestions are welcome.
I want to know if this idea is workable,if so, I will continue to improve this patch.
Thanks.

---
 fs/f2fs/compress.c | 12 ++++++------
 fs/f2fs/data.c     |  4 ++--
 fs/f2fs/f2fs.h     |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)
fs/f2fs/compress.c index renamed from fs/f2fs/compress.c +0 -0

925a5ca3744a..7056c009ee9a 100644

fs/f2fs/compress.c +0 -0
@@ -990,7 +990,7 @@ static void set_cluster_dirty(struct compress_ctx *cc)

}

static int prepare_compress_overwrite(struct compress_ctx *cc,
- struct page **pagep, pgoff_t index, void **fsdata)
+ struct page **pagep, pgoff_t index, void **fsdata, int len)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode); struct address_space *mapping = cc->inode->i_mapping; @@ -1007,6
+1007,8 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
if (ret <= 0)
return ret;

+ if (len == PAGE_SIZE)
+ return 0;
/* compressed case */
prealloc = (ret < cc->cluster_size);

@@ -1045,7 +1047,6 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
if (ret)
goto out;
}
-
for (i = 0; i < cc->cluster_size; i++) {
f2fs_bug_on(sbi, cc->rpages[i]);

@@ -1101,7 +1102,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, }

int f2fs_prepare_compress_overwrite(struct inode *inode,
- struct page **pagep, pgoff_t index, void **fsdata)
+ struct page **pagep, pgoff_t index, void **fsdata, int len)
{
struct compress_ctx cc = {
.inode = inode,
@@ -1111,8 +1112,7 @@ int f2fs_prepare_compress_overwrite(struct inode *inode,
.rpages = NULL,
.nr_rpages = 0,
};
-
- return prepare_compress_overwrite(&cc, pagep, index, fsdata);
+ return prepare_compress_overwrite(&cc, pagep, index, fsdata, len);
}

bool f2fs_compress_write_end(struct inode *inode, void *fsdata, @@ -1155,7
+1155,7 @@ int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock)

/* truncate compressed cluster */
err = f2fs_prepare_compress_overwrite(inode, &pagep,
- start_idx, &fsdata);
+ start_idx, &fsdata, 0);

/* should not be a normal cluster */ f2fs_bug_on(F2FS_I_SB(inode), err == 0); diff --git a/fs/f2fs/data.c
b/fs/f2fs/data.c index 009a09fb9d88..9a6b82d8f278 100644

fs/f2fs/data.c +0 -0
@@ -2916,7 +2916,7 @@ static int f2fs_write_cache_pages(struct address_space

*mapping,

ret2 =
f2fs_prepare_compress_overwrite(
inode, &pagep,
- page->index,
&fsdata);
+ page->index,
&fsdata, 0);
if (ret2 < 0) {
ret = ret2; done = 1;
@@ -3307,7 +3307,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
*fsdata = NULL;

ret = f2fs_prepare_compress_overwrite(inode, pagep,
- index, fsdata);
+ index, fsdata, len);
if (ret < 0) {
err = ret;
goto fail;

fs/f2fs/f2fs.h index renamed from fs/f2fs/f2fs.h +0 -0

c83d90125ebd..8d4fedf0291b 100644

fs/f2fs/f2fs.h +0 -0
@@ -3932,7 +3932,7 @@ static inline bool f2fs_post_read_required(struct

inode *inode) bool f2fs_is_compressed_page(struct page *page); struct page *f2fs_compress_control_page(struct page *page); int f2fs_prepare_compress_overwrite(struct inode *inode,
- struct page **pagep, pgoff_t index, void **fsdata);
+ struct page **pagep, pgoff_t index, void **fsdata,
int len);
bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
pgoff_t index, unsigned copied);
int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool
lock);
--
2.29.0

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

#2 lore raw
In reply to Fengnan Chang
Quoted 4 lines · Fengnan Chang

For now,when overwrite compressed file, we need read old data to page cache first and update pages.
But when we need overwrite whole cluster, we don't need old data anymore.

I only see you just check the whole page was dirty as below rather than the whole cluster is dirty during write().

Thanks,

fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 1013

Quoted 5 lines
fs/f2fs/compress.c +2 -0
+	if (len == PAGE_SIZE)
+		return 0;
  	/* compressed case */
  	prealloc = (ret < cc->cluster_size);

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

#3 lore raw

yes, I just check wheather the whole page was dirty, because of when write cache f2fs_prepare_compress_overwrite will be called again,
when update whole cluster, cc in prepare_compress_overwrite will be empty, so will not submit bio.
when only update one page in cluster, cc in prepare_compress_overwrite will not be empty, so will submit bio.
This is my thinking, not sure if I've missed anything

-----邮件原件-----
发件人: Chao Yu <[email protected]>
发送时间: 2021年5月24日 19:39
收件人: Fengnan Chang <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [RFC PATCH] f2fs: compress: remove unneeded read when rewrite whole cluster

Quoted 4 lines · Fengnan Chang

For now,when overwrite compressed file, we need read old data to page cache first and update pages.
But when we need overwrite whole cluster, we don't need old data anymore.

I only see you just check the whole page was dirty as below rather than the whole cluster is dirty during write().

Thanks,

fs/f2fs/compress.c static int prepare_compress_overwrite(struct compress_ctx *cc, · line 1013

Quoted 5 lines
fs/f2fs/compress.c +2 -0
+	if (len == PAGE_SIZE)
+		return 0;
  	/* compressed case */
  	prealloc = (ret < cc->cluster_size);

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

#4 lore raw
Quoted 7 lines · On 2021/5/25 20:05, [email protected] wrote:

yes, I just check wheather the whole page was dirty, because of when write cache f2fs_prepare_compress_overwrite will be called again,
when update whole cluster, cc in prepare_compress_overwrite will be empty, so will not submit bio.
when only update one page in cluster, cc in prepare_compress_overwrite will not be empty, so will submit bio.
This is my thinking, not sure if I've missed anything

Well, it looks more like we did for mmap() write case.

So I guess we can change as below:

To Jaegeuk, comments?

---
 fs/f2fs/data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +1 -1
index 2ea887a114c8..723c59df51b7 100644
@@ -3323,7 +3323,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 	}
 
 #ifdef CONFIG_F2FS_FS_COMPRESSION
-	if (f2fs_compressed_file(inode)) {
+	if (f2fs_compressed_file(inode) && len != PAGE_SIZE) {
 		int ret;
 
 		*fsdata = NULL;
Signature · 3 lines
2.29.2

Thanks,
Quoted 21 lines

-----邮件原件-----
发件人: Chao Yu <[email protected]>
发送时间: 2021年5月24日 19:39
收件人: Fengnan Chang <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: [f2fs-dev] [RFC PATCH] f2fs: compress: remove unneeded read when rewrite whole cluster

Quoted 4 lines · Fengnan Chang

For now,when overwrite compressed file, we need read old data to page cache first and update pages.
But when we need overwrite whole cluster, we don't need old data anymore.

I only see you just check the whole page was dirty as below rather than the whole cluster is dirty during write().

Thanks,

Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+	if (len == PAGE_SIZE)
+		return 0;
   	/* compressed case */
   	prealloc = (ret < cc->cluster_size);

.

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

#5 lore raw
Quoted 24 lines · Chao Yu
Quoted 7 lines · On 2021/5/25 20:05, [email protected] wrote:

yes, I just check wheather the whole page was dirty, because of when write cache f2fs_prepare_compress_overwrite will be called again,
when update whole cluster, cc in prepare_compress_overwrite will be empty, so will not submit bio.
when only update one page in cluster, cc in prepare_compress_overwrite will not be empty, so will submit bio.
This is my thinking, not sure if I've missed anything

Well, it looks more like we did for mmap() write case.

So I guess we can change as below:

To Jaegeuk, comments?

---
   fs/f2fs/data.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +0 -0
index 2ea887a114c8..723c59df51b7 100644

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

Quoted 5 lines
fs/f2fs/data.c +1 -1
@@ -3323,7 +3323,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
   	}
 
   #ifdef CONFIG_F2FS_FS_COMPRESSION
-	if (f2fs_compressed_file(inode)) {
+	if (f2fs_compressed_file(inode) && len != PAGE_SIZE) {

It will cause panic in f2fs_write_end() due to miss to assign fsdata with NULL, updated as below:

---
 fs/f2fs/data.c | 3 +++
 1 file changed, 3 insertions(+)
fs/f2fs/data.c +3 -0
index 2ea887a114c8..4e214ac87925 100644
@@ -3328,6 +3328,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
 
 		*fsdata = NULL;
 
+		if (len == PAGE_SIZE)
+			goto repeat;
+
 		ret = f2fs_prepare_compress_overwrite(inode, pagep,
 							index, fsdata);
 		if (ret < 0) {
Signature · 3 lines
2.29.2

Thanks,

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

Quoted 4 lines
fs/f2fs/data.c +0 -0
   		int ret;
 
   		*fsdata = NULL;

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

#6 lore raw

Hi Jaegeuk:

Any comments about this patch?

Thanks.

-----邮件原件-----
发件人: Chao Yu <[email protected]>
发送时间: 2021年5月29日 9:13
收件人: [email protected]; [email protected]
抄送: [email protected]
主题: Re: [f2fs-dev] 答复: [RFC PATCH] f2fs: compress: remove unneeded read when rewrite whole cluster

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

Quoted 24 lines · Chao Yu
Quoted 7 lines · On 2021/5/25 20:05, [email protected] wrote:

yes, I just check wheather the whole page was dirty, because of when write cache f2fs_prepare_compress_overwrite will be called again, when update whole cluster, cc in prepare_compress_overwrite will be empty, so will not submit bio.
when only update one page in cluster, cc in prepare_compress_overwrite will not be empty, so will submit bio. This is my thinking, not sure if I've missed anything

Well, it looks more like we did for mmap() write case.

So I guess we can change as below:

To Jaegeuk, comments?

---
   fs/f2fs/data.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c index renamed from fs/f2fs/data.c +0 -0

2ea887a114c8..723c59df51b7 100644

fs/f2fs/data.c +0 -0
@@ -3323,7 +3323,7 @@ static int f2fs_write_begin(struct file *file,

struct address_space *mapping,

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

Quoted 5 lines
fs/f2fs/data.c +1 -1
   	}
 
   #ifdef CONFIG_F2FS_FS_COMPRESSION
-	if (f2fs_compressed_file(inode)) {
+	if (f2fs_compressed_file(inode) && len != PAGE_SIZE) {

It will cause panic in f2fs_write_end() due to miss to assign fsdata with NULL, updated as below:

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

2ea887a114c8..4e214ac87925 100644

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

address_space *mapping,

  		*fsdata = NULL;

+ if (len == PAGE_SIZE)
+ goto repeat;
+
ret = f2fs_prepare_compress_overwrite(inode, pagep,
index, fsdata);
if (ret < 0) {
--
2.29.2

Thanks,

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

Quoted 4 lines
fs/f2fs/data.c +0 -0
   		int ret;
 
   		*fsdata = NULL;

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