erofs-utils: refine tailpcluster compression approach
v2 cover erofs-utils: refine tailpcluster compression approach
Hi,
This patchset refines tailpcluster compression. Firstly, instead of compressing into many 4KiB pclusters, it compresses into 2 pclusters as I already mentioned in the previous comment [1].
Secondly, it fixes up EOF lclusters which was disabled on purpose before in order to achieve better inlining performance for small compressed data, which matches the new kernel fix [2].
Still take linux-5.10.87 as an example (75368 inodes in total):
linux-5.10.87 (erofs, lz4hc,9 4k tailpacking) 391696384 => 331292672
linux-5.10.87 (erofs, lz4hc,9 8k tailpacking) 368807936 => 321961984
linux-5.10.87 (erofs, lz4hc,9 16k tailpacking) 345649152 => 313344000
linux-5.10.87 (erofs, lz4hc,9 32k tailpacking) 338649088 => 309055488
(There is still another improvement working in progress..)
Thanks,
Gao Xiang
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
changes since v1 (reported by Yue Hu):
- fall back to uncompressed data if EOF lcluster inline is no possible;
- fix `ret' signedness.
Gao Xiang (2):
erofs-utils: lib: get rid of a redundent compress round
erofs-utils: lib: refine tailpcluster compression approach
include/erofs/compress.h | 1 + include/erofs/internal.h | 4 + lib/compress.c | 156 +++++++++++++++++++++++++++------------ lib/inode.c | 9 ++- 4 files changed, 119 insertions(+), 51 deletions(-)
Signature · 1 line
2.24.4
PATCH v2 1/2 erofs-utils: lib: get rid of a redundent compress round
No need another round if no remaining data.
It can improve compression ratios a bit for specific data.
--- lib/compress.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
lib/compress.c +3 -8
@@ -584,16 +584,11 @@ int erofs_write_compressed_file(struct erofs_inode *inode) remaining -= readcount; ctx.tail += readcount; -/* do one compress round */ - ret =vle_compress_one (inode, &ctx, false); + ret =vle_compress_one (inode, &ctx, !remaining);if (ret) - goto err_bdrop; + goto err_free_idata; } - -/* do the final round */ - ret =vle_compress_one (inode, &ctx, true); -if (ret) - goto err_free_idata; +DBG_BUGON (ctx.head != ctx.tail);/* fall back to no compression mode */ compressed_blocks = ctx.blkaddr - blkaddr;
Signature · 1 line
2.24.4
PATCH v2 2/2 erofs-utils: lib: refine tailpcluster compression approach
In reply to Gao XiangAs my previous comment [1] mentioned, currently, in order to inline a tail pcluster right after its inode metadata, tail data is split, compressed with many 4KiB pclusters and then the last pcluster is chosen.
However, it can have some impacts to overall compression ratios if big pclusters are enabled. So instead, let's implement another approach:
compressing with two pclusters by trying recompressing.
It also enables EOF lcluster inlining for small compressed data, so please make sure the kernel is already fixed up [2].
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
--- include/erofs/compress.h | 1 + include/erofs/internal.h | 4 ++ lib/compress.c | 145 ++++++++++++++++++++++++++++----------- lib/inode.c | 9 +-- 4 files changed, 116 insertions(+), 43 deletions(-)
include/erofs/compress.h +1 -0
@@ -19,6 +19,7 @@ extern "C"#define EROFS_CONFIG_COMPR_MAX_SZ (900 * 1024)#define EROFS_CONFIG_COMPR_MIN_SZ (32 * 1024) +void z_erofs_fixup_eof_lcluster (struct erofs_inode *inode);int erofs_write_compressed_file (struct erofs_inode *inode);int z_erofs_compress_init (struct erofs_buffer_head *bh);
include/erofs/internal.h +4 -0
@@ -186,6 +186,10 @@ struct erofs_inode {void *idata; +/* (ztailpacking) in order to recover uncompressed EOF data */ +void *eof_tailraw; +unsigned int eof_tailrawsize; +union {void *compressmeta;void *chunkindexes;
lib/compress.c +106 -39
216 lines not on this page · raw message
lib/inode.c +5 -4
@@ -96,6 +96,8 @@ unsigned int erofs_iput(struct erofs_inode *inode)list_for_each_entry_safe (d, t, &inode->i_subdirs, d_child)free (d); +if (inode->eof_tailraw) +free (inode->eof_tailraw);list_del (&inode->i_hash);free (inode);return 0 ;
@@ -614,7 +616,9 @@ static int erofs_prepare_inode_buffer(struct erofs_inode *inode)if (bh ==ERR_PTR (-ENOSPC )) {int ret; -if (!is_inode_layout_compression (inode)) +if (is_inode_layout_compression (inode)) +z_erofs_fixup_eof_lcluster (inode); +else inode->datalayout =EROFS_INODE_FLAT_PLAIN ; noinline:/* expend an extra block for tail-end data */
@@ -629,10 +633,7 @@ noinline:return PTR_ERR (bh); }else if (inode->idata_size) {if (is_inode_layout_compression (inode)) { -struct z_erofs_map_header *h = inode->compressmeta; -DBG_BUGON (!cfg.c_ztailpacking); - h->h_advise |=Z_EROFS_ADVISE_INLINE_PCLUSTER ;erofs_dbg ("Inline %scompressed data (%u bytes) to %s" , inode->compressed_idata ?"" :"un" , inode->idata_size, inode->i_srcpath);
Signature · 1 line
2.24.4
Quoted 32 lines · On Wed, 16 Feb 2022 20:28:43 +0800 Gao Xiang <[email protected]>…
Hi,
This patchset refines tailpcluster compression. Firstly, instead of compressing into many 4KiB pclusters, it compresses into 2 pclusters as I already mentioned in the previous comment [1].
Secondly, it fixes up EOF lclusters which was disabled on purpose before in order to achieve better inlining performance for small compressed data, which matches the new kernel fix [2].
Still take linux-5.10.87 as an example (75368 inodes in total):
linux-5.10.87 (erofs, lz4hc,9 4k tailpacking) 391696384 => 331292672
linux-5.10.87 (erofs, lz4hc,9 8k tailpacking) 368807936 => 321961984
linux-5.10.87 (erofs, lz4hc,9 16k tailpacking) 345649152 => 313344000
linux-5.10.87 (erofs, lz4hc,9 32k tailpacking) 338649088 => 309055488(There is still another improvement working in progress..)
Thanks,
Gao Xiang[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]changes since v1 (reported by Yue Hu):
- fall back to uncompressed data if EOF lcluster inline is no possible;
- fix `ret' signedness.Gao Xiang (2):
erofs-utils: lib: get rid of a redundent compress round
erofs-utils: lib: refine tailpcluster compression approach
Quoted 6 lines
include/erofs/compress.h | 1 + include/erofs/internal.h | 4 + lib/compress.c | 156 +++++++++++++++++++++++++++------------ lib/inode.c | 9 ++- 4 files changed, 119 insertions(+), 51 deletions(-)
Quoted 35 lines · Yue Hu
Quoted 32 lines · On Wed, 16 Feb 2022 20:28:43 +0800 Gao Xiang <[email protected]>…
Hi,
This patchset refines tailpcluster compression. Firstly, instead of compressing into many 4KiB pclusters, it compresses into 2 pclusters as I already mentioned in the previous comment [1].
Secondly, it fixes up EOF lclusters which was disabled on purpose before in order to achieve better inlining performance for small compressed data, which matches the new kernel fix [2].
Still take linux-5.10.87 as an example (75368 inodes in total):
linux-5.10.87 (erofs, lz4hc,9 4k tailpacking) 391696384 => 331292672
linux-5.10.87 (erofs, lz4hc,9 8k tailpacking) 368807936 => 321961984
linux-5.10.87 (erofs, lz4hc,9 16k tailpacking) 345649152 => 313344000
linux-5.10.87 (erofs, lz4hc,9 32k tailpacking) 338649088 => 309055488(There is still another improvement working in progress..)
Thanks,
Gao Xiang[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]changes since v1 (reported by Yue Hu):
- fall back to uncompressed data if EOF lcluster inline is no possible;
- fix `ret' signedness.Gao Xiang (2):
erofs-utils: lib: get rid of a redundent compress round
erofs-utils: lib: refine tailpcluster compression approach
Quoted 8 lines
Quoted 6 lines
include/erofs/compress.h | 1 + include/erofs/internal.h | 4 + lib/compress.c | 156 +++++++++++++++++++++++++++------------ lib/inode.c | 9 ++- 4 files changed, 119 insertions(+), 51 deletions(-)Tested-by Yue Hu <[email protected]>
Thanks for the confirmation on your side.
Thanks,
Gao Xiang