Skip to contentSkip to conversation

erofs-utils: compression inline feature

RFC PATCH Superseded Yue Hu 1 participant 3 messages Oct 29, 2021 Library code

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Yue Hu

author
#0 lore raw

v2 cover erofs-utils: compression inline feature

Now, we only support tail-end inline data for uncompressed file. We should also support it for compressed file to further decrease tail extent I/O and save more space. That is original intention as well from Xiang.

Note that tail pcluster data is compressed by 4KB in this patch, which looks like inefficent. As Xiang mentioned, there is another better way to handle it. This patch is just using 4KB compression policy, we may improve it next.

Thanks.

Yue Hu (2):
erofs-utils: support tail-packing inline compressed data
erofs-utils: fuse: support tail-packing inline compressed data

 include/erofs/internal.h |   4 ++
 include/erofs_fs.h       |  10 ++-
 lib/compress.c           |  76 ++++++++++++++++++-----
 lib/compressor.c         |   9 +--
 lib/decompress.c         |   7 ++-
 lib/inode.c              |  40 ++++++------
 lib/zmap.c               | 130 ++++++++++++++++++++++++++++++++++++---
 mkfs/main.c              |   6 ++
 8 files changed, 228 insertions(+), 54 deletions(-)
Signature · 1 line
2.29.0
author
#1 lore raw

RFC PATCH v2 1/2 erofs-utils: support tail-packing inline compressed data

Currently, we only support tail-end inline data for uncompressed files, let's support it as well for compressed files.

The idea is from Xiang.

---
changes since v1:
- add 2 bytes to record compressed size of tail-pcluster suggested from Xiang and update related code.

 include/erofs/internal.h |  1 +
 include/erofs_fs.h       | 10 ++++--
 lib/compress.c           | 76 +++++++++++++++++++++++++++++++---------
 lib/compressor.c         |  9 ++---
 lib/decompress.c         |  4 +++
 lib/inode.c              | 40 ++++++++++-----------
 mkfs/main.c              |  6 ++++
 7 files changed, 102 insertions(+), 44 deletions(-)
include/erofs/internal.h +1 -0
index da7be56..3769c27 100644
@@ -109,6 +109,7 @@ static inline void erofs_sb_clear_##name(void) \
 EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
 EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
 EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
+EROFS_FEATURE_FUNCS(tailpacking, incompat, INCOMPAT_TAILPACKING)
 EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
 
 #define EROFS_I_EA_INITED	(1 << 0)
include/erofs_fs.h +8 -2
index 18fc182..5a363e2 100644
@@ -22,10 +22,12 @@
 #define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING	0x00000001
 #define EROFS_FEATURE_INCOMPAT_COMPR_CFGS	0x00000002
 #define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER	0x00000002
+#define EROFS_FEATURE_INCOMPAT_TAILPACKING	0x00000004
 #define EROFS_ALL_FEATURE_INCOMPAT		\
 	(EROFS_FEATURE_INCOMPAT_LZ4_0PADDING | \
 	 EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \
-	 EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER)
+	 EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER | \
+	 EROFS_FEATURE_INCOMPAT_TAILPACKING)
 
 #define EROFS_SB_EXTSLOT_SIZE	16
 
