On 2021/8/11 10:50, Chao Yu wrote:
On 2021/8/11 10:32, Fengnan Chang wrote:


On 2021/8/11 10:29, Chao Yu wrote:
On 2021/8/11 10:17, Fengnan Chang wrote:


On 2021/8/11 10:07, Chao Yu wrote:
On 2021/8/10 11:39, Fengnan Chang wrote:
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     | 19 ++++++++++++++-----
    fs/f2fs/f2fs.h     |  1 +
    3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 7dbfd6965b97..71768f15752a 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -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;
    }
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index df5e8d8c654e..bc5c0d94a6fa 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -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,20 @@ 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)

Once cc.nc_cluster_idx was set, this condition will always force to
reading
single page? due to "cc.nc_cluster_idx = NULL_CLUSTER;" will never be
called.
Yes, cc.nc_cluster_idx only will be set for not first page of
non-compress cluster, and cc.nc_cluster_idx = NULL_CLUSTER; will be
called for compressed cluster.

I mean cc.nc_cluster_idx = NULL_CLUSTER will never be called once
cc.nc_cluster_idx was set?

When change to other cluster, will call f2fs_destroy_compress_ctx(),
cc.nc_cluster_idx = NULL_CLUSTER will be set again.

However, f2fs_destroy_compress_ctx() won't be called after non-compressed
cluster read, e.g.:

1. read non-compressed cluster
2. read compressed cluster
    f2fs_destroy_compress_ctx()

So cc.nc_cluster_idx won't be reset in between step 1 and 2.

Yes, you are right, it's my fault, when test forgot to drop cache.
maybe we should correct

if (cc.nc_cluster_idx != NULL_CLUSTER)
         goto read_single_page;
to:
if (cc.nc_cluster_idx != NULL_CLUSTER && cc.nc_cluster_idx == page->index >> cc.log_cluster_size)
         goto read_single_page;
Thanks,


Thanks.


Thanks,


Thanks,

+                    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;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e97b4d8c5efc..e9b6890a3f19 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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 */






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

Reply via email to