[RFC PATCH v5 3/4] erofs-utils: lib: support interlaced uncompressed data layout when compressing

Yue Hu zbestahu at gmail.com
Sun Aug 28 23:51:08 AEST 2022


From: Yue Hu <huyue2 at coolpad.com>

This can benefit from in-place I/O we are using.

Signed-off-by: Yue Hu <huyue2 at coolpad.com>
---
 lib/compress.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/lib/compress.c b/lib/compress.c
index fd02053..3f02fee 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -139,11 +139,12 @@ static void vle_write_indexes(struct z_erofs_vle_compress_ctx *ctx,
 	ctx->clusterofs = clusterofs + count;
 }
 
-static int write_uncompressed_extent(struct z_erofs_vle_compress_ctx *ctx,
+static int write_uncompressed_extent(struct erofs_inode *inode,
+				     struct z_erofs_vle_compress_ctx *ctx,
 				     unsigned int *len, char *dst)
 {
 	int ret;
-	unsigned int count;
+	unsigned int count, interlaced_offset, rcopied, rzeroed;
 
 	/* reset clusterofs to 0 if permitted */
 	if (!erofs_sb_has_lz4_0padding() && ctx->clusterofs &&
@@ -153,11 +154,26 @@ static int write_uncompressed_extent(struct z_erofs_vle_compress_ctx *ctx,
 		ctx->clusterofs = 0;
 	}
 
-	/* write uncompressed data */
+	/*
+	 * write uncompressed data from clusterofs which can benefit from
+	 * in-place I/O, loop shift right when to exceed EROFS_BLKSIZ.
+	 */
 	count = min(EROFS_BLKSIZ, *len);
 
-	memcpy(dst, ctx->queue + ctx->head, count);
-	memset(dst + count, 0, EROFS_BLKSIZ - count);
+	if (0) { /* ENABLEME */
+		interlaced_offset = ctx->clusterofs;
+		inode->z_advise |= Z_EROFS_ADVISE_INTERLACED_PCLUSTER;
+	} else {
+		interlaced_offset = 0;
+	}
+	rcopied = min(EROFS_BLKSIZ - interlaced_offset, count);
+	rzeroed = EROFS_BLKSIZ - interlaced_offset - rcopied;
+
+	memcpy(dst + interlaced_offset, ctx->queue + ctx->head, rcopied);
+	memcpy(dst, ctx->queue + ctx->head + rcopied, count - rcopied);
+
+	memset(dst + interlaced_offset + rcopied, 0, rzeroed);
+	memset(dst + count - rcopied, 0, EROFS_BLKSIZ - count - rzeroed);
 
 	erofs_dbg("Writing %u uncompressed data to block %u",
 		  count, ctx->blkaddr);
@@ -263,7 +279,8 @@ static int vle_compress_one(struct erofs_inode *inode,
 						len, true);
 			else
 nocompression:
-				ret = write_uncompressed_extent(ctx, &len, dst);
+				ret = write_uncompressed_extent(inode, ctx,
+								&len, dst);
 
 			if (ret < 0)
 				return ret;
-- 
2.17.1



More information about the Linux-erofs mailing list