@@ -230,14 +232,18 @@ struct z_erofs_lz4_cfgs {
  *                                  (4B) + 2B + (4B) if compacted 2B is on.
  * bit 1 : HEAD1 big pcluster (0 - off; 1 - on)
  * bit 2 : HEAD2 big pcluster (0 - off; 1 - on)
+ * bit 3 : inline (un)compressed data
  */
 #define Z_EROFS_ADVISE_COMPACTED_2B		0x0001
 #define Z_EROFS_ADVISE_BIG_PCLUSTER_1		0x0002
 #define Z_EROFS_ADVISE_BIG_PCLUSTER_2		0x0004
+#define Z_EROFS_ADVISE_TAILPACKING		0x0008
 
 struct z_erofs_map_header {
-	__le32	h_reserved1;
+	__le16	h_reserved1;
 	__le16	h_advise;
+	/* record the compressed size of tail-packing pcluster */
+	__le16	h_idata_size;
 	/*
 	 * bit 0-3 : algorithm type of head 1 (logical cluster type 01);
 	 * bit 4-7 : algorithm type of head 2 (logical cluster type 11).
lib/compress.c +59 -17

166 lines not on this page · raw message

lib/compressor.c +5 -4
index 8836e0c..26189b6 100644
@@ -28,7 +28,7 @@ int erofs_compress_destsize(struct erofs_compress *c,
 			    void *dst,
 			    unsigned int dstsize)
 {
-	unsigned uncompressed_size;
+	unsigned compressed_size;
 	int ret;
 
 	DBG_BUGON(!c->alg);
@@ -41,9 +41,10 @@ int erofs_compress_destsize(struct erofs_compress *c,
 		return ret;
 
 	/* check if there is enough gains to compress */
-	uncompressed_size = *srcsize;
-	if (roundup(ret, EROFS_BLKSIZ) >= uncompressed_size *
-	    c->compress_threshold / 100)
+	compressed_size = *srcsize <= EROFS_BLKSIZ ? ret :
+			  roundup(ret, EROFS_BLKSIZ);
+
+	if (*srcsize <= compressed_size * c->compress_threshold / 100)
 		return -EAGAIN;
 	return ret;
 }
lib/decompress.c +4 -0
index 490c4bc..0b6678d 100644
@@ -9,6 +9,7 @@
 
 #include "erofs/decompress.h"
 #include "erofs/err.h"
+#include "erofs/print.h"
 
 #ifdef LZ4_ENABLED
 #include <lz4.h>
@@ -50,6 +51,9 @@ static int z_erofs_decompress_lz4(struct z_erofs_decompress_req *rq)
 					  rq->decodedlength);
 
 	if (ret != (int)rq->decodedlength) {
+		erofs_err("failed to %s decompress %d in[%u, %u] out[%u]",
+			  rq->partial_decoding ? "partial" : "full",
+			  ret, rq->inputsize, inputmargin, rq->decodedlength);
 		ret = -EIO;
 		goto out;
 	}
lib/inode.c +19 -21
index 787e5b4..6d5c9f3 100644
@@ -521,9 +521,6 @@ int erofs_prepare_tail_block(struct erofs_inode *inode)
 	struct erofs_buffer_head *bh;
 	int ret;
 
