f2fs: compress: avoid duplicate counting of valid blocks when read compressed file
PATCH v4 1/1 f2fs: compress: avoid duplicate counting of valid blocks when read compressed file
Since cluster is basic unit of compression, one cluster is compressed or not, so we can calculate valid blocks only for first page in cluster, the other pages just skip.
--- fs/f2fs/data.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
fs/f2fs/data.c +19 -5
@@ -2299,6 +2299,7 @@ static int f2fs_mpage_readpages(struct inode *inode, .nr_rpages = 0, .nr_cpages = 0, }; +pgoff_t nc_cluster_idx =NULL_CLUSTER ;#endif unsigned nr_pages = rac ?readahead_count (rac) :1 ;unsigned max_nr_pages = nr_pages;
@@ -2328,15 +2329,27 @@ static int f2fs_mpage_readpages(struct inode *inode, &last_block_in_bio, rac != NULL, false);f2fs_destroy_compress_ctx (&cc, false); + nc_cluster_idx =NULL_CLUSTER ;if (ret) goto set_error_page; } - ret =f2fs_is_compressed_cluster (inode, page->index); -if (ret <0 ) - goto set_error_page; -else if (!ret) - goto read_single_page; +if (cc.cluster_idx ==NULL_CLUSTER ) { +if (nc_cluster_idx == + page->index >> cc.log_cluster_size) { + goto read_single_page; + } + + ret =f2fs_is_compressed_cluster (inode, page->index); +if (ret <0 ) + goto set_error_page; +else if (!ret) { + nc_cluster_idx = + page->index >> cc.log_cluster_size; + goto read_single_page; + } + nc_cluster_idx =NULL_CLUSTER ; + } ret =f2fs_init_compress_ctx (&cc);if (ret) goto set_error_page;
@@ -2373,6 +2386,7 @@ static int f2fs_mpage_readpages(struct inode *inode, &last_block_in_bio, rac != NULL, false);f2fs_destroy_compress_ctx (&cc, false); + nc_cluster_idx = NULL_CLUSTER; } }#endif
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 22 lines · Fengnan Chang
Since cluster is basic unit of compression, one cluster is compressed or not, so we can calculate valid blocks only for first page in cluster, the other pages just skip.
Signed-off-by Fengnan Chang <[email protected]>--- fs/f2fs/data.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)fs/f2fs/data.c +1
-0@@ -2299,6 +2299,7 @@ static int f2fs_mpage_readpages(struct inode *inode, .nr_rpages = 0, .nr_cpages = 0, }; +pgoff_t nc_cluster_idx =NULL_CLUSTER ;#endif unsigned nr_pages = rac ?readahead_count (rac) :1 ;unsigned max_nr_pages = nr_pages;
fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2332
Quoted 4 lines
fs/f2fs/data.c +1
-0@@ -2328,15 +2329,27 @@ static int f2fs_mpage_readpages(struct inode *inode, &last_block_in_bio, rac != NULL, false);f2fs_destroy_compress_ctx (&cc, false); + nc_cluster_idx =NULL_CLUSTER ;
Can we get rid of this?
Quoted 29 lines
fs/f2fs/data.c +16
-5if (ret) goto set_error_page; } - ret =f2fs_is_compressed_cluster (inode, page->index); -if (ret <0 ) - goto set_error_page; -else if (!ret) - goto read_single_page; +if (cc.cluster_idx ==NULL_CLUSTER ) { +if (nc_cluster_idx == + page->index >> cc.log_cluster_size) { + goto read_single_page; + } + + ret =f2fs_is_compressed_cluster (inode, page->index); +if (ret <0 ) + goto set_error_page; +else if (!ret) { + nc_cluster_idx = + page->index >> cc.log_cluster_size; + goto read_single_page; + } + nc_cluster_idx =NULL_CLUSTER ; + } ret =f2fs_init_compress_ctx (&cc);if (ret) goto set_error_page;
fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2389
Quoted 4 lines
fs/f2fs/data.c +1
-0@@ -2373,6 +2386,7 @@ static int f2fs_mpage_readpages(struct inode *inode, &last_block_in_bio, rac != NULL, false);f2fs_destroy_compress_ctx (&cc, false); + nc_cluster_idx =NULL_CLUSTER ;
Ditto,
Thanks,
fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2392
Quoted 4 lines
fs/f2fs/data.c +0
-0} }#endif
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel