erofs-utils: get rid of useless nr_dup
PATCH 1/3 erofs-utils: get rid of useless nr_dup
Also refine the longest detection.
--- lib/fragments.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
lib/fragments.c +9 -9
@@ -26,7 +26,7 @@struct erofs_fragment_dedupe_item {struct list_head list; -unsigned int length, nr_dup; +unsigned int length;erofs_off_t pos;u8 data[]; };
@@ -53,7 +53,7 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,struct erofs_fragment_dedupe_item *cur, *di =NULL ;struct list_head *head;u8 *data; -unsigned int length, e2; +unsigned int length, e2, deduped;int ret; head = &dupli_frags[FRAGMENT_HASH (crc)];
@@ -83,6 +83,7 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,DBG_BUGON (length <=EROFS_TOF_HASHLEN ); e2 = length -EROFS_TOF_HASHLEN ; + deduped =0 ;list_for_each_entry (cur, head, list) {unsigned int e1, mn, i =0 ;
@@ -97,22 +98,22 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,while (i < mn && cur->data[e1 - i -1 ] == data[e2 - i -1 ]) ++i; -if (i && (!di || i +EROFS_TOF_HASHLEN > di->nr_dup)) { - cur->nr_dup = i +EROFS_TOF_HASHLEN ; +if (!di || i +EROFS_TOF_HASHLEN > deduped) { + deduped = i +EROFS_TOF_HASHLEN ; di = cur;/* full match */ -if (i == mn) +if (i == e2)break ; } }if (!di) goto out; -DBG_BUGON (di->length < di->nr_dup); +DBG_BUGON (di->length < deduped); - inode->fragment_size = di->nr_dup; - inode->fragmentoff = di->pos + di->length - di->nr_dup; + inode->fragment_size = deduped; + inode->fragmentoff = di->pos + di->length - deduped;erofs_dbg ("Dedupe %u tail data at %llu" , inode->fragment_size, inode->fragmentoff |0ULL );
@@ -161,7 +162,6 @@ static int z_erofs_fragments_dedupe_insert(void *data, unsigned int len,memcpy (di->data, data, len); di->length = len; di->pos = pos; - di->nr_dup =0 ;list_add_tail (&di->list, &dupli_frags[FRAGMENT_HASH (crc)]);return 0 ;
Signature · 1 line
2.36.1
PATCH 2/3 erofs-utils: use compressed pclusters to mark fragments
The decoded lengths of uncompressed pclusters should be strictly no more than encoded lengths.
--- lib/compress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/compress.c +3 -3
@@ -95,7 +95,7 @@ static void z_erofs_write_indexes(struct z_erofs_vle_compress_ctx *ctx)* A lcluster cannot have three parts with the middle one which * is well-compressed for !ztailpacking cases. */ -DBG_BUGON (!ctx->e.raw && !cfg.c_ztailpacking); +DBG_BUGON (!ctx->e.raw && !cfg.c_ztailpacking && !cfg.c_fragments);DBG_BUGON (ctx->e.partial); type = ctx->e.raw ?Z_EROFS_VLE_CLUSTER_TYPE_PLAIN :Z_EROFS_VLE_CLUSTER_TYPE_HEAD ;
@@ -457,7 +457,7 @@ frag_packing:if (ret <0 )return ret; ctx->e.compressedblks =0 ;/* indicate a fragment */ - ctx->e.raw = true; + ctx->e.raw = false; ctx->fragemitted = true; fix_dedupedfrag = false;/* tailpcluster should be less than 1 block */
@@ -928,7 +928,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)z_erofs_write_indexes (&ctx); ctx.e.length = inode->fragment_size; ctx.e.compressedblks =0 ; - ctx.e.raw = true; + ctx.e.raw = false; ctx.e.partial = false; ctx.e.blkaddr = ctx.blkaddr; }
Signature · 1 line
2.36.1
Re: [PATCH 2/3] erofs-utils: use compressed pclusters to mark fragments
Quoted 5 lines · On Wed, 1 Mar 2023 02:54:58 +0800 Gao Xiang <[email protected]>…
The decoded lengths of uncompressed pclusters should be strictly no more than encoded lengths.
Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")Signed-off-by Gao Xiang <[email protected]>
Quoted 35 lines
--- lib/compress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)lib/compress.c +3
-3@@ -95,7 +95,7 @@ static void z_erofs_write_indexes(struct z_erofs_vle_compress_ctx *ctx)* A lcluster cannot have three parts with the middle one which * is well-compressed for !ztailpacking cases. */ -DBG_BUGON (!ctx->e.raw && !cfg.c_ztailpacking); +DBG_BUGON (!ctx->e.raw && !cfg.c_ztailpacking && !cfg.c_fragments);DBG_BUGON (ctx->e.partial); type = ctx->e.raw ?Z_EROFS_VLE_CLUSTER_TYPE_PLAIN :Z_EROFS_VLE_CLUSTER_TYPE_HEAD ;@@ -457,7 +457,7 @@ frag_packing:if (ret <0 )return ret; ctx->e.compressedblks =0 ;/* indicate a fragment */ - ctx->e.raw = true; + ctx->e.raw = false; ctx->fragemitted = true; fix_dedupedfrag = false;/* tailpcluster should be less than 1 block */ @@ -928,7 +928,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)z_erofs_write_indexes (&ctx); ctx.e.length = inode->fragment_size; ctx.e.compressedblks =0 ; - ctx.e.raw = true; + ctx.e.raw = false; ctx.e.partial = false; ctx.e.blkaddr = ctx.blkaddr; }
PATCH 3/3 erofs-utils: add `-Eall-fragments` option
In reply to Gao XiangIt's almost the same as -Efragments option, except that will explicitly pack the whole data into the special inode instead.
--- configure.ac | 1 + include/erofs/config.h | 1 + include/erofs/fragments.h | 1 + lib/compress.c | 32 ++++++++++++++++------------- lib/fragments.c | 43 ++++++++++++++++++++++++++++++++++++++- man/mkfs.erofs.1 | 25 ++++++++++++++--------- mkfs/main.c | 6 ++++++ 7 files changed, 84 insertions(+), 25 deletions(-)
configure.ac +1 -0
@@ -134,6 +134,7 @@ AC_CHECK_HEADERS(m4_flatten([ stdlib.h string.h sys/ioctl.h + sys/mman.h sys/stat.h sys/sysmacros.h sys/time.h
include/erofs/config.h +1 -0
@@ -48,6 +48,7 @@ struct erofs_configure {bool c_noinline_data;bool c_ztailpacking;bool c_fragments; +bool c_all_fragments;bool c_dedupe;bool c_ignore_mtime;bool c_showprogress;
include/erofs/fragments.h +1 -0
@@ -16,6 +16,7 @@ extern const char *frags_packedname;#define EROFS_PACKED_INODE frags_packednameint z_erofs_fragments_dedupe (struct erofs_inode *inode,int fd,u32 *tofcrc); +int z_erofs_pack_file_from_fd (struct erofs_inode *inode,int fd,u32 tofcrc);int z_erofs_pack_fragments (struct erofs_inode *inode,void *data,unsigned int len,u32 tofcrc);void z_erofs_fragments_commit (struct erofs_inode *inode);
lib/compress.c +18 -14
@@ -899,22 +899,26 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd) ctx.remaining = inode->i_size - inode->fragment_size; ctx.fix_dedupedfrag = false; ctx.fragemitted = false; +if (cfg.c_all_fragments && !erofs_is_packed_inode (inode) && + !inode->fragment_size) { + ret =z_erofs_pack_file_from_fd (inode, fd, ctx.tof_chksum); + }else { +while (ctx.remaining) { +const u64 rx =min_t (u64, ctx.remaining, +sizeof (ctx.queue) - ctx.tail); + + ret =read (fd, ctx.queue + ctx.tail, rx); +if (ret != rx) { + ret = -errno; + goto err_bdrop; + } + ctx.remaining -= rx; + ctx.tail += rx; -while (ctx.remaining) { -const u64 readcount =min_t (u64, ctx.remaining, -sizeof (ctx.queue) - ctx.tail); - - ret =read (fd, ctx.queue + ctx.tail, readcount); -if (ret != readcount) { - ret = -errno; - goto err_bdrop; + ret =vle_compress_one (&ctx); +if (ret) + goto err_free_idata; } - ctx.remaining -= readcount; - ctx.tail += readcount; - - ret =vle_compress_one (&ctx); -if (ret) - goto err_free_idata; }DBG_BUGON (ctx.head != ctx.tail);
lib/fragments.c +42 -1
61 lines not on this page · raw message
man/mkfs.erofs.1 +15 -10
@@ -42,6 +42,21 @@ and may take an extra argument using the equals ('=') sign. The following extended options are supported: .RS 1.2i .TP +.BI all-fragments +Forcely record the whole files into a special inode for better compression and +it may take an argument as the pcluster size of the packed inode in bytes. +(Linux v6.1+) +.TP +.BI dedupe +Enable global compressed data deduplication to minimize duplicated data in +the filesystem. It may be used with \fI-Efragments\fR option together to +further reduce image sizes. (Linux v6.1+) +.TP +.BI fragments +Pack the tail part (pcluster) of compressed files or the whole files into a +special inode for smaller image sizes, and it may take an argument as the +pcluster size of the packed inode in bytes. (Linux v6.1+) +.TP .BI force-inode-compact Forcely generate compact inodes (32-byte inodes) to output. .TP
@@ -64,16 +79,6 @@ Don't inline regular files to enable FSDAX for these files (Linux v5.15+). .BI ztailpacking Pack the tail part (pcluster) of compressed files into its metadata to save more space and the tail part I/O. (Linux v5.17+) -.TP -.BI fragments -Pack the tail part (pcluster) of compressed files or the whole files into a -special inode for smaller image sizes, and it may take an argument as the -pcluster size of the packed inode in bytes. (Linux v6.1+) -.TP -.BI dedupe -Enable global compressed data deduplication to minimize duplicated data in -the filesystem. It may be used with \fI-Efragments\fR option together to -further reduce image sizes. (Linux v6.1+) .RE .TP .BI "\-L " volume-label
mkfs/main.c +6 -0
@@ -208,10 +208,16 @@ static int parse_extended_opts(const char *opts) cfg.c_ztailpacking = true; } +if (MATCH_EXTENTED_OPT ("all-fragments" , token, keylen)) { + cfg.c_all_fragments = true; + goto handle_fragment; + } +if (MATCH_EXTENTED_OPT ("fragments" , token, keylen)) {char *endptr;u64 i; +handle_fragment: cfg.c_fragments = true;if (vallen) { i =strtoull (value, &endptr,0 );
Signature · 1 line
2.36.1
Re: [PATCH 3/3] erofs-utils: add `-Eall-fragments` option
Quoted 4 lines · On Wed, 1 Mar 2023 02:54:59 +0800 Gao Xiang <[email protected]>…
It's almost the same as
-Efragmentsoption, except that will explicitly pack the whole data into the special inode instead.Signed-off-by Gao Xiang <[email protected]>
Quoted 4 lines · On Wed, 1 Mar 2023 02:54:57 +0800 Gao Xiang <[email protected]>…
Also refine the longest detection.
Fixes 990c7e383795 ("erofs-utils: mkfs: support fragment deduplication")Signed-off-by Gao Xiang <[email protected]>
Quoted 71 lines
--- lib/fragments.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)lib/fragments.c +9
-9@@ -26,7 +26,7 @@struct erofs_fragment_dedupe_item {struct list_head list; -unsigned int length, nr_dup; +unsigned int length;erofs_off_t pos;u8 data[]; };@@ -53,7 +53,7 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,struct erofs_fragment_dedupe_item *cur, *di =NULL ;struct list_head *head;u8 *data; -unsigned int length, e2; +unsigned int length, e2, deduped;int ret; head = &dupli_frags[FRAGMENT_HASH (crc)];@@ -83,6 +83,7 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,DBG_BUGON (length <=EROFS_TOF_HASHLEN ); e2 = length -EROFS_TOF_HASHLEN ; + deduped =0 ;list_for_each_entry (cur, head, list) {unsigned int e1, mn, i =0 ;@@ -97,22 +98,22 @@ static int z_erofs_fragments_dedupe_find(struct erofs_inode *inode, int fd,while (i < mn && cur->data[e1 - i -1 ] == data[e2 - i -1 ]) ++i; -if (i && (!di || i +EROFS_TOF_HASHLEN > di->nr_dup)) { - cur->nr_dup = i +EROFS_TOF_HASHLEN ; +if (!di || i +EROFS_TOF_HASHLEN > deduped) { + deduped = i +EROFS_TOF_HASHLEN ; di = cur;/* full match */ -if (i == mn) +if (i == e2)break ; } }if (!di) goto out; -DBG_BUGON (di->length < di->nr_dup); +DBG_BUGON (di->length < deduped); - inode->fragment_size = di->nr_dup; - inode->fragmentoff = di->pos + di->length - di->nr_dup; + inode->fragment_size = deduped; + inode->fragmentoff = di->pos + di->length - deduped;erofs_dbg ("Dedupe %u tail data at %llu" , inode->fragment_size, inode->fragmentoff |0ULL );@@ -161,7 +162,6 @@ static int z_erofs_fragments_dedupe_insert(void *data, unsigned int len,memcpy (di->data, data, len); di->length = len; di->pos = pos; - di->nr_dup =0 ;list_add_tail (&di->list, &dupli_frags[FRAGMENT_HASH (crc)]);return 0 ;