erofs-utils: ignore comments and blank lines in compress hints
PATCH v2 1/3 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
@@ -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.24.4
PATCH v2 2/3 erofs-utils: support multiple algorithms in a single 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 separated by ':' like below:
-zlzma:lz4hc,12:lzma,9 -C32768
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,12" compression with 4k pclusters, ".txt" files will use "lzma,9" compression with 32k pclusters, files under "/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 the "-C" option, otherwise all larger pclusters will be limited.
---
changes since v1:
- move enable field into the next patch;
- refine commit message.
include/erofs/compress_hints.h | 1 + include/erofs/config.h | 6 ++- lib/compress.c | 80 ++++++++++++++++++++-------------- lib/compress_hints.c | 57 ++++++++++++++++-------- lib/config.c | 1 - lib/inode.c | 2 +- mkfs/main.c | 43 +++++++++++++----- 7 files changed, 123 insertions(+), 67 deletions(-)
include/erofs/compress_hints.h +1 -0
@@ -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
@@ -32,6 +32,8 @@ enum { TIMESTAMP_CLAMPING, }; +#define EROFS_MAX_COMPR_CFGS 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_CFGS ]; +int c_compr_level[EROFS_MAX_COMPR_CFGS ];char c_force_inodeversion;char c_force_chunkformat;/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
lib/compress.c +47 -33
148 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
@@ -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
@@ -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.24.4
PATCH v2 3/3 erofs-utils: support randomizing algorithms in debugging mode
In reply to Gao XiangIt's used for multiple algorithms selftest.
--- include/erofs/config.h | 1 + lib/compress.c | 12 ++++++++++++ mkfs/main.c | 5 +++++ 3 files changed, 18 insertions(+)
include/erofs/config.h +1 -0
@@ -41,6 +41,7 @@ struct erofs_configure {bool c_legacy_compress;#ifndef NDEBUG bool c_random_pclusterblks; +bool c_random_algorithms;#endif char c_timeinherit;char c_chunkbits;
lib/compress.c +12 -0
@@ -25,6 +25,7 @@struct erofs_compress_cfg {struct erofs_compress handle;unsigned int algorithmtype; +bool enable; } erofs_ccfg[EROFS_MAX_COMPR_CFGS ];struct z_erofs_vle_compress_ctx {
@@ -859,6 +860,16 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)if (cfg.c_fragments && !cfg.c_dedupe) inode->z_advise |=Z_EROFS_ADVISE_INTERLACED_PCLUSTER ; +#ifndef NDEBUG +if (cfg.c_random_algorithms) { +while (1 ) { + inode->z_algorithmtype[0 ] = +rand () %EROFS_MAX_COMPR_CFGS ; +if (erofs_ccfg[inode->z_algorithmtype[0 ]].enable) +break ; + } + } +#endif ctx.ccfg = &erofs_ccfg[inode->z_algorithmtype[0 ]]; inode->z_algorithmtype[0 ] = ctx.ccfg[0 ].algorithmtype; inode->z_algorithmtype[1 ] =0 ;
@@ -1074,6 +1085,7 @@ int z_erofs_compress_init(struct erofs_buffer_head *sb_bh)if (ret <0 )return ret; erofs_ccfg[i].algorithmtype = ret; + erofs_ccfg[i].enable = true; sbi.available_compr_algs |=1 << ret;if (ret !=Z_EROFS_COMPRESSION_LZ4 )erofs_sb_set_compr_cfgs ();
mkfs/main.c +5 -0
@@ -45,6 +45,7 @@ static struct option long_options[] = { {"all-root", no_argument, NULL, 7}, #ifndef NDEBUG {"random-pclusterblks", no_argument, NULL, 8}, + {"random-algorithms", no_argument, NULL, 18}, #endif {"max-extent-bytes", required_argument, NULL, 9}, {"compress-hints", required_argument, NULL, 10},
@@ -111,6 +112,7 @@ static void usage(void) " --quiet quiet execution (do not write anything to standard output.)\n" #ifndef NDEBUG " --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n" + " --random-algorithms randomize per-file algorithms (debugging only)\n" #endif " --mount-point=X X=prefix of target fs path (default: /)\n"#ifdef WITH_ANDROID
@@ -370,6 +372,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])case 8 : cfg.c_random_pclusterblks = true;break ; +case 18 : + cfg.c_random_algorithms = true; +break ;#endif case 9 : cfg.c_max_decompressed_extent_bytes =
Signature · 1 line
2.24.4