-	if (!inode->idata_size)
-		return 0;
-
 	bh = inode->bh_data;
 	if (!bh) {
 		bh = erofs_balloc(DATA, EROFS_BLKSIZ, 0, 0);
@@ -557,26 +554,21 @@ int erofs_prepare_inode_buffer(struct erofs_inode *inode)
 		inodesize = Z_EROFS_VLE_EXTENT_ALIGN(inodesize) +
 			    inode->extent_isize;
 
-	if (is_inode_layout_compression(inode))
-		goto noinline;
-
-	/*
-	 * if the file size is block-aligned for uncompressed files,
-	 * should use EROFS_INODE_FLAT_PLAIN data mapping mode.
-	 */
 	if (!inode->idata_size)
-		inode->datalayout = EROFS_INODE_FLAT_PLAIN;
+		goto noinline;
 
 	bh = erofs_balloc(INODE, inodesize, 0, inode->idata_size);
 	if (bh == ERR_PTR(-ENOSPC)) {
 		int ret;
 
-		inode->datalayout = EROFS_INODE_FLAT_PLAIN;
-noinline:
 		/* expend an extra block for tail-end data */
 		ret = erofs_prepare_tail_block(inode);
 		if (ret)
 			return ret;
+noinline:
+		if (!is_inode_layout_compression(inode))
+			inode->datalayout = EROFS_INODE_FLAT_PLAIN;
+
 		bh = erofs_balloc(INODE, inodesize, 0, 0);
 		if (IS_ERR(bh))
 			return PTR_ERR(bh);
@@ -584,7 +576,14 @@ noinline:
 	} else if (IS_ERR(bh)) {
 		return PTR_ERR(bh);
 	} else if (inode->idata_size) {
-		inode->datalayout = EROFS_INODE_FLAT_INLINE;
+		if (is_inode_layout_compression(inode)) {
+			struct z_erofs_map_header *h = inode->compressmeta;
+			h->h_advise |= Z_EROFS_ADVISE_TAILPACKING;
+			erofs_dbg("%s: inline data (%u bytes)",
+				  inode->i_srcpath, inode->idata_size);
+		} else {
+			inode->datalayout = EROFS_INODE_FLAT_INLINE;
+		}
 
 		/* allocate inline buffer */
 		ibh = erofs_battach(bh, META, inode->idata_size);
@@ -647,13 +646,12 @@ int erofs_write_tail_end(struct erofs_inode *inode)
 		ret = dev_write(inode->idata, pos, inode->idata_size);
 		if (ret)
 			return ret;
-		if (inode->idata_size < EROFS_BLKSIZ) {
-			ret = dev_fillzero(pos + inode->idata_size,
-					   EROFS_BLKSIZ - inode->idata_size,
-					   false);
-			if (ret)
-				return ret;
-		}
+		ret = dev_fillzero(pos + inode->idata_size,
+				   EROFS_BLKSIZ - inode->idata_size,
+				   false);
+		if (ret)
+			return ret;
+
 		inode->idata_size = 0;
 		free(inode->idata);
 		inode->idata = NULL;
mkfs/main.c +6 -0
index e476189..7dd29df 100644
@@ -48,6 +48,7 @@ static struct option long_options[] = {
 	{"product-out", required_argument, NULL, 11},
 	{"fs-config-file", required_argument, NULL, 12},
 #endif
+	{"inline", no_argument, NULL, 13},
 	{0, 0, 0, 0},
 };
 
@@ -87,6 +88,7 @@ static void usage(void)
 	      " --all-root            make all files owned by root\n"
 	      " --help                display this help and exit\n"
 	      " --max-extent-bytes=#  set maximum decompressed extent size # in bytes\n"
+	      " --inline              tail-packing inline compressed data\n"
 #ifndef NDEBUG
 	      " --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n"
 #endif
@@ -304,6 +306,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			}
 			cfg.c_physical_clusterblks = i / EROFS_BLKSIZ;
 			break;
+		case 13:
+			erofs_sb_set_tailpacking();
+			erofs_warn("EXPERIMENTAL compression inline feature in use. Use at your own risk!");
+			break;
 
 		case 1:
 			usage();
Signature · 1 line
2.29.0
author
#2 lore raw

RFC PATCH v2 2/2 erofs-utils: fuse: support tail-packing inline compressed data

In reply to Yue Hu

Add tail-packing inline compressed data support for erofsfuse.

---
changes since v1:
- add tail-packing information to inode and get it on first read.
- update tail-packing checking logic.

 include/erofs/internal.h |   3 +
 lib/decompress.c         |   3 -
 lib/zmap.c               | 130 ++++++++++++++++++++++++++++++++++++---
 3 files changed, 126 insertions(+), 10 deletions(-)
include/erofs/internal.h +3 -0
index 3769c27..ce9fb40 100644
@@ -165,6 +165,8 @@ struct erofs_inode {
 			uint16_t z_advise;
 			uint8_t  z_algorithmtype[2];
 			uint8_t  z_logical_clusterbits;
+			uint16_t z_idata_size;
+			uint64_t z_idata_addr;
 		};
 	};
 #ifdef WITH_ANDROID
@@ -251,6 +253,7 @@ struct erofs_map_blocks {
 
 	unsigned int m_flags;
 	erofs_blk_t index;
+	unsigned long m_taillcn;
 };
 
 /* super.c */
lib/decompress.c +0 -3
index 0b6678d..ac5d126 100644
@@ -73,9 +73,6 @@ out:
 int z_erofs_decompress(struct z_erofs_decompress_req *rq)
 {
 	if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED) {
-		if (rq->inputsize != EROFS_BLKSIZ)
-			return -EFSCORRUPTED;
-
 		DBG_BUGON(rq->decodedlength > EROFS_BLKSIZ);
 		DBG_BUGON(rq->decodedlength < rq->decodedskip);
 
lib/zmap.c +123 -7

177 lines not on this page · raw message

Signature · 1 line
2.29.0