erofs-utils: add a compress limit to source input stream
PATCH 1/1 erofs-utils: add a compress limit to source input stream
It cause a differential amplification when create binary diff image for upgrade. Give a limits to cut compress, so the amplification will be limit in the given size.
Signed-off-by Li Guifu <[email protected]>
--- include/erofs/internal.h | 1 + lib/compress.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-)
include/erofs/internal.h +1 -0
@@ -41,6 +41,7 @@ typedef unsigned short umode_t;#define EROFS_ISLOTBITS 5#define EROFS_SLOTSIZE (1U << EROFS_ISLOTBITS) +#define EROFS_COMPR_LIMITS (1024U * EROFS_BLKSIZ)typedef u64 erofs_off_t ;typedef u64 erofs_nid_t ;
lib/compress.c +12 -3
@@ -150,7 +150,7 @@ static int vle_compress_one(struct erofs_inode *inode, {struct erofs_compress *const h = &compresshandle;unsigned int len = ctx->tail - ctx->head; -unsigned int count; +unsigned int count =0 ;int ret;static char dstbuf[EROFS_BLKSIZ *2 ];char *const dst = dstbuf +EROFS_BLKSIZ ;
@@ -159,7 +159,7 @@ static int vle_compress_one(struct erofs_inode *inode,bool raw;if (len <=EROFS_BLKSIZ ) { -if (final) +if (!count || final) goto nocompression;break ; }
@@ -392,7 +392,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode) {struct erofs_buffer_head *bh;struct z_erofs_vle_compress_ctx ctx; -erofs_off_t remaining; +erofs_off_t remaining, comprlimits;erofs_blk_t blkaddr, compressed_blocks;unsigned int legacymetasize;int ret, fd;
@@ -422,6 +422,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode) ctx.head = ctx.tail =0 ; ctx.clusterofs =0 ; remaining = inode->i_size; + comprlimits =EROFS_COMPR_LIMITS ;while (remaining) { const u64 readcount = min_t(u64, remaining,
@@ -434,11 +435,19 @@ int erofs_write_compressed_file(struct erofs_inode *inode) } remaining -= readcount; ctx.tail += readcount; + comprlimits -= readcount; +compr_continue:/* do one compress round */ ret =vle_compress_one (inode, &ctx, false);if (ret) goto err_bdrop; +if (!comprlimits) { +if (ctx.head != ctx.tail) + goto compr_continue; + ctx.clusterofs =0 ; + comprlimits =EROFS_COMPR_LIMITS ; + } }/* do the final round */
Signature · 1 line
2.17.1