Skip to contentSkip to conversation

erofs-utils: ignore comments and blank lines in compress hints

PATCH Superseded Gao Xiang 1 participant 2 messages Feb 22, 2023 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: ignore comments and blank lines in compress hints

Identify lines starting with '#' as a comment.

---
 lib/compress_hints.c | 3 +++
 1 file changed, 3 insertions(+)
lib/compress_hints.c +3 -0
index 92964eb..3e5c8c8 100644
@@ -101,6 +101,9 @@ int erofs_load_compress_hints(void)
 		unsigned int pclustersize;
 		char *pattern;
 
+		if (*buf == '#' || *buf == '\n')
+			continue;
+
 		pclustersize = atoi(strtok(buf, "\t "));
 		pattern = strtok(NULL, "\n");
 		if (!pattern || *pattern == '\0') {
Signature · 1 line
2.36.1
author
#1 lore raw

PATCH 2/2 erofs-utils: support multiple algorithms in an image

Some binaries in an image may be just for archival purposes only so that the runtime performance is not the top priority at all.

Therefore, it'd better to use another algorithm with higher compression ratios and (even) pack the whole file into the packed inode entirely (will enable this way later.)

In order to use alternative algorithms, just specify two or more compressing configurations together seperated by ':' like below:
-zlzma:lz4hc,12:lzma,9 -C 32768

Although mkfs still choose the first one by default, you could try to write a compress-hints file like below:
4096 1 .*\.so$
32768 2 .*\.txt$
4096 sbin/.*$
16384 0 .*

So that ".so" files will use "lz4hc,1" compression with 4k pclusters ".txt" files will use "lzma,9" compression with 32k pclusters, files in "/sbin" will use the default "lzma" compression with 4k plusters and other files will use "lzma" compression with 16k pclusters.

Note that the largest pcluster size should be specified with "-C" option, otherwise all larger pclusters will be limited.

---
 include/erofs/compress_hints.h |  1 +
 include/erofs/config.h         |  6 ++-
 lib/compress.c                 | 81 ++++++++++++++++++++--------------
 lib/compress_hints.c           | 57 ++++++++++++++++--------
 lib/config.c                   |  1 -
 lib/inode.c                    |  2 +-
 mkfs/main.c                    | 43 +++++++++++++-----
 7 files changed, 124 insertions(+), 67 deletions(-)
include/erofs/compress_hints.h +1 -0
index 659c5b6..d836f22 100644
@@ -20,6 +20,7 @@ struct erofs_compress_hints {
 
 	regex_t reg;
 	unsigned int physical_clusterblks;
+	unsigned char algorithmtype;
 };
 
 bool z_erofs_apply_compress_hints(struct erofs_inode *inode);
include/erofs/config.h +4 -2
index a93ab25..17db98c 100644
@@ -32,6 +32,8 @@ enum {
 	TIMESTAMP_CLAMPING,
 };
 
+#define EROFS_MAX_COMPR_CFG		64
+
 struct erofs_configure {
 	const char *c_version;
 	int c_dbg_lvl;
@@ -57,8 +59,8 @@ struct erofs_configure {
 	char *c_src_path;
 	char *c_blobdev_path;
 	char *c_compress_hints_file;
-	char *c_compr_alg_master;
-	int c_compr_level_master;
+	char *c_compr_alg[EROFS_MAX_COMPR_CFG];
+	int c_compr_level[EROFS_MAX_COMPR_CFG];
 	char c_force_inodeversion;
 	char c_force_chunkformat;
 	/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
lib/compress.c +48 -33

149 lines not on this page · raw message

lib/compress_hints.c +39 -18

123 lines not on this page · raw message

lib/config.c +0 -1
index 20200be..a3235c8 100644
@@ -25,7 +25,6 @@ void erofs_init_configure(void)
 	cfg.c_version  = PACKAGE_VERSION;
 	cfg.c_dry_run  = false;
 	cfg.c_ignore_mtime = false;
-	cfg.c_compr_level_master = -1;
 	cfg.c_force_inodeversion = 0;
 	cfg.c_inline_xattr_tolerance = 2;
 	cfg.c_unix_timestamp = -1;
lib/inode.c +1 -1
index 6fd28a2..8364451 100644
@@ -424,7 +424,7 @@ static int erofs_write_file(struct erofs_inode *inode)
 		return erofs_blob_write_chunked_file(inode);
 	}
 
-	if (cfg.c_compr_alg_master && erofs_file_is_compressible(inode)) {
+	if (cfg.c_compr_alg[0] && erofs_file_is_compressible(inode)) {
 		fd = open(inode->i_srcpath, O_RDONLY | O_BINARY);
 		if (fd < 0)
 			return -errno;
mkfs/main.c +31 -12

63 lines not on this page · raw message

Signature · 1 line
2.36.1