Skip to contentSkip to conversation

erofs: remove unneeded icur field from struct z_erofs_decompress_frontend

PATCH In review Yue Hu 2 participants 6 messages Apr 17, 2023 EROFS file system

lore
Share & tools
lore

Yue Hu

author reviewer
#0 lore raw

PATCH 1/1 erofs: remove unneeded icur field from struct z_erofs_decompress_frontend

From: Yue Hu <[email protected]>

The icur field is only used in z_erofs_try_inplace_io(). Let's just use a local variable instead. And no need to check if the pcluster is inline when setting icur since inline page cannot be used for inplace I/O.

---
 fs/erofs/zdata.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
fs/erofs/zdata.c +5 -8
index f759152feffa..f8bf2b227942 100644
@@ -554,9 +554,6 @@ struct z_erofs_decompress_frontend {
 	/* used for applying cache strategy on the fly */
 	bool backmost;
 	erofs_off_t headoffset;
-
-	/* a pointer used to pick up inplace I/O pages */
-	unsigned int icur;
 };
 
 #define DECOMPRESS_FRONTEND_INIT(__i) { \
@@ -707,11 +704,13 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe,
 				   struct z_erofs_bvec *bvec)
 {
 	struct z_erofs_pcluster *const pcl = fe->pcl;
+	/* file-backed online pages are traversed in reverse order */
+	unsigned int icur = pcl->pclusterpages;
 
-	while (fe->icur > 0) {
-		if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page,
+	while (icur > 0) {
+		if (!cmpxchg(&pcl->compressed_bvecs[--icur].page,
 			     NULL, bvec->page)) {
-			pcl->compressed_bvecs[fe->icur] = *bvec;
+			pcl->compressed_bvecs[icur] = *bvec;
 			return true;
 		}
 	}
@@ -877,8 +876,6 @@ static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
 	}
 	z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
 				Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
-	/* since file-backed online pages are traversed in reverse order */
-	fe->icur = z_erofs_pclusterpages(fe->pcl);
 	return 0;
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 7 lines · Yue Hu

From: Yue Hu <[email protected]>

The icur field is only used in z_erofs_try_inplace_io(). Let's just use a local variable instead. And no need to check if the pcluster is inline when setting icur since inline page cannot be used for inplace I/O.

Nope, it's a behavior change.
Other users could feed more inplace I/O pages before I/O submission to reduce memory consumption, it's common when applying stress model in low memory scenarios.

Thanks,
Gao Xiang

Quoted 44 lines
---
  fs/erofs/zdata.c | 13 +++++--------
  1 file changed, 5 insertions(+), 8 deletions(-)
fs/erofs/zdata.c +5 -8
index f759152feffa..f8bf2b227942 100644
@@ -554,9 +554,6 @@ struct z_erofs_decompress_frontend {
  	/* used for applying cache strategy on the fly */
  	bool backmost;
  	erofs_off_t headoffset;
-
-	/* a pointer used to pick up inplace I/O pages */
-	unsigned int icur;
  };
 
  #define DECOMPRESS_FRONTEND_INIT(__i) { \
@@ -707,11 +704,13 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe,
  				   struct z_erofs_bvec *bvec)
  {
  	struct z_erofs_pcluster *const pcl = fe->pcl;
+	/* file-backed online pages are traversed in reverse order */
+	unsigned int icur = pcl->pclusterpages;
 
-	while (fe->icur > 0) {
-		if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page,
+	while (icur > 0) {
+		if (!cmpxchg(&pcl->compressed_bvecs[--icur].page,
  			     NULL, bvec->page)) {
-			pcl->compressed_bvecs[fe->icur] = *bvec;
+			pcl->compressed_bvecs[icur] = *bvec;
  			return true;
  		}
  	}
@@ -877,8 +876,6 @@ static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
  	}
  	z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
  				Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
-	/* since file-backed online pages are traversed in reverse order */
-	fe->icur = z_erofs_pclusterpages(fe->pcl);
  	return 0;
  }
 
Reviewed-by
#2 lore raw
Quoted 8 lines · Gao Xiang
Quoted 5 lines · Yue Hu

From: Yue Hu <[email protected]>

The icur field is only used in z_erofs_try_inplace_io(). Let's just use a local variable instead. And no need to check if the pcluster is inline when setting icur since inline page cannot be used for inplace I/O.

