f2fs: compress: avoid duplicate counting of valid blocks when read compressed file
PATCH v2 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/compress.c | 1 + fs/f2fs/data.c | 21 ++++++++++++++++----- fs/f2fs/f2fs.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
@@ -152,6 +152,7 @@ void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse) cc->rpages =NULL ; cc->nr_rpages =0 ; cc->nr_cpages =0 ; + cc->nc_cluster_idx =NULL_CLUSTER ;if (!reuse) cc->cluster_idx =NULL_CLUSTER ; }
fs/f2fs/data.c +16 -5
@@ -2294,6 +2294,7 @@ static int f2fs_mpage_readpages(struct inode *inode, .log_cluster_size = F2FS_I(inode)->i_log_cluster_size, .cluster_size = F2FS_I(inode)->i_cluster_size, .cluster_idx = NULL_CLUSTER, + .nc_cluster_idx = NULL_CLUSTER, .rpages = NULL, .cpages = NULL, .nr_rpages = 0,
@@ -2331,12 +2332,22 @@ static int f2fs_mpage_readpages(struct inode *inode,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 (cc.nc_cluster_idx !=NULL_CLUSTER && + cc.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) { + cc.nc_cluster_idx = page->index >> cc.log_cluster_size; + goto read_single_page; + } + cc.nc_cluster_idx =NULL_CLUSTER ; + } ret =f2fs_init_compress_ctx (&cc);if (ret) goto set_error_page;
fs/f2fs/f2fs.h +1 -0
@@ -1471,6 +1471,7 @@ struct compress_data {struct compress_ctx {struct inode *inode;/* inode the context belong to */ pgoff_t cluster_idx;/* cluster index number */ +pgoff_t nc_cluster_idx;/* cluster index number for non-compressed cluster use*/ unsigned int cluster_size;/* page count in cluster */ unsigned int log_cluster_size;/* log of cluster size */ struct page **rpages;/* pages store raw data in cluster */
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 28 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/compress.c | 1 + fs/f2fs/data.c | 21 ++++++++++++++++----- fs/f2fs/f2fs.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-)fs/f2fs/compress.c +1
-0@@ -152,6 +152,7 @@ void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse) cc->rpages =NULL ; cc->nr_rpages =0 ; cc->nr_cpages =0 ; + cc->nc_cluster_idx =NULL_CLUSTER ;if (!reuse) cc->cluster_idx =NULL_CLUSTER ; }fs/f2fs/data.c +0
-0
fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2300
Quoted 7 lines
fs/f2fs/data.c +1
-0@@ -2294,6 +2294,7 @@ static int f2fs_mpage_readpages(struct inode *inode, .log_cluster_size = F2FS_I(inode)->i_log_cluster_size, .cluster_size = F2FS_I(inode)->i_cluster_size, .cluster_idx = NULL_CLUSTER, + .nc_cluster_idx = NULL_CLUSTER, .rpages = NULL, .cpages = NULL, .nr_rpages = 0,
pgoff_t nc_cluster_idx = NULL_CLUSTER;
fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2337
Quoted 12 lines
fs/f2fs/data.c +3
-5@@ -2331,12 +2332,22 @@ static int f2fs_mpage_readpages(struct inode *inode,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 (cc.nc_cluster_idx !=NULL_CLUSTER && + cc.nc_cluster_idx == page->index >> cc.log_cluster_size) {
if (nc_cluster_idx == page->index >> cc.log_cluster_size)
fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2345
Quoted 8 lines
fs/f2fs/data.c +8
-0+ goto read_single_page; + } + + ret =f2fs_is_compressed_cluster (inode, page->index); +if (ret <0 ) + goto set_error_page; +else if (!ret) { + cc.nc_cluster_idx = page->index >> cc.log_cluster_size;
nc_cluster_idx = page->index >> cc.log_cluster_size;
Quoted 13 lines
fs/f2fs/data.c +4
-0+ goto read_single_page; + } + cc.nc_cluster_idx =NULL_CLUSTER ; + } ret =f2fs_init_compress_ctx (&cc);if (ret) goto set_error_page;fs/f2fs/f2fs.h +0
-0
fs/f2fs/f2fs.h struct compress_data { · line 1474
Quoted 4 lines
fs/f2fs/f2fs.h +1
-0@@ -1471,6 +1471,7 @@ struct compress_data {struct compress_ctx {struct inode *inode;/* inode the context belong to */ pgoff_t cluster_idx;/* cluster index number */ +pgoff_t nc_cluster_idx;/* cluster index number for non-compressed cluster use*/
We only use this field in read flow, please add a local variable to record last cluster index number of non-compressed cluster.
Thanks,
fs/f2fs/f2fs.h struct compress_data { · line 1477
Quoted 4 lines
fs/f2fs/f2fs.h +0
-0unsigned int cluster_size;/* page count in cluster */ unsigned int log_cluster_size;/* log of cluster size */ struct page **rpages;/* pages store raw data in cluster */
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel