erofs-utils: determine the [un]compressed data block is inline or not early
PATCH 1/3 erofs-utils: determine the [un]compressed data block is inline or not early
Introducing erofs_get_inodesize function and erofs_get_lowest_offset function, we can determine the [un]compressed data block is inline or not before executing z_erofs_merge_segment function. It enable the following,
* skip the redundant write for ztailpacking block.
* simplify erofs_prepare_inode_buffer function. (remove handling ENOSPC error)
--- include/erofs/inode.h | 2 + lib/compress.c | 11 +++-- lib/inode.c | 112 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 116 insertions(+), 9 deletions(-)
include/erofs/inode.h +2 -0
@@ -40,6 +40,8 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,struct erofs_inode *erofs_new_inode (void );struct erofs_inode *erofs_mkfs_build_tree_from_path (const char *path);struct erofs_inode *erofs_mkfs_build_special_from_fd (int fd,const char *name); +unsigned int erofs_get_inodesize (struct erofs_inode *inode); +unsigned int erofs_get_lowest_offset (struct erofs_inode *inode); #ifdef __cplusplus }
lib/compress.c +7 -4
@@ -20,6 +20,7 @@#include "erofs/block_list.h" #include "erofs/compress_hints.h" #include "erofs/fragments.h" +#include "erofs/inode.h" #ifdef EROFS_MT_ENABLED #include "erofs/workqueue.h" #endif
@@ -530,7 +531,8 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx, e->length = len; goto frag_packing; } -if (!may_inline && len <= blksz) +if ((!may_inline && len <= blksz) || + (may_inline &&erofs_get_lowest_offset (inode) + len > blksz)) goto nocompression; }
@@ -550,7 +552,7 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,/* check if there is enough gain to keep the compressed data */ if (ret * h->compress_threshold /100 >= e->length) { -if (may_inline && len < blksz) { +if (may_inline && (erofs_get_lowest_offset (inode) + len < blksz)) { ret =z_erofs_fill_inline_data (inode, ctx->queue + ctx->head, len, true); }else {
@@ -584,7 +586,8 @@ frag_packing: e->raw = false; ictx->fragemitted = true;/* tailpcluster should be less than 1 block */ - }else if (may_inline && len == e->length && compressedsize < blksz) { + }else if (may_inline && len == e->length && + (erofs_get_lowest_offset (inode) + compressedsize < blksz)) {if (ctx->clusterofs + len <= blksz) { inode->eof_tailraw =malloc (len);if (!inode->eof_tailraw)
@@ -621,7 +624,7 @@ frag_packing: &e->length, dst, &compressedsize); e->compressedblks =BLK_ROUND_UP (sbi, compressedsize); -DBG_BUGON (e->compressedblks * blksz >= e->length); +DBG_BUGON (!may_inline && e->compressedblks * blksz >= e->length); padding =0 ; tailused = compressedsize & (blksz -1 );
lib/inode.c +107 -5
148 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH 2/3 erofs-utils: skip the redundant write for ztailpacking block
z_erofs_merge_segment() doesn't consider the ztailpacking block in the extent list and unnecessarily writes it back to the disk. This patch fixes this issue by changing compressdblks to 0.
And the value of blkaddr corresponding to the ztailpacking block in the extent list is handled in z_erofs_write_extent function.
* legacy: 0 (fragmentoff >> 32)
* compact: -1 (EROFS_NULL_ADDR)
--- lib/compress.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
lib/compress.c +6 -12
@@ -555,24 +555,19 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,if (may_inline && (erofs_get_lowest_offset (inode) + len < blksz)) { ret =z_erofs_fill_inline_data (inode, ctx->queue + ctx->head, len, true); + e->compressedblks =0 ; }else { may_inline = false; may_packing = false; nocompression:/* TODO: reset clusterofs to 0 if permitted */ ret =write_uncompressed_extent (ctx, len, dst); + e->compressedblks =1 ; }if (ret <0 )return ret; e->length = ret; - -/* -* XXX: For now, we have to leave `ctx->compressedblk = 1' -* since there is no way to generate compressed indexes after -* the time that ztailpacking is decided. -*/ - e->compressedblks =1 ; e->raw = true; } else if (may_packing && len == e->length && compressedsize < ctx->pclustersize &&
@@ -601,7 +596,7 @@ frag_packing: compressedsize, false);if (ret <0 )return ret; - e->compressedblks =1 ; + e->compressedblks =0 ; e->raw = false; }else {unsigned int tailused, padding;
@@ -1151,6 +1146,9 @@ int z_erofs_merge_segment(struct z_erofs_compress_ictx *ictx,if (ei->e.blkaddr !=EROFS_NULL_ADDR )/* deduped extents */ continue ; +if (!ei->e.compressedblks) +continue ; + ei->e.blkaddr = sctx->blkaddr; sctx->blkaddr += ei->e.compressedblks;
@@ -1358,10 +1356,6 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd, u64 fpos) compressed_blocks = sctx.blkaddr - blkaddr; } -/* fall back to no compression mode */ -DBG_BUGON (compressed_blocks < !!inode->idata_size); - compressed_blocks -= !!inode->idata_size; -/* generate an extent for the deduplicated fragment */ if (inode->fragment_size && !ctx.fragemitted) {struct z_erofs_extent_item *ei;
Signature · 1 line
2.44.0
PATCH 3/3 erofs-utils: allow blkaddr == EROFS_NULL_ADDR for zpacking in write_compacted_indexes()
In reply to Noboru AsaiWith ztailpacking, the value of blkaddr corresponding to the ztailpacking block in the extent list is EROFS_NULL_ADDR(-1), allow this value in write_compacted_indexes() function.
--- lib/compress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/compress.c +2 -1
@@ -790,7 +790,8 @@ static void *write_compacted_indexes(u8 *out, *dummy_head = true; update_blkaddr = false; -if (cv[i].u.blkaddr != blkaddr) { +if (cv[i].u.blkaddr !=EROFS_NULL_ADDR && + cv[i].u.blkaddr != blkaddr) {if (i +1 != vcnt)DBG_BUGON (!final);DBG_BUGON (cv[i].u.blkaddr);
Signature · 1 line
2.44.0
Hi Noboru,
Quoted 8 lines · Noboru Asai
Introducing
erofs_get_inodesizefunction anderofs_get_lowest_offsetfunction, we can determine the [un]compressed data block is inline or not before executingz_erofs_merge_segmentfunction. It enable the following,* skip the redundant write for ztailpacking block.
* simplifyerofs_prepare_inode_bufferfunction. (remove handling ENOSPC error)Signed-off-by Noboru Asai <[email protected]>
I appreciate and thanks for your effort and time.
Yet I tend to avoid assuming if the inline is ok or not before prepare_inode_buffer() since it will be free for space allocator to decide inline or not at that time.
So personally I still would like to write a final compressed index for inline fallback.
I will fix this issue myself later (it should be just a small patch to fix this).
Thanks for your effort on this issue again!
Thanks,
Gao Xiang
Hi Gao,
Thank you for your kind explanation. I respect your policy.
Please let me know if you change your mind,
since I will maintainance this patch personally.
2024年4月18日(木) 16:37 Gao Xiang <[email protected]>:
Quoted 30 lines
Hi Noboru,
Quoted 8 lines · Noboru Asai
Introducing
erofs_get_inodesizefunction anderofs_get_lowest_offsetfunction, we can determine the [un]compressed data block is inline or not before executingz_erofs_merge_segmentfunction. It enable the following,* skip the redundant write for ztailpacking block.
* simplifyerofs_prepare_inode_bufferfunction. (remove handling ENOSPC error)Signed-off-by Noboru Asai <[email protected]>I appreciate and thanks for your effort and time.
Yet I tend to avoid assuming if the inline is ok or not before
prepare_inode_buffer()since it will be free for space allocator to decide inline or not at that time.So personally I still would like to write a final compressed index for inline fallback.
I will fix this issue myself later (it should be just a small patch to fix this).
Thanks for your effort on this issue again!
Thanks,
Gao Xiang