Where do we check if the pcluster is inline?

Quoted 7 lines
Quoted 2 lines

Nope, it's a behavior change.
Other users could feed more inplace I/O pages before I/O submission to reduce memory consumption, it's common when applying stress model in low memory scenarios.

Oh, I misread it. I think it can be done in this way although each following users will now rescan the whole array all the time.

Quoted 18 lines

Thanks,
Gao Xiang

Quoted 14 lines

---
  fs/erofs/zdata.c | 13 +++++--------

  1 file changed, 5 insertions(+), 8 deletions(-)
fs/erofs/zdata.c +0 -2
index f759152feffa..f8bf2b227942 100644
@@ -554,9 +554,6 @@ struct z_erofs_decompress_frontend {
       /* used for applying cache strategy on the fly */
       bool backmost;
       erofs_off_t headoffset;
-
-    /* a pointer used to pick up inplace I/O pages */
Quoted 8 lines

fs/erofs/zdata.c static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, · line 707

Quoted 8 lines
fs/erofs/zdata.c +1 -1
-    unsigned int icur;
   };
   #define DECOMPRESS_FRONTEND_INIT(__i) { \
@@ -707,11 +704,13 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe,
                      struct z_erofs_bvec *bvec)
   {
       struct z_erofs_pcluster *const pcl = fe->pcl;
+    /* file-backed online pages are traversed in reverse order */

Although please help refine the comment below:

	/* scan & fill inplace I/O pages in the reverse order */

Thanks,
Gao Xiang

Quoted 19 lines
Quoted 19 lines
fs/erofs/zdata.c +4 -5
+    unsigned int icur = pcl->pclusterpages;
-    while (fe->icur > 0) {
-        if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page,
+    while (icur > 0) {
+        if (!cmpxchg(&pcl->compressed_bvecs[--icur].page,
                    NULL, bvec->page)) {
-            pcl->compressed_bvecs[fe->icur] = *bvec;
+            pcl->compressed_bvecs[icur] = *bvec;
               return true;
           }
       }
@@ -877,8 +876,6 @@ static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
       }
       z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
                   Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
-    /* since file-backed online pages are traversed in reverse order */
-    fe->icur = z_erofs_pclusterpages(fe->pcl);
       return 0;
   }
author reviewer
#3 lore raw
Quoted 11 lines · On Mon, 17 Apr 2023 15:00:25 +0800 Gao Xiang <[email protected]>…
Quoted 8 lines · Gao Xiang
Quoted 5 lines · Yue Hu

From: Yue Hu <[email protected]>

The icur field is only used in z_erofs_try_inplace_io(). Let's just use a local variable instead. And no need to check if the pcluster is inline when setting icur since inline page cannot be used for inplace I/O.

Where do we check if the pcluster is inline?

       /* since file-backed online pages are traversed in reverse order */
       fe->icur = z_erofs_pclusterpages(fe->pcl);

static inline unsigned int z_erofs_pclusterpages(struct z_erofs_pcluster *pcl)

{
        if (z_erofs_is_inline_pcluster(pcl))
                return 1;
	[...]
Quoted 43 lines
Quoted 8 lines
Quoted 3 lines

Nope, it's a behavior change.
Other users could feed more inplace I/O pages before I/O submission to reduce memory consumption, it's common when applying stress model in low memory scenarios.

Oh, I misread it. I think it can be done in this way although each following users will now rescan the whole array all the time.

Quoted 18 lines

Thanks,
Gao Xiang

Quoted 14 lines

---
  fs/erofs/zdata.c | 13 +++++--------

  1 file changed, 5 insertions(+), 8 deletions(-)
fs/erofs/zdata.c +0 -2
index f759152feffa..f8bf2b227942 100644
@@ -554,9 +554,6 @@ struct z_erofs_decompress_frontend {
       /* used for applying cache strategy on the fly */
       bool backmost;
       erofs_off_t headoffset;
-
-    /* a pointer used to pick up inplace I/O pages */
Quoted 8 lines

fs/erofs/zdata.c static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, · line 707

Quoted 8 lines
fs/erofs/zdata.c +1 -1
-    unsigned int icur;
   };
   #define DECOMPRESS_FRONTEND_INIT(__i) { \
@@ -707,11 +704,13 @@ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe,
                      struct z_erofs_bvec *bvec)
   {
       struct z_erofs_pcluster *const pcl = fe->pcl;
+    /* file-backed online pages are traversed in reverse order */  

Although please help refine the comment below:

Quoted 1 line
	/* scan & fill inplace I/O pages in the reverse order */

Ok, will refine it in v2.

Quoted 23 lines

Thanks,
Gao Xiang

Quoted 19 lines
Quoted 19 lines
fs/erofs/zdata.c +4 -5
+    unsigned int icur = pcl->pclusterpages;
-    while (fe->icur > 0) {
-        if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page,
+    while (icur > 0) {
+        if (!cmpxchg(&pcl->compressed_bvecs[--icur].page,
                    NULL, bvec->page)) {
-            pcl->compressed_bvecs[fe->icur] = *bvec;
+            pcl->compressed_bvecs[icur] = *bvec;
               return true;
           }
       }
@@ -877,8 +876,6 @@ static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
       }
       z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
                   Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
-    /* since file-backed online pages are traversed in reverse order */
-    fe->icur = z_erofs_pclusterpages(fe->pcl);
       return 0;
   }  
#4 lore raw
Quoted 3 lines · Yue Hu

On Mon, 17 Apr 2023 15:00:25 +0800
Gao Xiang <[email protected]> wrote:

..

Quoted 6 lines
Quoted 4 lines

Although please help refine the comment below:

	/* scan & fill inplace I/O pages in the reverse order */

Ok, will refine it in v2.

I rethink this, I don't want to go far in this way, and this makes a O(n) scan into O(n^2) when a single inplace I/O page is added.

So sorry, I don't think it's a good way, although I also don't think icur is a good name and we might need to find a better name.

Thanks,
Gao Xiang

Quoted 24 lines
Quoted 24 lines

Thanks,
Gao Xiang

Quoted 19 lines
Quoted 19 lines

+    unsigned int icur = pcl->pclusterpages;
-    while (fe->icur > 0) {
-        if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page, +    while (icur > 0) {
+        if (!cmpxchg(&pcl->compressed_bvecs[--icur].page,
                   NULL, bvec->page)) {
-            pcl->compressed_bvecs[fe->icur] = *bvec; +            pcl->compressed_bvecs[icur] = *bvec;
              return true;
          }
      }

fs/erofs/zdata.c +0 -2
@@ -877,8 +876,6 @@ static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
       }
       z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
                   Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
-    /* since file-backed online pages are traversed in reverse order */
-    fe->icur = z_erofs_pclusterpages(fe->pcl);
       return 0;
   }
author reviewer
#5 lore raw
Quoted 8 lines · On Mon, 17 Apr 2023 15:12:31 +0800 Gao Xiang <[email protected]>…
Quoted 3 lines · Yue Hu

On Mon, 17 Apr 2023 15:00:25 +0800
Gao Xiang <[email protected]> wrote:

..

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Although please help refine the comment below:

	/* scan & fill inplace I/O pages in the reverse order */  

Ok, will refine it in v2.

I rethink this, I don't want to go far in this way, and this makes a O(n) scan into O(n^2) when a single inplace I/O page is added.

Yeah, i misread that, it should be global before submission, just ignore the change.

Quoted 31 lines

So sorry, I don't think it's a good way, although I also don't think icur is a good name and we might need to find a better name.

Thanks,
Gao Xiang

Quoted 24 lines
Quoted 24 lines

Thanks,
Gao Xiang

Quoted 19 lines
Quoted 19 lines

+    unsigned int icur = pcl->pclusterpages;
-    while (fe->icur > 0) {
-        if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page, +    while (icur > 0) {
+        if (!cmpxchg(&pcl->compressed_bvecs[--icur].page,
                   NULL, bvec->page)) {
-            pcl->compressed_bvecs[fe->icur] = *bvec; +            pcl->compressed_bvecs[icur] = *bvec;
              return true;
          }
      }

fs/erofs/zdata.c +0 -2
@@ -877,8 +876,6 @@ static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe)
       }
       z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset,
                   Z_EROFS_INLINE_BVECS, fe->pcl->vcnt);
-    /* since file-backed online pages are traversed in reverse order */
-    fe->icur = z_erofs_pclusterpages(fe->pcl);
       return 0;
   }