f2fs: compress: fix overwrite may reduce compress ratio unproperly
PATCH v2 1/1 f2fs: compress: fix overwrite may reduce compress ratio unproperly
when overwrite only first block of cluster, since cluster is not full, it will call f2fs_write_raw_pages when f2fs_write_multi_pages, and cause the whole cluster become uncompressed eventhough data can be compressed. this may will make random write bench score reduce a lot.
root# dd if=/dev/zero of=./fio-test bs=1M count=1
root# sync
root# echo 3 > /proc/sys/vm/drop_caches
root# f2fs_io get_cblocks ./fio-test
root# dd if=/dev/zero of=./fio-test bs=4K count=1 oflag=direct conv=notrunc
w/o patch:
root# f2fs_io get_cblocks ./fio-test
189
w/ patch:
root# f2fs_io get_cblocks ./fio-test
192
--- fs/f2fs/compress.c | 12 ++++++++++++ fs/f2fs/data.c | 7 +++++++ fs/f2fs/f2fs.h | 1 + 3 files changed, 20 insertions(+)
fs/f2fs/compress.c +12 -0
@@ -857,6 +857,18 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed,f2fs_decompress_cluster (dic); } +bool is_page_same_cluster (struct compress_ctx *cc,struct pagevec *pvec,int index) +{ +int idx =cluster_idx (cc, pvec->pages[index]->index); +int i = index +1 ; + +for (i = index +1 ; i < index + cc->cluster_size; i++) { +if (cluster_idx (cc, pvec->pages[i]->index) != idx) +return false; + } + +return true; +}static bool is_page_in_cluster (struct compress_ctx *cc,pgoff_t index) {if (cc->cluster_idx ==NULL_CLUSTER )
fs/f2fs/data.c +7 -0
@@ -3025,6 +3025,13 @@ static int f2fs_write_cache_pages(struct address_space *mapping, 1)) { retry =1 ;break ; + } else if (ret2 && nr_pages - i < cc.cluster_size) { + retry =1 ; +break ; + } else if (ret2 && nr_pages - i >= cc.cluster_size && + !is_page_same_cluster(&cc, &pvec, i)) { + retry =1 ; +break ; } }else { goto lock_page;
fs/f2fs/f2fs.h +1 -0
@@ -4031,6 +4031,7 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed,bool f2fs_cluster_is_empty (struct compress_ctx *cc);bool f2fs_cluster_can_merge_page (struct compress_ctx *cc,pgoff_t index);bool f2fs_sanity_check_cluster (struct dnode_of_data *dn); +bool is_page_same_cluster (struct compress_ctx *cc,struct pagevec *pvec,int index);void f2fs_compress_ctx_add_page (struct compress_ctx *cc,struct page *page); int f2fs_write_multi_pages(struct compress_ctx *cc, int *submitted,
Signature · 8 lines
2.32.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 35 lines · Fengnan Chang
when overwrite only first block of cluster, since cluster is not full, it will call
f2fs_write_raw_pageswhenf2fs_write_multi_pages, and cause the whole cluster become uncompressed eventhough data can be compressed. this may will make random write bench score reduce a lot.root# dd if=/dev/zero of=./fio-test bs=1M count=1
root# sync
root# echo 3 >
/proc/sys/vm/drop_cachesroot#
f2fs_ioget_cblocks./fio-testroot# dd if=/dev/zero of=./fio-test bs=4K count=1 oflag=direct conv=notrunc
w/o patch:
root#f2fs_ioget_cblocks./fio-test
189w/ patch:
root#f2fs_ioget_cblocks./fio-test
192Signed-off-by Fengnan Chang <[email protected]>--- fs/f2fs/compress.c | 12 ++++++++++++ fs/f2fs/data.c | 7 +++++++ fs/f2fs/f2fs.h | 1 + 3 files changed, 20 insertions(+)fs/f2fs/compress.c +0
-0
fs/f2fs/compress.c void f2fs_end_read_compressed_page(struct page *page, bool failed, · line 860
Quoted 4 lines
fs/f2fs/compress.c +1
-0@@ -857,6 +857,18 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed,f2fs_decompress_cluster (dic); } +bool is_page_same_cluster (struct compress_ctx *cc,struct pagevec *pvec,int index)
Fengnan,
It needs add f2fs prefix for non-static symbol to avoid global namespace pollution.
Anyway, how about this?
--- fs/f2fs/compress.c | 19 +++++++++++++++++++ fs/f2fs/data.c | 7 ++++--- fs/f2fs/f2fs.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-)
fs/f2fs/compress.c +19 -0
@@ -881,6 +881,25 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index)return is_page_in_cluster (cc, index); } +bool f2fs_all_cluster_page_loaded (struct compress_ctx *cc,struct pagevec *pvec, +int index,int nr_pages) +{ +unsigned long pgidx; +int i; + +if (nr_pages - index < cc->cluster_size) +return false; + + pgidx = pvec->pages[index]->index; + +for (i =1 ; i < cc->cluster_size; i++) { +if (pvec->pages[index + i]->index != pgidx + i) +return false; + } + +return true; +} +static bool cluster_has_invalid_data (struct compress_ctx *cc) {loff_t i_size =i_size_read (cc->inode);
fs/f2fs/data.c +4 -3
@@ -3075,9 +3075,10 @@ static int f2fs_write_cache_pages(struct address_space *mapping, done =1 ;break ; }else if (ret2 && - !f2fs_compress_write_end (inode, - fsdata, page->index, -1 )) { + (!f2fs_compress_write_end (inode, + fsdata, page->index,1 ) || + !f2fs_all_cluster_page_loaded (&cc, + &pvec, i, nr_pages))) { retry =1 ;break ; }
fs/f2fs/f2fs.h +2 -0
@@ -4047,6 +4047,8 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed, block_t blkaddr);bool f2fs_cluster_is_empty (struct compress_ctx *cc);bool f2fs_cluster_can_merge_page (struct compress_ctx *cc,pgoff_t index); +bool f2fs_all_cluster_page_loaded (struct compress_ctx *cc,struct pagevec *pvec, +int index,int nr_pages);bool f2fs_sanity_check_cluster (struct dnode_of_data *dn);void f2fs_compress_ctx_add_page (struct compress_ctx *cc,struct page *page); int f2fs_write_multi_pages(struct compress_ctx *cc,
Signature · 9 lines
2.32.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
A message that is not in the archive (sent off-list or not yet received): ALgAyADvEmTgm6EcRRwmGaoi.9.1634826831858.Hmail.changfengnan@vivo.com
Quoted 58 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Chao Yu
Sent: Thursday, October 21, 2021 10:34 PM
To: 常凤楠 <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH v2] f2fs: compress: fix overwrite may reduce compress ratio unproperlyQuoted 3 lines · Fengnan Chang
when overwrite only first block of cluster, since cluster is not full, it will call
f2fs_write_raw_pageswhenf2fs_write_multi_pages, and cause the whole cluster become uncompressed eventhough data can becompressed.
fs/f2fs/compress.c void f2fs_end_read_compressed_page(struct page
Quoted 33 lines
this may will make random write bench score reduce a lot.
root# dd if=/dev/zero of=./fio-test bs=1M count=1
root# sync
root# echo 3 >
/proc/sys/vm/drop_cachesroot#
f2fs_ioget_cblocks./fio-testroot# dd if=/dev/zero of=./fio-test bs=4K count=1 oflag=direct conv=notrunc
w/o patch:
root#f2fs_ioget_cblocks./fio-test
189w/ patch:
root#f2fs_ioget_cblocks./fio-test
192Signed-off-by Fengnan Chang <[email protected]>--- fs/f2fs/compress.c | 12 ++++++++++++ fs/f2fs/data.c | 7 +++++++ fs/f2fs/f2fs.h | 1 + 3 files changed, 20 insertions(+)fs/f2fs/compress.c index renamed from fs/f2fs/compress.c +0
-0
c1bf9ad4c220..c4f36ead6f17100644fs/f2fs/compress.c +0
-0@@ -857,6 +857,18 @@ void f2fs_end_read_compressed_page(struct page*page, bool failed,
fs/f2fs/compress.c void f2fs_end_read_compressed_page(struct page *page, bool failed,
Quoted 5 lines
fs/f2fs/compress.c +2
-0f2fs_decompress_cluster (dic); } +bool is_page_same_cluster (struct compress_ctx *cc,struct pagevec +*pvec,int index)Fengnan,
Quoted 4 lines
It needs add f2fs prefix for non-static symbol to avoid global namespace pollution.
Anyway, how about this?
It looks good for me, you can make this as V3.
Quoted 70 lines
--- fs/f2fs/compress.c | 19 +++++++++++++++++++ fs/f2fs/data.c | 7 ++++--- fs/f2fs/f2fs.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-)fs/f2fs/compress.c index renamed from fs/f2fs/compress.c +0
-0
c1bf9ad4c220..15d9b89d4df0100644fs/f2fs/compress.c +19
-0@@ -881,6 +881,25 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index) return is_page_in_cluster(cc, index); } +bool f2fs_all_cluster_page_loaded (struct compress_ctx *cc,struct pagevec *pvec, +int index,int nr_pages) +{ +unsigned long pgidx; +int i; + +if (nr_pages - index < cc->cluster_size) +return false; + + pgidx = pvec->pages[index]->index; + +for (i =1 ; i < cc->cluster_size; i++) { +if (pvec->pages[index + i]->index != pgidx + i) +return false; + } + +return true; +} +static bool cluster_has_invalid_data (struct compress_ctx *cc){
loff_ti_size=i_size_read(cc->inode); diff --gita/fs/f2fs/data.cb/fs/f2fs/data.cindex14fe5c6216cc..b0665f69c093100644fs/f2fs/data.c +4
-3@@ -3075,9 +3075,10 @@ static int f2fs_write_cache_pages(structaddress_space *mapping, done =1 ;break ; }else if (ret2 && - !f2fs_compress_write_end (inode, - fsdata, page->index, -1 )) { + (!f2fs_compress_write_end (inode, + fsdata, page->index,1 ) || + !f2fs_all_cluster_page_loaded (&cc, + &pvec, i, nr_pages))) { retry =1 ;break ;}fs/f2fs/f2fs.h index 7a32c2127945..b8da34198ce0 renamed from fs/f2fs/f2fs.h +0
-0100644
fs/f2fs/f2fs.h +2
-0@@ -4047,6 +4047,8 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed, block_t blkaddr);bool f2fs_cluster_is_empty (struct compress_ctx *cc);bool f2fs_cluster_can_merge_page (struct compress_ctx *cc,pgoff_t index); +bool f2fs_all_cluster_page_loaded (struct compress_ctx *cc,struct pagevec *pvec, +int index,int nr_pages);bool f2fs_sanity_check_cluster (struct dnode_of_data *dn);
Quoted 6 lines
void f2fs_compress_ctx_add_page(struct
compress_ctx*cc, struct page
*page);
int f2fs_write_multi_pages(structcompress_ctx*cc,
--
2.32.0
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 58 lines · 常凤楠
Quoted 58 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Chao Yu
Sent: Thursday, October 21, 2021 10:34 PM
To: 常凤楠 <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH v2] f2fs: compress: fix overwrite may reduce compress ratio unproperlyQuoted 3 lines · Fengnan Chang
when overwrite only first block of cluster, since cluster is not full, it will call
f2fs_write_raw_pageswhenf2fs_write_multi_pages, and cause the whole cluster become uncompressed eventhough data can becompressed.
fs/f2fs/compress.c void f2fs_end_read_compressed_page(struct page
Quoted 33 lines
this may will make random write bench score reduce a lot.
root# dd if=/dev/zero of=./fio-test bs=1M count=1
root# sync
root# echo 3 >
/proc/sys/vm/drop_cachesroot#
f2fs_ioget_cblocks./fio-testroot# dd if=/dev/zero of=./fio-test bs=4K count=1 oflag=direct conv=notrunc
w/o patch:
root#f2fs_ioget_cblocks./fio-test
189w/ patch:
root#f2fs_ioget_cblocks./fio-test
192Signed-off-by Fengnan Chang <[email protected]>--- fs/f2fs/compress.c | 12 ++++++++++++ fs/f2fs/data.c | 7 +++++++ fs/f2fs/f2fs.h | 1 + 3 files changed, 20 insertions(+)fs/f2fs/compress.c index renamed from fs/f2fs/compress.c +0
-0
c1bf9ad4c220..c4f36ead6f17100644fs/f2fs/compress.c +0
-0@@ -857,6 +857,18 @@ void f2fs_end_read_compressed_page(struct page*page, bool failed,
fs/f2fs/compress.c void f2fs_end_read_compressed_page(struct page *page, bool failed,
Quoted 5 lines
fs/f2fs/compress.c +2
-0f2fs_decompress_cluster (dic); } +bool is_page_same_cluster (struct compress_ctx *cc,struct pagevec +*pvec,int index)Fengnan,
Quoted 6 lines
Quoted 4 lines
It needs add f2fs prefix for non-static symbol to avoid global namespace pollution.
Anyway, how about this?
It looks good for me, you can make this as V3.
Well, could you please send v3 with below updates?
Thanks,
Quoted 68 lines
Quoted 68 lines
--- fs/f2fs/compress.c | 19 +++++++++++++++++++ fs/f2fs/data.c | 7 ++++--- fs/f2fs/f2fs.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-)fs/f2fs/compress.c index renamed from fs/f2fs/compress.c +0
-0
c1bf9ad4c220..15d9b89d4df0100644fs/f2fs/compress.c +19
-0@@ -881,6 +881,25 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index) return is_page_in_cluster(cc, index); } +bool f2fs_all_cluster_page_loaded (struct compress_ctx *cc,struct pagevec *pvec, +int index,int nr_pages) +{ +unsigned long pgidx; +int i; + +if (nr_pages - index < cc->cluster_size) +return false; + + pgidx = pvec->pages[index]->index; + +for (i =1 ; i < cc->cluster_size; i++) { +if (pvec->pages[index + i]->index != pgidx + i) +return false; + } + +return true; +} +static bool cluster_has_invalid_data (struct compress_ctx *cc){ loff_t i_size = i_size_read(cc->inode); diff --git a/fs/f2fs/data.c
b/fs/f2fs/data.cindex14fe5c6216cc..b0665f69c093100644fs/f2fs/data.c +4
-3@@ -3075,9 +3075,10 @@ static int f2fs_write_cache_pages(structaddress_space *mapping, done =1 ;break ; }else if (ret2 && - !f2fs_compress_write_end (inode, - fsdata, page->index, -1 )) { + (!f2fs_compress_write_end (inode, + fsdata, page->index,1 ) || + !f2fs_all_cluster_page_loaded (&cc, + &pvec, i, nr_pages))) { retry =1 ;break ;}fs/f2fs/f2fs.h index 7a32c2127945..b8da34198ce0 renamed from fs/f2fs/f2fs.h +0
-0100644
fs/f2fs/f2fs.h +1
-0@@ -4047,6 +4047,8 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed, block_t blkaddr);bool f2fs_cluster_is_empty (struct compress_ctx *cc);bool f2fs_cluster_can_merge_page (struct compress_ctx *cc,pgoff_t index); +bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
Quoted 9 lines
Quoted 8 lines
fs/f2fs/f2fs.h +1
-0+ int index, int nr_pages);bool f2fs_sanity_check_cluster (struct dnode_of_data *dn);void f2fs_compress_ctx_add_page(struct
compress_ctx*cc, struct page
*page);
int f2fs_write_multi_pages(structcompress_ctx*cc,
--
2.32.0
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel