Skip to contentSkip to conversation

f2fs: compress: avoid duplicate counting of valid blocks when read compressed file

PATCH Superseded Fengnan Chang 2 participants 7 messages Aug 10, 2021 – Aug 11, 2021 F2FS file system

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 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     | 19 ++++++++++++++-----
 fs/f2fs/f2fs.h     |  1 +
 3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +14 -5
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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)
+					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
index e97b4d8c5efc..e9b6890a3f19 100644
@@ -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
maintainer
#1 lore raw
Quoted 36 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.

---
  fs/f2fs/compress.c |  1 +
  fs/f2fs/data.c     | 19 ++++++++++++++-----
  fs/f2fs/f2fs.h     |  1 +
  3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +1 -0
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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,

fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2336

Quoted 10 lines
fs/f2fs/data.c +2 -5
@@ -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.

Thanks,

Quoted 21 lines
fs/f2fs/data.c +11 -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;
+					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
index e97b4d8c5efc..e9b6890a3f19 100644

fs/f2fs/f2fs.h struct compress_data { · line 1477

Quoted 7 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*/
  	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

#2 lore raw
Quoted 45 lines · Chao Yu
Quoted 44 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.

---
  fs/f2fs/compress.c |  1 +
  fs/f2fs/data.c     | 19 ++++++++++++++-----
  fs/f2fs/f2fs.h     |  1 +

  3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +1 -0
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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,

fs/f2fs/data.c +0 -2
@@ -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)
Quoted 8 lines

fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2336

Quoted 5 lines
fs/f2fs/data.c +2 -3
-                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.

Quoted 24 lines

Thanks,

Quoted 21 lines
fs/f2fs/data.c +11 -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;
+                    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
index e97b4d8c5efc..e9b6890a3f19 100644
@@ -1471,6 +1471,7 @@ struct compress_data {
   struct compress_ctx {
Quoted 9 lines
Quoted 8 lines

      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

maintainer
#3 lore raw
Quoted 57 lines · Fengnan Chang
Quoted 46 lines · Chao Yu
Quoted 45 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.

---
   fs/f2fs/compress.c |  1 +
   fs/f2fs/data.c     | 19 ++++++++++++++-----
   fs/f2fs/f2fs.h     |  1 +
   3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +1 -0
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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,

fs/f2fs/data.c +0 -3
@@ -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;
Quoted 8 lines

fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2336

Quoted 4 lines
fs/f2fs/data.c +2 -2
-            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.

Quoted 3 lines

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?

Thanks,

Quoted 25 lines
Quoted 25 lines

Thanks,

Quoted 22 lines
fs/f2fs/data.c +11 -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;
+                    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
index e97b4d8c5efc..e9b6890a3f19 100644
@@ -1471,6 +1471,7 @@ struct compress_data {
   struct compress_ctx {
       struct inode *inode;        /* inode the context belong to */
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/f2fs/f2fs.h +1 -0
       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

#4 lore raw
Quoted 58 lines · Chao Yu
Quoted 57 lines · Fengnan Chang
Quoted 54 lines · Chao Yu
Quoted 39 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.

---
   fs/f2fs/compress.c |  1 +
   fs/f2fs/data.c     | 19 ++++++++++++++-----
   fs/f2fs/f2fs.h     |  1 +

   3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +1 -0
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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,

fs/f2fs/data.c +0 -0
@@ -2331,12 +2332,20 @@ static int f2fs_mpage_readpages(struct inode
 *inode,

fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode · line 2337

Quoted 10 lines
fs/f2fs/data.c +2 -5
                    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.

Quoted 6 lines
Quoted 3 lines

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.

Thanks.

Quoted 37 lines

Thanks,

Quoted 33 lines
Quoted 33 lines

Thanks,

Quoted 29 lines
fs/f2fs/data.c +11 -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;
+                    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
index e97b4d8c5efc..e9b6890a3f19 100644
@@ -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

maintainer
#5 lore raw
Quoted 67 lines · Fengnan Chang
Quoted 64 lines · Chao Yu
Quoted 62 lines · Fengnan Chang
Quoted 48 lines · Chao Yu
Quoted 47 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.

---
    fs/f2fs/compress.c |  1 +
    fs/f2fs/data.c     | 19 ++++++++++++++-----
    fs/f2fs/f2fs.h     |  1 +
    3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +1 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +1 -0
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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,

fs/f2fs/data.c +0 -4
@@ -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)
Quoted 8 lines

fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2336

Quoted 3 lines
fs/f2fs/data.c +2 -1
-                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.

Quoted 5 lines
Quoted 2 lines

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.

Thanks,

Quoted 41 lines

Thanks.

Quoted 38 lines

Thanks,

Quoted 34 lines
Quoted 34 lines

Thanks,

Quoted 30 lines
fs/f2fs/data.c +11 -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;
+                    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
index e97b4d8c5efc..e9b6890a3f19 100644
@@ -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

#6 lore raw
Quoted 75 lines · Chao Yu
Quoted 68 lines · Fengnan Chang
Quoted 65 lines · Chao Yu
Quoted 63 lines · Fengnan Chang
Quoted 49 lines · Chao Yu
Quoted 48 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.

---
    fs/f2fs/compress.c |  1 +
    fs/f2fs/data.c     | 19 ++++++++++++++-----
    fs/f2fs/f2fs.h     |  1 +

    3 files changed, 16 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +0 -0
index 7dbfd6965b97..71768f15752a 100644
@@ -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 +1 -0
index df5e8d8c654e..bc5c0d94a6fa 100644
@@ -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,

fs/f2fs/data.c +0 -4
@@ -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)
Quoted 8 lines

fs/f2fs/data.c static int f2fs_mpage_readpages(struct inode *inode, · line 2336

Quoted 3 lines
fs/f2fs/data.c +2 -1
-                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.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 9 lines

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;
Quoted 45 lines

Thanks,

Quoted 42 lines

Thanks.

Quoted 39 lines

Thanks,

Quoted 35 lines
Quoted 35 lines

Thanks,

Quoted 31 lines
fs/f2fs/data.c +11 -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;
+                    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
index e97b4d8c5efc..e9b6890a3f19 100644
@@ -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