Update to zstd-1.4.6
Subsystems (7)
v6 cover Update to zstd-1.4.6
From: Nick Terrell <[email protected]>
Please pull from
[email protected]:terrelln/linux.git tags/zstd-1.4.6-v6
to get these changes. Alternatively the patchset is included.
This patchset upgrades the zstd library to the latest upstream release. The current zstd version in the kernel is a modified version of upstream zstd-1.3.1. At the time it was integrated, zstd wasn't ready to be used in the kernel as-is. But, it is now possible to use upstream zstd directly in the kernel.
I have not yet released zstd-1.4.6 upstream. I want the zstd version in the kernel to match up with a known upstream release, so we know exactly what code is running. Whenever this patchset is ready for merge, I will cut a release at the upstream commit that gets merged. This should not be necessary for future releases.
The kernel zstd library is automatically generated from upstream zstd. A script makes the necessary changes and imports it into the kernel. The changes are:
1. Replace all libc dependencies with kernel replacements and rewrite includes.
2. Remove unncessary portability macros like: #if defined(_MSC_VER).
3. Use the kernel xxhash instead of bundling it.
This automation gets tested every commit by upstream's continuous integration. When we cut a new zstd release, we will submit a patch to the kernel to update the zstd version in the kernel.
I've updated zstd to upstream with one big patch because every commit must build, so that precludes partial updates. Since the commit is 100% generated, I hope the review burden is lightened. I considered replaying upstream commits, but that is not possible because there have been ~3500 upstream commits since the last zstd import, and the commits don't all build individually. The bulk update preserves bisectablity because bugs can be bisected to the zstd version update. At that point the update can be reverted, and we can work with upstream to find and fix the bug. After this big switch in how the kernel consumes zstd, future patches will be smaller, because they will only have one upstream release worth of changes each.
This patchset adds a new kernel-style wrapper around zstd. This wrapper API is functionally equivalent to the subset of the current zstd API that is currently used. The wrapper API changes to be kernel style so that the symbols don't collide with zstd's symbols. The update to zstd-1.4.6 maintains the same API and preserves the semantics, so that none of the callers need to be updated.
This patchset comes in 2 parts:
1. The first 2 patches prepare for the zstd upgrade. The first patch adds the new kernel style API so zstd can be upgraded without modifying any callers. The second patch adds an indirection for the lib/decompress_unzstd.c including of all decompression source files.
2. Import zstd-1.4.6. This patch is completely generated from upstream using automated tooling.
I tested every caller of zstd on x86_64. I tested both after the 1.4.6 upgrade using the compatibility wrapper, and after the final patch in this series.
I tested kernel and initramfs decompression in i386 and arm.
I ran benchmarks to compare the current zstd in the kernel with zstd-1.4.6. I benchmarked on x86_64 using QEMU with KVM enabled on an Intel i9-9900k. I found:
* BtrFS zstd compression at levels 1 and 3 is 5% faster
* BtrFS zstd decompression+read is 15% faster
* SquashFS zstd decompression+read is 15% faster
* F2FS zstd compression+write at level 3 is 8% faster
* F2FS zstd decompression+read is 20% faster
* ZRAM decompression+read is 30% faster
* Kernel zstd decompression is 35% faster
* Initramfs zstd decompression+build is 5% faster
The latest zstd also offers bug fixes and a 1 KB reduction in stack uage during compression. For example the recent problem with large kernel decompression has been fixed upstream for over 2 years https://lkml.org/lkml/2020/9/29/27.
Please let me know if there is anything that I can do to ease the way for these patches. I think it is important because it gets large performance improvements, contains bug fixes, and is switching to a more maintainable model of consuming upstream zstd directly, making it easy to keep up to date.
Best,
Nick Terrell
v1 -> v2:
* Successfully tested F2FS with help from Chao Yu to fix my test.
* (1/9) Fix ZSTD_initCStream() wrapper to handle pledged_src_size=0 means unknown. This fixes F2FS with the zstd-1.4.6 compatibility wrapper, exposed by the test.
v2 -> v3:
* (3/9) Silence warnings by Kernel Test Robot:
https://github.com/facebook/zstd/pull/2324
Stack size warnings remain, but these aren't new, and the functions it warns on are either unused or not in the maximum stack path. This patchset reduces zstd compression stack usage by 1 KB overall. I've gotten the low hanging fruit, and more stack reduction would require significant changes that have the potential to introduce new bugs. However, I do hope to continue to reduce zstd stack usage in future versions.
v3 -> v4:
* (3/9) Fix errors and warnings reported by Kernel Test Robot:
https://github.com/facebook/zstd/pull/2326
- Replace mem.h with a custom kernel implementation that matches the current lib/zstd/mem.h in the kernel. This avoids calls to __builtin_bswap*() which don't work on certain architectures, as exposed by the Kernel Test Robot.
- Remove ASAN/MSAN (un)poisoning code which doesn't work in the kernel, as exposed by the Kernel Test Robot.
- I've fixed all of the valid cppcheck warnings reported, but there were many false positives, where cppcheck was incorrectly analyzing the situation, which I did not fix. I don't believe it is reasonable to expect that upstream zstd silences all the static analyzer false positives. Upstream zstd uses clang scan-build for its static analysis. We find that supporting multiple static analysis tools multiplies the burden of silencing false positives, without providing enough marginal value over running a single static analysis tool.
v4 -> v5:
* Rebase onto v5.10-rc2
* (6/9) Merge with other F2FS changes (no functional change in patch).
v5 -> v6:
* Rebase onto v5.10-rc6.
* Switch to using a kernel style wrapper API as suggested by Cristoph.
Nick Terrell (3):
lib: zstd: Add kernel-specific API
lib: zstd: Add decompress_sources.h for decompress_unzstd
lib: zstd: Upgrade to latest upstream zstd version 1.4.6
crypto/zstd.c | 28 +- fs/btrfs/zstd.c | 72 +- fs/f2fs/compress.c | 56 +- fs/pstore/platform.c | 2 +- fs/squashfs/zstd_wrapper.c | 16 +- include/linux/zstd.h | 1274 ++--- lib/decompress_unzstd.c | 66 +- lib/zstd/Makefile | 35 +- lib/zstd/bitstream.h | 379 -- lib/zstd/common/bitstream.h | 437 ++ lib/zstd/common/compiler.h | 150 + lib/zstd/common/cpu.h | 194 + lib/zstd/common/debug.c | 24 + lib/zstd/common/debug.h | 101 + lib/zstd/common/entropy_common.c | 355 ++ lib/zstd/common/error_private.c | 55 + lib/zstd/common/error_private.h | 66 + lib/zstd/common/fse.h | 709 +++ lib/zstd/common/fse_decompress.c | 380 ++ lib/zstd/common/huf.h | 352 ++ lib/zstd/common/mem.h | 258 + lib/zstd/common/zstd_common.c | 83 + lib/zstd/common/zstd_deps.h | 124 + lib/zstd/common/zstd_errors.h | 76 + lib/zstd/common/zstd_internal.h | 438 ++ lib/zstd/compress.c | 3485 -------------- lib/zstd/compress/fse_compress.c | 625 +++ lib/zstd/compress/hist.c | 165 + lib/zstd/compress/hist.h | 75 + lib/zstd/compress/huf_compress.c | 764 +++ lib/zstd/compress/zstd_compress.c | 4157 +++++++++++++++++ lib/zstd/compress/zstd_compress_internal.h | 1103 +++++ lib/zstd/compress/zstd_compress_literals.c | 158 + lib/zstd/compress/zstd_compress_literals.h | 29 + lib/zstd/compress/zstd_compress_sequences.c | 433 ++ lib/zstd/compress/zstd_compress_sequences.h | 54 + lib/zstd/compress/zstd_compress_superblock.c | 849 ++++ lib/zstd/compress/zstd_compress_superblock.h | 32 + lib/zstd/compress/zstd_cwksp.h | 465 ++ lib/zstd/compress/zstd_double_fast.c | 521 +++ lib/zstd/compress/zstd_double_fast.h | 32 + lib/zstd/compress/zstd_fast.c | 496 ++ lib/zstd/compress/zstd_fast.h | 31 + lib/zstd/compress/zstd_lazy.c | 1138 +++++ lib/zstd/compress/zstd_lazy.h | 61 + lib/zstd/compress/zstd_ldm.c | 619 +++ lib/zstd/compress/zstd_ldm.h | 104 + lib/zstd/compress/zstd_opt.c | 1200 +++++ lib/zstd/compress/zstd_opt.h | 50 + lib/zstd/decompress.c | 2531 ---------- lib/zstd/decompress/huf_decompress.c | 1205 +++++ lib/zstd/decompress/zstd_ddict.c | 241 + lib/zstd/decompress/zstd_ddict.h | 44 + lib/zstd/decompress/zstd_decompress.c | 1836 ++++++++ lib/zstd/decompress/zstd_decompress_block.c | 1540 ++++++ lib/zstd/decompress/zstd_decompress_block.h | 62 + .../decompress/zstd_decompress_internal.h | 195 + lib/zstd/decompress_sources.h | 19 + lib/zstd/entropy_common.c | 243 - lib/zstd/error_private.h | 53 - lib/zstd/fse.h | 575 --- lib/zstd/fse_compress.c | 795 ---- lib/zstd/fse_decompress.c | 325 -- lib/zstd/huf.h | 212 - lib/zstd/huf_compress.c | 772 --- lib/zstd/huf_decompress.c | 960 ---- lib/zstd/mem.h | 151 - lib/zstd/zstd.h | 2104 +++++++++ lib/zstd/zstd_common.c | 75 - lib/zstd/zstd_compress_module.c | 206 + lib/zstd/zstd_decompress_module.c | 122 + lib/zstd/zstd_internal.h | 273 -- lib/zstd/zstd_opt.h | 1014 ---- 73 files changed, 24966 insertions(+), 12963 deletions(-) delete mode 100644 lib/zstd/bitstream.h create mode 100644 lib/zstd/common/bitstream.h create mode 100644 lib/zstd/common/compiler.h create mode 100644 lib/zstd/common/cpu.h create mode 100644 lib/zstd/common/debug.c create mode 100644 lib/zstd/common/debug.h create mode 100644 lib/zstd/common/entropy_common.c create mode 100644 lib/zstd/common/error_private.c create mode 100644 lib/zstd/common/error_private.h create mode 100644 lib/zstd/common/fse.h create mode 100644 lib/zstd/common/fse_decompress.c create mode 100644 lib/zstd/common/huf.h create mode 100644 lib/zstd/common/mem.h create mode 100644 lib/zstd/common/zstd_common.c create mode 100644 lib/zstd/common/zstd_deps.h create mode 100644 lib/zstd/common/zstd_errors.h create mode 100644 lib/zstd/common/zstd_internal.h delete mode 100644 lib/zstd/compress.c create mode 100644 lib/zstd/compress/fse_compress.c create mode 100644 lib/zstd/compress/hist.c create mode 100644 lib/zstd/compress/hist.h create mode 100644 lib/zstd/compress/huf_compress.c create mode 100644 lib/zstd/compress/zstd_compress.c create mode 100644 lib/zstd/compress/zstd_compress_internal.h create mode 100644 lib/zstd/compress/zstd_compress_literals.c create mode 100644 lib/zstd/compress/zstd_compress_literals.h create mode 100644 lib/zstd/compress/zstd_compress_sequences.c create mode 100644 lib/zstd/compress/zstd_compress_sequences.h create mode 100644 lib/zstd/compress/zstd_compress_superblock.c create mode 100644 lib/zstd/compress/zstd_compress_superblock.h create mode 100644 lib/zstd/compress/zstd_cwksp.h create mode 100644 lib/zstd/compress/zstd_double_fast.c create mode 100644 lib/zstd/compress/zstd_double_fast.h create mode 100644 lib/zstd/compress/zstd_fast.c create mode 100644 lib/zstd/compress/zstd_fast.h create mode 100644 lib/zstd/compress/zstd_lazy.c create mode 100644 lib/zstd/compress/zstd_lazy.h create mode 100644 lib/zstd/compress/zstd_ldm.c create mode 100644 lib/zstd/compress/zstd_ldm.h create mode 100644 lib/zstd/compress/zstd_opt.c create mode 100644 lib/zstd/compress/zstd_opt.h delete mode 100644 lib/zstd/decompress.c create mode 100644 lib/zstd/decompress/huf_decompress.c create mode 100644 lib/zstd/decompress/zstd_ddict.c create mode 100644 lib/zstd/decompress/zstd_ddict.h create mode 100644 lib/zstd/decompress/zstd_decompress.c create mode 100644 lib/zstd/decompress/zstd_decompress_block.c create mode 100644 lib/zstd/decompress/zstd_decompress_block.h create mode 100644 lib/zstd/decompress/zstd_decompress_internal.h create mode 100644 lib/zstd/decompress_sources.h delete mode 100644 lib/zstd/entropy_common.c delete mode 100644 lib/zstd/error_private.h delete mode 100644 lib/zstd/fse.h delete mode 100644 lib/zstd/fse_compress.c delete mode 100644 lib/zstd/fse_decompress.c delete mode 100644 lib/zstd/huf.h delete mode 100644 lib/zstd/huf_compress.c delete mode 100644 lib/zstd/huf_decompress.c delete mode 100644 lib/zstd/mem.h create mode 100644 lib/zstd/zstd.h delete mode 100644 lib/zstd/zstd_common.c create mode 100644 lib/zstd/zstd_compress_module.c create mode 100644 lib/zstd/zstd_decompress_module.c delete mode 100644 lib/zstd/zstd_internal.h delete mode 100644 lib/zstd/zstd_opt.h
Signature · 8 lines
2.29.2 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v6 1/3 lib: zstd: Add kernel-specific API
From: Nick Terrell <[email protected]>
This patch:
- Moves include/linux/zstd.h -> lib/zstd/zstd.h
- Adds a new API in include/linux/zstd.h that is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.
There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
This patch is preparing the next patch in the series, which updates zstd to version 1.4.6. Since the upstream zstd API is no longer exposed to callers, the update can happen transparently.
--- crypto/zstd.c | 28 +- fs/btrfs/zstd.c | 72 +- fs/f2fs/compress.c | 56 +- fs/pstore/platform.c | 2 +- fs/squashfs/zstd_wrapper.c | 16 +- include/linux/zstd.h | 1273 ++++++++---------------------------- lib/decompress_unzstd.c | 60 +- lib/zstd/compress.c | 210 ++++-- lib/zstd/decompress.c | 140 +++- lib/zstd/error_private.h | 2 +- lib/zstd/zstd.h | 1157 ++++++++++++++++++++++++++++++++ lib/zstd/zstd_internal.h | 1 + 12 files changed, 1832 insertions(+), 1185 deletions(-) create mode 100644 lib/zstd/zstd.h
crypto/zstd.c +14 -14
@@ -18,22 +18,22 @@#define ZSTD_DEF_LEVEL 3struct zstd_ctx { -ZSTD_CCtx *cctx; -ZSTD_DCtx *dctx; +zstd_cctx *cctx; +zstd_dctx *dctx;void *cwksp;void *dwksp; }; -static ZSTD_parameters zstd_params (void ) +static struct zstd_parameters zstd_params (void ) { -return ZSTD_getParams (ZSTD_DEF_LEVEL ,0 ,0 ); +return zstd_get_params (ZSTD_DEF_LEVEL ,0 ); }static int zstd_comp_init (struct zstd_ctx *ctx) {int ret =0 ; -const ZSTD_parameters params =zstd_params (); -const size_t wksp_size =ZSTD_CCtxWorkspaceBound (params.cParams); +const struct zstd_parameters params =zstd_params (); +const size_t wksp_size =zstd_cctx_workspace_bound (¶ms.cparams); ctx->cwksp =vzalloc (wksp_size);if (!ctx->cwksp) {
@@ -41,7 +41,7 @@ static int zstd_comp_init(struct zstd_ctx *ctx) goto out; } - ctx->cctx =ZSTD_initCCtx (ctx->cwksp, wksp_size); + ctx->cctx =zstd_init_cctx (ctx->cwksp, wksp_size);if (!ctx->cctx) { ret = -EINVAL ; goto out_free;
@@ -56,7 +56,7 @@ static int zstd_comp_init(struct zstd_ctx *ctx)static int zstd_decomp_init (struct zstd_ctx *ctx) {int ret =0 ; -const size_t wksp_size =ZSTD_DCtxWorkspaceBound (); +const size_t wksp_size =zstd_dctx_workspace_bound (); ctx->dwksp =vzalloc (wksp_size);if (!ctx->dwksp) {
@@ -64,7 +64,7 @@ static int zstd_decomp_init(struct zstd_ctx *ctx) goto out; } - ctx->dctx =ZSTD_initDCtx (ctx->dwksp, wksp_size); + ctx->dctx =zstd_init_dctx (ctx->dwksp, wksp_size);if (!ctx->dctx) { ret = -EINVAL ; goto out_free;
@@ -152,10 +152,10 @@ static int __zstd_compress(const u8 *src, unsigned int slen, {size_t out_len;struct zstd_ctx *zctx = ctx; -const ZSTD_parameters params =zstd_params (); +const struct zstd_parameters params =zstd_params (); - out_len =ZSTD_compressCCtx (zctx->cctx, dst, *dlen, src, slen, params); -if (ZSTD_isError (out_len)) + out_len =zstd_compress_cctx (zctx->cctx, dst, *dlen, src, slen, ¶ms); +if (zstd_is_error (out_len))return -EINVAL ; *dlen = out_len;return 0 ;
@@ -182,8 +182,8 @@ static int __zstd_decompress(const u8 *src, unsigned int slen,size_t out_len;struct zstd_ctx *zctx = ctx; - out_len =ZSTD_decompressDCtx (zctx->dctx, dst, *dlen, src, slen); -if (ZSTD_isError (out_len)) + out_len =zstd_decompress_dctx (zctx->dctx, dst, *dlen, src, slen); +if (zstd_is_error (out_len))return -EINVAL ; *dlen = out_len;return 0 ;
fs/btrfs/zstd.c +36 -36
174 lines not on this page · raw message
fs/f2fs/compress.c +28 -28
120 lines not on this page · raw message
fs/pstore/platform.c +1 -1
@@ -218,7 +218,7 @@ static int zbufsize_842(size_t size)#if IS_ENABLED (CONFIG_PSTORE_ZSTD_COMPRESS )static int zbufsize_zstd (size_t size) { -return ZSTD_compressBound (size); +return zstd_compress_bound (size); }#endif
fs/squashfs/zstd_wrapper.c +8 -8
@@ -34,7 +34,7 @@ static void *zstd_init(struct squashfs_sb_info *msblk, void *buff) goto failed; wksp->window_size =max_t (size_t, msblk->block_size,SQUASHFS_METADATA_SIZE ); - wksp->mem_size =ZSTD_DStreamWorkspaceBound (wksp->window_size); + wksp->mem_size =zstd_dstream_workspace_bound (wksp->window_size); wksp->mem =vmalloc (wksp->mem_size);if (wksp->mem ==NULL ) goto failed;
@@ -63,15 +63,15 @@ static int zstd_uncompress(struct squashfs_sb_info *msblk, void *strm, struct squashfs_page_actor *output) {struct workspace *wksp = strm; -ZSTD_DStream *stream; +zstd_dstream *stream;size_t total_out =0 ;int error =0 ; -ZSTD_inBuffer in_buf = {NULL ,0 ,0 }; -ZSTD_outBuffer out_buf = {NULL ,0 ,0 }; +struct zstd_in_buffer in_buf = {NULL ,0 ,0 }; +struct zstd_out_buffer out_buf = {NULL ,0 ,0 };struct bvec_iter_all iter_all = {};struct bio_vec *bvec =bvec_init_iter_all (&iter_all); - stream =ZSTD_initDStream (wksp->window_size, wksp->mem, wksp->mem_size); + stream =zstd_init_dstream (wksp->window_size, wksp->mem, wksp->mem_size);if (!stream) {ERROR ("Failed to initialize zstd decompressor\n" );
@@ -116,14 +116,14 @@ static int zstd_uncompress(struct squashfs_sb_info *msblk, void *strm, } total_out -= out_buf.pos; - zstd_err =ZSTD_decompressStream (stream, &out_buf, &in_buf); + zstd_err =zstd_decompress_stream (stream, &out_buf, &in_buf); total_out += out_buf.pos;/* add the additional data produced */ if (zstd_err ==0 )break ; -if (ZSTD_isError (zstd_err)) { +if (zstd_is_error (zstd_err)) {ERROR ("zstd decompression error: %d\n" , - (int )ZSTD_getErrorCode (zstd_err)); + (int )zstd_get_error_code (zstd_err)); error = -EIO ;break ; }
include/linux/zstd.h +287 -986
1,434 lines not on this page · raw message
lib/decompress_unzstd.c +22 -38
137 lines not on this page · raw message
lib/zstd/compress.c +173 -37
216 lines not on this page · raw message
lib/zstd/decompress.c +104 -36
146 lines not on this page · raw message
lib/zstd/error_private.h +1 -1
@@ -23,7 +23,7 @@* Dependencies ******************************************/ #include <linux/types.h> /* size_t */ -#include <linux/zstd.h> /* enum list */ +#include "zstd.h" /* enum list */ /* **************************************** * Compiler-specific
lib/zstd/zstd.h new file +1157 -0
638 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.29.2
Part of the diff is not shown here. View the raw message.
Re: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0
[...]
Quoted 17 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-12-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0 ; -switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected:
lib/decompress_unzstd.c line 100
Quoted 10 lines
lib/decompress_unzstd.c +1
-7-case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" ); -break ; - } +error ("ZSTD decompression failed" );return -1 ; }
This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Quoted 4 lines
lib/decompress_unzstd.c +4
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o;
lib/decompress_unzstd.c
Quoted 10 lines
lib/decompress_unzstd.c +10
-0+ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i)); + ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}
Is all this copying necessary? How is it different from type-punning by direct pointer cast?
Best Regards
Michał Mirosław
Nick Terrell
maintainerRe: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
Quoted 45 lines · Michał Mirosław
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0[...]
Quoted 22 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-3-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0;lib/decompress_unzstd.c +0
-14-switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected: -case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" );
Quoted 8 lines
Quoted 5 lines
lib/decompress_unzstd.c +1
-2-break ; - } +error ("ZSTD decompression failed" );return -1; }This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Good point. The zstd API no longer exposes the error code enum, but it does expose zstd_get_error_name() which can be used here. I was thinking that the string needed to be static for some reason, but that is not the case. I will make that change.
Quoted 9 lines
Quoted 9 lines
lib/decompress_unzstd.c +9
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o; +ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i));
Quoted 8 lines
lib/decompress_unzstd.c
Quoted 5 lines
lib/decompress_unzstd.c +5
-0+ ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}Is all this copying necessary? How is it different from type-punning by direct pointer cast?
If breaking strict aliasing and type-punning by pointer casing is okay, then we can do that here. These memcpys will be negligible for performance, but type-punning would be more succinct if allowed.
Best,
Nick
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
Quoted 77 lines · Nick Terrell
Quoted 45 lines · Michał Mirosław
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0[...]
Quoted 22 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-3-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0;lib/decompress_unzstd.c +0
-14-switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected: -case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" );Quoted 8 lines
Quoted 5 lines
lib/decompress_unzstd.c +1
-2-break ; - } +error ("ZSTD decompression failed" );return -1; }This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Good point. The zstd API no longer exposes the error code enum, but it does expose
zstd_get_error_name()which can be used here. I was thinking that the string needed to be static for some reason, but that is not the case. I will make that change.Quoted 9 lines
Quoted 9 lines
lib/decompress_unzstd.c +9
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o; +ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i));Quoted 8 lines
lib/decompress_unzstd.c
Quoted 5 lines
lib/decompress_unzstd.c +5
-0+ ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}Is all this copying necessary? How is it different from type-punning by direct pointer cast?
Quoted 3 lines
If breaking strict aliasing and type-punning by pointer casing is okay, then we can do that here. These memcpys will be negligible for performance, but type-punning would be more succinct if allowed.
Ah, this might break LTO builds due to strict aliasing violation. So I would suggest to just #define the ZSTD names to kernel ones for the library code. Unless there is a cleaner solution...
Best Regards
Michał Mirosław
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Nick Terrell
maintainerRe: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
Quoted 82 lines · Michał Mirosław
Quoted 77 lines · Nick Terrell
Quoted 45 lines · Michał Mirosław
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0[...]
Quoted 22 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-3-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0;lib/decompress_unzstd.c +0
-14-switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected: -case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" );Quoted 8 lines
Quoted 5 lines
lib/decompress_unzstd.c +1
-2-break ; - } +error ("ZSTD decompression failed" );return -1; }This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Good point. The zstd API no longer exposes the error code enum, but it does expose
zstd_get_error_name()which can be used here. I was thinking that the string needed to be static for some reason, but that is not the case. I will make that change.Quoted 17 lines
Quoted 4 lines
lib/decompress_unzstd.c +4
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o;lib/decompress_unzstd.c
Quoted 10 lines
lib/decompress_unzstd.c +10
-0+ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i)); + ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}Is all this copying necessary? How is it different from type-punning by direct pointer cast?
Quoted 7 lines
Quoted 3 lines
If breaking strict aliasing and type-punning by pointer casing is okay, then we can do that here. These memcpys will be negligible for performance, but type-punning would be more succinct if allowed.
Ah, this might break LTO builds due to strict aliasing violation. So I would suggest to just #define the ZSTD names to kernel ones for the library code. Unless there is a cleaner solution...
I don’t want to do that because I want in the 3rd series of the patchset I update to zstd-1.4.6. And I’m using zstd-1.4.6 as-is in upstream. This allows us to keep the kernel version up to date, since the patch to update to a new version can be generated automatically (and manually tested), so it doesn’t fall years behind upstream again.
The alternative would be to make upstream zstd’s header public and #define zstd_in_buffer ZSTD_inBuffer. But that would make zstd’s header public, which would somewhat defeat the purpose of having a kernel wrapper.
These memcpy’s won’t hurt performance, since this function is called at most every 4KB of input data in all the callers, though they are clunky.
Re: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
Quoted 90 lines · Nick Terrell
Quoted 75 lines · Michał Mirosław
Quoted 74 lines · Nick Terrell
Quoted 41 lines · Michał Mirosław
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0[...]
Quoted 22 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-3-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0;lib/decompress_unzstd.c +0
-14-switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected: -case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" );Quoted 8 lines
Quoted 5 lines
lib/decompress_unzstd.c +1
-2-break ; - } +error ("ZSTD decompression failed" );return -1; }This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Good point. The zstd API no longer exposes the error code enum, but it does expose
zstd_get_error_name()which can be used here. I was thinking that the string needed to be static for some reason, but that is not the case. I will make that change.Quoted 17 lines
Quoted 4 lines
lib/decompress_unzstd.c +4
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o;lib/decompress_unzstd.c
Quoted 10 lines
lib/decompress_unzstd.c +10
-0+ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i)); + ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}Is all this copying necessary? How is it different from type-punning by direct pointer cast?
Quoted 7 lines
Quoted 3 lines
If breaking strict aliasing and type-punning by pointer casing is okay, then we can do that here. These memcpys will be negligible for performance, but type-punning would be more succinct if allowed.
Ah, this might break LTO builds due to strict aliasing violation. So I would suggest to just #define the ZSTD names to kernel ones for the library code. Unless there is a cleaner solution...
I don’t want to do that because I want in the 3rd series of the patchset I update to zstd-1.4.6. And I’m using zstd-1.4.6 as-is in upstream. This allows us to keep the kernel version up to date, since the patch to update to a new version can be generated automatically (and manually tested), so it doesn’t fall years behind upstream again.
Quoted 3 lines
The alternative would be to make upstream zstd’s header public and #define
zstd_in_bufferZSTD_inBuffer. But that would make zstd’s header public, which would somewhat defeat the purpose of having a kernel wrapper.
I thought the problem was API style spill-over from the library to other parts of the kernel. A header-only wrapper can stop this. I'm not sure symbol visibility (namespace pollution) was a concern.
Best Regards
Michał Mirosław
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Nick Terrell
maintainerRe: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
Quoted 95 lines · Michał Mirosław
Quoted 90 lines · Nick Terrell
Quoted 75 lines · Michał Mirosław
Quoted 74 lines · Nick Terrell
Quoted 41 lines · Michał Mirosław
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0[...]
Quoted 22 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-3-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0;lib/decompress_unzstd.c +0
-14-switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected: -case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" );Quoted 8 lines
Quoted 5 lines
lib/decompress_unzstd.c +1
-2-break ; - } +error ("ZSTD decompression failed" );return -1; }This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Good point. The zstd API no longer exposes the error code enum, but it does expose
zstd_get_error_name()which can be used here. I was thinking that the string needed to be static for some reason, but that is not the case. I will make that change.Quoted 17 lines
Quoted 4 lines
lib/decompress_unzstd.c +4
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o;lib/decompress_unzstd.c
Quoted 10 lines
lib/decompress_unzstd.c +10
-0+ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i)); + ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}Is all this copying necessary? How is it different from type-punning by direct pointer cast?
Quoted 7 lines
Quoted 3 lines
If breaking strict aliasing and type-punning by pointer casing is okay, then we can do that here. These memcpys will be negligible for performance, but type-punning would be more succinct if allowed.
Ah, this might break LTO builds due to strict aliasing violation. So I would suggest to just #define the ZSTD names to kernel ones for the library code. Unless there is a cleaner solution...
I don’t want to do that because I want in the 3rd series of the patchset I update to zstd-1.4.6. And I’m using zstd-1.4.6 as-is in upstream. This allows us to keep the kernel version up to date, since the patch to update to a new version can be generated automatically (and manually tested), so it doesn’t fall years behind upstream again.
Quoted 7 lines
Quoted 3 lines
The alternative would be to make upstream zstd’s header public and #define
zstd_in_bufferZSTD_inBuffer. But that would make zstd’s header public, which would somewhat defeat the purpose of having a kernel wrapper.I thought the problem was API style spill-over from the library to other parts of the kernel. A header-only wrapper can stop this. I'm not sure symbol visibility (namespace pollution) was a concern.
Thats true. It seems slightly unclean, but so Is duplicating these structs and memcpying them. So I’ll go ahead and expose the upstream zstd’s header (“lib/zstd/zstd.h” here). I’ll just need to pick a name for the upstream “zstd.h” header.
Quoted 2 lines
Best Regards
Michał Mirosław
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Nick Terrell
maintainerRe: [PATCH v6 1/3] lib: zstd: Add kernel-specific API
In reply to Michał MirosławQuoted 95 lines · Michał Mirosław
Quoted 90 lines · Nick Terrell
Quoted 75 lines · Michał Mirosław
Quoted 74 lines · Nick Terrell
Quoted 41 lines · Michał Mirosław
Quoted 14 lines · Nick Terrell
From: Nick Terrell <[email protected]>
This patch:
- Movesinclude/linux/zstd.h->lib/zstd/zstd.h
- Adds a new API ininclude/linux/zstd.hthat is functionally equivalent to the in-use subset of the current API. Functions are renamed to avoid symbol collisions with zstd, to make it clear it is not the upstream zstd API, and to follow the kernel style guide.
- Updates all callers to use the new API.There are no functional changes in this patch. Since there are no functional change, I felt it was okay to update all the callers in a single patch, since once the API is approved, the callers are mechanically changed.
[...]
Quoted 2 lines
lib/decompress_unzstd.c +0
-0[...]
Quoted 22 lines
static int INIT
handle_zstd_error(size_t ret, void (*error)(char *x)){lib/decompress_unzstd.c +1
-3-const int err =ZSTD_getErrorCode (ret); - -if (!ZSTD_isError (ret)) +if (!zstd_is_error (ret))return 0;lib/decompress_unzstd.c +0
-14-switch (err) { -case ZSTD_error_memory_allocation: -error ("ZSTD decompressor ran out of memory" ); -break ; -case ZSTD_error_prefix_unknown: -error ("Input is not in the ZSTD format (wrong magic bytes)" ); -break ; -case ZSTD_error_dstSize_tooSmall: -case ZSTD_error_corruption_detected: -case ZSTD_error_checksum_wrong: -error ("ZSTD-compressed data is corrupt" ); -break ; -default : -error ("ZSTD-compressed data is probably corrupt" );Quoted 8 lines
Quoted 5 lines
lib/decompress_unzstd.c +1
-2-break ; - } +error ("ZSTD decompression failed" );return -1; }This looses diagnostics specificity - is this intended? At least the out-of-memory condition seems useful to distinguish.
Good point. The zstd API no longer exposes the error code enum, but it does expose
zstd_get_error_name()which can be used here. I was thinking that the string needed to be static for some reason, but that is not the case. I will make that change.Quoted 17 lines
Quoted 4 lines
lib/decompress_unzstd.c +4
-0+size_t zstd_compress_stream (zstd_cstream *cstream, +struct zstd_out_buffer *output,struct zstd_in_buffer *input) +{ +ZSTD_outBuffer o;lib/decompress_unzstd.c
Quoted 10 lines
lib/decompress_unzstd.c +10
-0+ZSTD_inBuffer i; +size_t ret; + +memcpy (&o, output,sizeof (o)); +memcpy (&i, input,sizeof (i)); + ret =ZSTD_compressStream (cstream, &o, &i); +memcpy (output, &o,sizeof (o)); +memcpy (input, &i,sizeof (i)); +return ret; +}Is all this copying necessary? How is it different from type-punning by direct pointer cast?
Quoted 7 lines
Quoted 3 lines
If breaking strict aliasing and type-punning by pointer casing is okay, then we can do that here. These memcpys will be negligible for performance, but type-punning would be more succinct if allowed.
Ah, this might break LTO builds due to strict aliasing violation. So I would suggest to just #define the ZSTD names to kernel ones for the library code. Unless there is a cleaner solution...
I don’t want to do that because I want in the 3rd series of the patchset I update to zstd-1.4.6. And I’m using zstd-1.4.6 as-is in upstream. This allows us to keep the kernel version up to date, since the patch to update to a new version can be generated automatically (and manually tested), so it doesn’t fall years behind upstream again.
Quoted 7 lines
Quoted 3 lines
The alternative would be to make upstream zstd’s header public and #define
zstd_in_bufferZSTD_inBuffer. But that would make zstd’s header public, which would somewhat defeat the purpose of having a kernel wrapper.I thought the problem was API style spill-over from the library to other parts of the kernel. A header-only wrapper can stop this. I'm not sure symbol visibility (namespace pollution) was a concern.
Thanks for the review Michał! I have just submitted a new version of the patches with the suggested changes!
Best,
Nick Terrell
Quoted 2 lines
Best Regards
Michał Mirosław
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v6 2/3 lib: zstd: Add decompress_sources.h for decompress_unzstd
In reply to Nick TerrellFrom: Nick Terrell <[email protected]>
Adds decompress_sources.h which includes every .c file necessary for zstd decompression. This is used in decompress_unzstd.c so the internal structure of the library isn't exposed.
This allows us to upgrade the zstd library version without modifying any callers. Instead we just need to update decompress_sources.h.
--- lib/decompress_unzstd.c | 6 +----- lib/zstd/decompress_sources.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 lib/zstd/decompress_sources.h
lib/decompress_unzstd.c +1 -5
@@ -68,11 +68,7 @@#ifdef STATIC # define UNZSTD_PREBOOT # include "xxhash.c" -# include "zstd/entropy_common.c" -# include "zstd/fse_decompress.c" -# include "zstd/huf_decompress.c" -# include "zstd/zstd_common.c" -# include "zstd/decompress.c" +# include "zstd/decompress_sources.h" #endif #include <linux/decompress/mm.h>
lib/zstd/decompress_sources.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* +* This file includes every .c file needed for decompression. +* It is used by lib/decompress_unzstd.c to include the decompression +* source into the translation-unit, so it can be used for kernel +* decompression. +*/ + +#include "entropy_common.c" +#include "fse_decompress.c" +#include "huf_decompress.c" +#include "zstd_common.c" +#include "decompress.c"
Signature · 8 lines
2.29.2 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v6 3/3 lib: zstd: Upgrade to latest upstream zstd version 1.4.6
In reply to Nick TerrellFrom: Nick Terrell <[email protected]>
Upgrade to the latest upstream zstd version 1.4.6.
This patch is 100% generated from upstream zstd commit 841b626d815b [0].
This patch is very large because it is transitioning from the custom kernel zstd to using upstream directly. The new zstd follows upstreams file structure which is different. Future update patches will be much smaller because they will only contain the changes from one upstream zstd release.
As an aid for review I've created a commit [1] that shows the diff between upstream zstd as-is (which doesn't compile), and the zstd code imported in this patch. The verion of zstd in this patch is generated from upstream with changes applied by automation to replace upstreams libc dependencies, remove unnecessary portability macros, and use the kernel's xxhash instead of bundling it.
The benefits of this patch are as follows:
1. Using upstream directly with automated script to generate kernel code. This allows us to update the kernel every upstream release, so the kernel gets the latest bug fixes and performance improvements, and doesn't get 3 years out of date again. The automation and the translated code are tested every upstream commit to ensure it continues to work.
2. Upgrades from a custom zstd based on 1.3.1 to 1.4.6, getting 3 years of performance improvements and bug fixes. On x86_64 I've measured 15% faster BtrFS and SquashFS decompression+read speeds, 35% faster kernel decompression, and 30% faster ZRAM decompression+read speeds. Additionally, the latest zstd uses ~1 KB less stack space for compression.
3. Zstd-1.4.6 supports negative compression levels, which allow zstd to match or subsume lzo's performance.
4. Maintains the same kernel-specific wrapper API, so no callers have to be modified with zstd version updates.
I chose the bulk update instead of replaying upstream commits because there have been ~3500 upstream commits since the 1.3.1 release, zstd wasn't ready to be used in the kernel as-is before a month ago, and not all upstream zstd commits build. The bulk update preserves bisectablity because bugs can be bisected to the zstd version update. At that point the update can be reverted, and we can work with upstream to find and fix the bug.
Note that upstream zstd release 1.4.6 doesn't exist yet. I have cut a staging branch at 841b626d815b [0] and will apply any changes requested to the staging branch. Once we're ready to merge this update I will cut a zstd release at the commit we merge, so we have a known zstd release in the kernel.
The implementation of the kernel API is contained in zstd_compress_module.c and zstd_decompress_module.c.
[0] https://github.com/facebook/zstd/commit/841b626d815b37561596cc2449cf37d071e8812d
[1] https://github.com/terrelln/linux/commit/c59b8ceddbac03fc093ba9e43d6ed5936044dadd
--- include/linux/zstd.h | 21 +- lib/zstd/Makefile | 35 +- lib/zstd/bitstream.h | 379 -- lib/zstd/common/bitstream.h | 437 ++ lib/zstd/common/compiler.h | 150 + lib/zstd/common/cpu.h | 194 + lib/zstd/common/debug.c | 24 + lib/zstd/common/debug.h | 101 + lib/zstd/common/entropy_common.c | 355 ++ lib/zstd/common/error_private.c | 55 + lib/zstd/common/error_private.h | 66 + lib/zstd/common/fse.h | 709 +++ lib/zstd/common/fse_decompress.c | 380 ++ lib/zstd/common/huf.h | 352 ++ lib/zstd/common/mem.h | 258 + lib/zstd/common/zstd_common.c | 83 + lib/zstd/common/zstd_deps.h | 124 + lib/zstd/common/zstd_errors.h | 76 + lib/zstd/common/zstd_internal.h | 438 ++ lib/zstd/compress.c | 3621 -------------- lib/zstd/compress/fse_compress.c | 625 +++ lib/zstd/compress/hist.c | 165 + lib/zstd/compress/hist.h | 75 + lib/zstd/compress/huf_compress.c | 764 +++ lib/zstd/compress/zstd_compress.c | 4157 +++++++++++++++++ lib/zstd/compress/zstd_compress_internal.h | 1103 +++++ lib/zstd/compress/zstd_compress_literals.c | 158 + lib/zstd/compress/zstd_compress_literals.h | 29 + lib/zstd/compress/zstd_compress_sequences.c | 433 ++ lib/zstd/compress/zstd_compress_sequences.h | 54 + lib/zstd/compress/zstd_compress_superblock.c | 849 ++++ lib/zstd/compress/zstd_compress_superblock.h | 32 + lib/zstd/compress/zstd_cwksp.h | 465 ++ lib/zstd/compress/zstd_double_fast.c | 521 +++ lib/zstd/compress/zstd_double_fast.h | 32 + lib/zstd/compress/zstd_fast.c | 496 ++ lib/zstd/compress/zstd_fast.h | 31 + lib/zstd/compress/zstd_lazy.c | 1138 +++++ lib/zstd/compress/zstd_lazy.h | 61 + lib/zstd/compress/zstd_ldm.c | 619 +++ lib/zstd/compress/zstd_ldm.h | 104 + lib/zstd/compress/zstd_opt.c | 1200 +++++ lib/zstd/compress/zstd_opt.h | 50 + lib/zstd/decompress.c | 2599 ----------- lib/zstd/decompress/huf_decompress.c | 1205 +++++ lib/zstd/decompress/zstd_ddict.c | 241 + lib/zstd/decompress/zstd_ddict.h | 44 + lib/zstd/decompress/zstd_decompress.c | 1836 ++++++++ lib/zstd/decompress/zstd_decompress_block.c | 1540 ++++++ lib/zstd/decompress/zstd_decompress_block.h | 62 + .../decompress/zstd_decompress_internal.h | 195 + lib/zstd/decompress_sources.h | 15 +- lib/zstd/entropy_common.c | 243 - lib/zstd/error_private.h | 53 - lib/zstd/fse.h | 575 --- lib/zstd/fse_compress.c | 795 ---- lib/zstd/fse_decompress.c | 325 -- lib/zstd/huf.h | 212 - lib/zstd/huf_compress.c | 772 --- lib/zstd/huf_decompress.c | 960 ---- lib/zstd/mem.h | 151 - lib/zstd/zstd.h | 3021 ++++++++---- lib/zstd/zstd_common.c | 75 - lib/zstd/zstd_compress_module.c | 206 + lib/zstd/zstd_decompress_module.c | 122 + lib/zstd/zstd_internal.h | 274 -- lib/zstd/zstd_opt.h | 1014 ---- 67 files changed, 24450 insertions(+), 13104 deletions(-) delete mode 100644 lib/zstd/bitstream.h create mode 100644 lib/zstd/common/bitstream.h create mode 100644 lib/zstd/common/compiler.h create mode 100644 lib/zstd/common/cpu.h create mode 100644 lib/zstd/common/debug.c create mode 100644 lib/zstd/common/debug.h create mode 100644 lib/zstd/common/entropy_common.c create mode 100644 lib/zstd/common/error_private.c create mode 100644 lib/zstd/common/error_private.h create mode 100644 lib/zstd/common/fse.h create mode 100644 lib/zstd/common/fse_decompress.c create mode 100644 lib/zstd/common/huf.h create mode 100644 lib/zstd/common/mem.h create mode 100644 lib/zstd/common/zstd_common.c create mode 100644 lib/zstd/common/zstd_deps.h create mode 100644 lib/zstd/common/zstd_errors.h create mode 100644 lib/zstd/common/zstd_internal.h delete mode 100644 lib/zstd/compress.c create mode 100644 lib/zstd/compress/fse_compress.c create mode 100644 lib/zstd/compress/hist.c create mode 100644 lib/zstd/compress/hist.h create mode 100644 lib/zstd/compress/huf_compress.c create mode 100644 lib/zstd/compress/zstd_compress.c create mode 100644 lib/zstd/compress/zstd_compress_internal.h create mode 100644 lib/zstd/compress/zstd_compress_literals.c create mode 100644 lib/zstd/compress/zstd_compress_literals.h create mode 100644 lib/zstd/compress/zstd_compress_sequences.c create mode 100644 lib/zstd/compress/zstd_compress_sequences.h create mode 100644 lib/zstd/compress/zstd_compress_superblock.c create mode 100644 lib/zstd/compress/zstd_compress_superblock.h create mode 100644 lib/zstd/compress/zstd_cwksp.h create mode 100644 lib/zstd/compress/zstd_double_fast.c create mode 100644 lib/zstd/compress/zstd_double_fast.h create mode 100644 lib/zstd/compress/zstd_fast.c create mode 100644 lib/zstd/compress/zstd_fast.h create mode 100644 lib/zstd/compress/zstd_lazy.c create mode 100644 lib/zstd/compress/zstd_lazy.h create mode 100644 lib/zstd/compress/zstd_ldm.c create mode 100644 lib/zstd/compress/zstd_ldm.h create mode 100644 lib/zstd/compress/zstd_opt.c create mode 100644 lib/zstd/compress/zstd_opt.h delete mode 100644 lib/zstd/decompress.c create mode 100644 lib/zstd/decompress/huf_decompress.c create mode 100644 lib/zstd/decompress/zstd_ddict.c create mode 100644 lib/zstd/decompress/zstd_ddict.h create mode 100644 lib/zstd/decompress/zstd_decompress.c create mode 100644 lib/zstd/decompress/zstd_decompress_block.c create mode 100644 lib/zstd/decompress/zstd_decompress_block.h create mode 100644 lib/zstd/decompress/zstd_decompress_internal.h delete mode 100644 lib/zstd/entropy_common.c delete mode 100644 lib/zstd/error_private.h delete mode 100644 lib/zstd/fse.h delete mode 100644 lib/zstd/fse_compress.c delete mode 100644 lib/zstd/fse_decompress.c delete mode 100644 lib/zstd/huf.h delete mode 100644 lib/zstd/huf_compress.c delete mode 100644 lib/zstd/huf_decompress.c delete mode 100644 lib/zstd/mem.h delete mode 100644 lib/zstd/zstd_common.c create mode 100644 lib/zstd/zstd_compress_module.c create mode 100644 lib/zstd/zstd_decompress_module.c delete mode 100644 lib/zstd/zstd_internal.h delete mode 100644 lib/zstd/zstd_opt.h
include/linux/zstd.h +11 -10
@@ -69,14 +69,15 @@ const char *zstd_get_error_name(size_t code);* From faster to stronger. */ enum zstd_strategy { - zstd_fast, - zstd_dfast, - zstd_greedy, - zstd_lazy, - zstd_lazy2, - zstd_btlazy2, - zstd_btopt, - zstd_btopt2 + zstd_fast =1 , + zstd_dfast =2 , + zstd_greedy =3 , + zstd_lazy =4 , + zstd_lazy2 =5 , + zstd_btlazy2 =6 , + zstd_btopt =7 , + zstd_btultra =8 , + zstd_btultra2 =9 };/**
@@ -257,7 +258,7 @@ struct zstd_out_buffer {/* ====== Streaming Compression ====== */ -typedef struct ZSTD_CStream_s zstd_cstream ; +typedef struct ZSTD_CCtx_s zstd_cstream ;/** * zstd_cstream_workspace_bound() - memory needed to initialize a zstd_cstream
@@ -353,7 +354,7 @@ size_t zstd_end_stream(zstd_cstream *cstream, struct zstd_out_buffer *output);/* ====== Streaming Decompression ====== */ -typedef struct ZSTD_DStream_s zstd_dstream ; +typedef struct ZSTD_DCtx_s zstd_dstream ;/** * zstd_dstream_workspace_bound() - memory needed to initialize a zstd_dstream
lib/zstd/Makefile +31 -4
@@ -4,7 +4,34 @@ obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o ccflags-y += -O3 -zstd_compress-y := fse_compress.o huf_compress.o compress.o \ - entropy_common.o fse_decompress.o zstd_common.o -zstd_decompress-y := huf_decompress.o decompress.o \ - entropy_common.o fse_decompress.o zstd_common.o +zstd_compress-y := \ + zstd_compress_module.o \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \ + compress/fse_compress.o \ + compress/hist.o \ + compress/huf_compress.o \ + compress/zstd_compress.o \ + compress/zstd_compress_literals.o \ + compress/zstd_compress_sequences.o \ + compress/zstd_compress_superblock.o \ + compress/zstd_double_fast.o \ + compress/zstd_fast.o \ + compress/zstd_lazy.o \ + compress/zstd_ldm.o \ + compress/zstd_opt.o \ + +zstd_decompress-y := \ + zstd_decompress_module.o \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \ + decompress/huf_decompress.o \ + decompress/zstd_ddict.o \ + decompress/zstd_decompress.o \ + decompress/zstd_decompress_block.o \
lib/zstd/bitstream.h deleted +0 -379
379 lines not on this page · raw message
lib/zstd/common/bitstream.h new file +437 -0
437 lines not on this page · raw message
lib/zstd/common/compiler.h new file +150 -0
150 lines not on this page · raw message
lib/zstd/common/cpu.h new file +194 -0
194 lines not on this page · raw message
lib/zstd/common/debug.c new file +24 -0
@@ -0,0 +1,24 @@ +/* ****************************************************************** +* debug +* Part of FSE library +* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc. +* +* You can contact the author at : +* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy +* +* This source code is licensed under both the BSD-style license (found in the +* LICENSE file in the root directory of this source tree) and the GPLv2 (found +* in the COPYING file in the root directory of this source tree). +* You may select, at your option, one of the above-listed licenses. +****************************************************************** */ + + +/* +* This module only hosts one global variable +* which can be used to dynamically influence the verbosity of traces, +* such as DEBUGLOG and RAWLOG +*/ + +#include "debug.h" + +int g_debuglevel =DEBUGLEVEL ;
lib/zstd/common/debug.h new file +101 -0
101 lines not on this page · raw message
lib/zstd/common/entropy_common.c new file +355 -0
355 lines not on this page · raw message
lib/zstd/common/error_private.c new file +55 -0
55 lines not on this page · raw message
lib/zstd/common/error_private.h new file +66 -0
66 lines not on this page · raw message
lib/zstd/common/fse.h new file +709 -0
709 lines not on this page · raw message
lib/zstd/common/fse_decompress.c new file +380 -0
380 lines not on this page · raw message
lib/zstd/common/huf.h new file +352 -0
73 lines not on this page · raw message
lib/zstd/common/mem.h new file +258 -0
258 lines not on this page · raw message
lib/zstd/common/zstd_common.c new file +83 -0
83 lines not on this page · raw message
lib/zstd/common/zstd_deps.h new file +124 -0
124 lines not on this page · raw message
lib/zstd/common/zstd_errors.h new file +76 -0
76 lines not on this page · raw message
lib/zstd/common/zstd_internal.h new file +438 -0
438 lines not on this page · raw message
lib/zstd/compress.c deleted +0 -3621
3,621 lines not on this page · raw message
lib/zstd/compress/fse_compress.c new file +625 -0
625 lines not on this page · raw message
lib/zstd/compress/hist.c new file +165 -0
165 lines not on this page · raw message
lib/zstd/compress/hist.h new file +75 -0
75 lines not on this page · raw message
lib/zstd/compress/huf_compress.c new file +764 -0
764 lines not on this page · raw message
lib/zstd/compress/zstd_compress.c new file +4157 -0
4,157 lines not on this page · raw message
lib/zstd/compress/zstd_compress_internal.h new file +1103 -0
1,103 lines not on this page · raw message
lib/zstd/compress/zstd_compress_literals.c new file +158 -0
158 lines not on this page · raw message
lib/zstd/compress/zstd_compress_literals.h new file +29 -0
Lines of this file are not shown. View the raw message.
lib/zstd/compress/zstd_compress_sequences.c new file +433 -0
433 lines not on this page · raw message
lib/zstd/compress/zstd_compress_sequences.h new file +54 -0
54 lines not on this page · raw message
lib/zstd/compress/zstd_compress_superblock.c new file +849 -0
849 lines not on this page · raw message
lib/zstd/compress/zstd_compress_superblock.h new file +32 -0
Lines of this file are not shown. View the raw message.
lib/zstd/compress/zstd_cwksp.h new file +465 -0
465 lines not on this page · raw message
lib/zstd/compress/zstd_double_fast.c new file +521 -0
521 lines not on this page · raw message
lib/zstd/compress/zstd_double_fast.h new file +32 -0
Lines of this file are not shown. View the raw message.
lib/zstd/compress/zstd_fast.c new file +496 -0
496 lines not on this page · raw message
lib/zstd/compress/zstd_fast.h new file +31 -0
Lines of this file are not shown. View the raw message.
lib/zstd/compress/zstd_lazy.c new file +1138 -0
1,138 lines not on this page · raw message
lib/zstd/compress/zstd_lazy.h new file +61 -0
61 lines not on this page · raw message
lib/zstd/compress/zstd_ldm.c new file +619 -0
619 lines not on this page · raw message
lib/zstd/compress/zstd_ldm.h new file +104 -0
104 lines not on this page · raw message
lib/zstd/compress/zstd_opt.c new file +1200 -0
1,200 lines not on this page · raw message
lib/zstd/compress/zstd_opt.h new file +50 -0
50 lines not on this page · raw message
lib/zstd/decompress.c deleted +0 -2599
2,599 lines not on this page · raw message
lib/zstd/decompress/huf_decompress.c new file +1205 -0
1,205 lines not on this page · raw message
lib/zstd/decompress/zstd_ddict.c new file +241 -0
241 lines not on this page · raw message
lib/zstd/decompress/zstd_ddict.h new file +44 -0
44 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress.c new file +1836 -0
1,836 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress_block.c new file +1540 -0
1,540 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress_block.h new file +62 -0
62 lines not on this page · raw message
lib/zstd/decompress/zstd_decompress_internal.h new file +195 -0
195 lines not on this page · raw message
lib/zstd/entropy_common.c deleted +0 -243
243 lines not on this page · raw message
lib/zstd/error_private.h deleted +0 -53
53 lines not on this page · raw message
lib/zstd/fse.h deleted +0 -575
575 lines not on this page · raw message
lib/zstd/fse_compress.c deleted +0 -795
795 lines not on this page · raw message
lib/zstd/fse_decompress.c deleted +0 -325
325 lines not on this page · raw message
lib/zstd/huf.h deleted +0 -212
212 lines not on this page · raw message
lib/zstd/huf_compress.c deleted +0 -772
772 lines not on this page · raw message
lib/zstd/huf_decompress.c deleted +0 -960
960 lines not on this page · raw message
lib/zstd/mem.h deleted +0 -151
151 lines not on this page · raw message
lib/zstd/zstd.h +1984 -1037
3,021 lines not on this page · raw message
lib/zstd/zstd_common.c deleted +0 -75
75 lines not on this page · raw message
lib/zstd/zstd_compress_module.c new file +206 -0
206 lines not on this page · raw message
lib/zstd/zstd_decompress_module.c new file +122 -0
122 lines not on this page · raw message
lib/zstd/zstd_internal.h deleted +0 -274
274 lines not on this page · raw message
lib/zstd/zstd_opt.h deleted +0 -1014
1,014 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 8 lines
2.29.2 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Part of the diff is not shown here. View the raw message.
kernel test robot
build botRe: [PATCH v6 3/3] lib: zstd: Upgrade to latest upstream zstd version 1.4.6
Thank you for the patch! Perhaps something to improve:
Hi Nick,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on cryptodev/master]
[also build test WARNING on kdave/for-next f2fs/dev-test kees/for-next/pstore linus/master v5.10-rc6] [cannot apply to crypto/master squashfs/master next-20201201]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Nick-Terrell/Update-to-zstd-1-4-6/20201203-043418 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master config: parisc-allyesconfig (attached as .config) compiler: hppa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1ae5d159649a18815c67be65c370f7fd90e59e9f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nick-Terrell/Update-to-zstd-1-4-6/20201203-043418 git checkout 1ae5d159649a18815c67be65c370f7fd90e59e9f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
lib/zstd/compress/zstd_double_fast.c: In function 'ZSTD_compressBlock_doubleFast_extDict_generic':
>> lib/zstd/compress/zstd_double_fast.c:501:1: warning: the frame size of 3724 bytes is larger than 1280 bytes [-Wframe-larger-than=]
501 | }
| ^
lib/zstd/compress/zstd_double_fast.c: In function 'ZSTD_compressBlock_doubleFast':
lib/zstd/compress/zstd_double_fast.c:336:1: warning: the frame size of 3792 bytes is larger than 1280 bytes [-Wframe-larger-than=]
336 | }
| ^
lib/zstd/compress/zstd_double_fast.c: In function 'ZSTD_compressBlock_doubleFast_dictMatchState':
lib/zstd/compress/zstd_double_fast.c:356:1: warning: the frame size of 3808 bytes is larger than 1280 bytes [-Wframe-larger-than=]
356 | }
| ^
--
lib/zstd/compress/zstd_fast.c: In function 'ZSTD_compressBlock_fast_extDict_generic':
>> lib/zstd/compress/zstd_fast.c:476:1: warning: the frame size of 2736 bytes is larger than 1280 bytes [-Wframe-larger-than=]
476 | }
| ^
lib/zstd/compress/zstd_fast.c: In function 'ZSTD_compressBlock_fast':
lib/zstd/compress/zstd_fast.c:204:1: warning: the frame size of 1508 bytes is larger than 1280 bytes [-Wframe-larger-than=]
204 | }
| ^
lib/zstd/compress/zstd_fast.c: In function 'ZSTD_compressBlock_fast_dictMatchState':
lib/zstd/compress/zstd_fast.c:372:1: warning: the frame size of 1540 bytes is larger than 1280 bytes [-Wframe-larger-than=]
372 | }
| ^vim +501 lib/zstd/compress/zstd_double_fast.c
357
358
359 static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
360 ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
361 void const* src, size_t srcSize,
362 U32 const mls /* template */)
363 {
364 ZSTD_compressionParameters const* cParams = &ms->cParams;
365 U32* const hashLong = ms->hashTable;
366 U32 const hBitsL = cParams->hashLog;
367 U32* const hashSmall = ms->chainTable;
368 U32 const hBitsS = cParams->chainLog;
369 const BYTE* const istart = (const BYTE*)src;
370 const BYTE* ip = istart;
371 const BYTE* anchor = istart;
372 const BYTE* const iend = istart + srcSize;
373 const BYTE* const ilimit = iend - 8;
374 const BYTE* const base = ms->window.base;
375 const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
376 const U32 lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, cParams->windowLog);
377 const U32 dictStartIndex = lowLimit;
378 const U32 dictLimit = ms->window.dictLimit;
379 const U32 prefixStartIndex = (dictLimit > lowLimit) ? dictLimit : lowLimit;
380 const BYTE* const prefixStart = base + prefixStartIndex;
381 const BYTE* const dictBase = ms->window.dictBase;
382 const BYTE* const dictStart = dictBase + dictStartIndex;
383 const BYTE* const dictEnd = dictBase + prefixStartIndex;
384 U32 offset_1=rep[0], offset_2=rep[1];
385
386 DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_extDict_generic (srcSize=%zu)", srcSize);
387
388 /* if extDict is invalidated due to maxDistance, switch to "regular" variant */
389 if (prefixStartIndex == dictStartIndex)
390 return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, mls, ZSTD_noDict);
391
392 /* Search Loop */
393 while (ip < ilimit) { /* < instead of <=, because (ip+1) */
394 const size_t hSmall = ZSTD_hashPtr(ip, hBitsS, mls);
395 const U32 matchIndex = hashSmall[hSmall];
396 const BYTE* const matchBase = matchIndex < prefixStartIndex ? dictBase : base;
397 const BYTE* match = matchBase + matchIndex;
398
399 const size_t hLong = ZSTD_hashPtr(ip, hBitsL, 8);
400 const U32 matchLongIndex = hashLong[hLong];
401 const BYTE* const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase : base;
402 const BYTE* matchLong = matchLongBase + matchLongIndex;
403
404 const U32 curr = (U32)(ip-base);
405 const U32 repIndex = curr + 1 - offset_1; /* offset_1 expected <= curr +1 */
406 const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
407 const BYTE* const repMatch = repBase + repIndex;
408 size_t mLength;
409 hashSmall[hSmall] = hashLong[hLong] = curr; /* update hash table */
410
411 if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
412 & (repIndex > dictStartIndex))
413 && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
414 const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
415 mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
416 ip++;
417 ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
418 } else {
419 if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
420 const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
421 const BYTE* const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
422 U32 offset;
423 mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, prefixStart) + 8;
424 offset = curr - matchLongIndex;
425 while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
426 offset_2 = offset_1;
427 offset_1 = offset;
428 ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
429
430 } else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
431 size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
432 U32 const matchIndex3 = hashLong[h3];
433 const BYTE* const match3Base = matchIndex3 < prefixStartIndex ? dictBase : base;
434 const BYTE* match3 = match3Base + matchIndex3;
435 U32 offset;
436 hashLong[h3] = curr + 1;
437 if ( (matchIndex3 > dictStartIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) {
438 const BYTE* const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
439 const BYTE* const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
440 mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, prefixStart) + 8;
441 ip++;
442 offset = curr+1 - matchIndex3;
443 while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */
444 } else {
445 const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
446 const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
447 mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
448 offset = curr - matchIndex;
449 while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
450 }
451 offset_2 = offset_1;
452 offset_1 = offset;
453 ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
454
455 } else {
456 ip += ((ip-anchor) >> kSearchStrength) + 1;
457 continue;
458 } }
459
460 /* move to next sequence start */
461 ip += mLength;
462 anchor = ip;
463
464 if (ip <= ilimit) {
465 /* Complementary insertion */
466 /* done after iLimit test, as candidates could be > iend-8 */
467 { U32 const indexToInsert = curr+2;
468 hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
469 hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
470 hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
471 hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
472 }
473
474 /* check immediate repcode */
475 while (ip <= ilimit) {
476 U32 const current2 = (U32)(ip-base);
477 U32 const repIndex2 = current2 - offset_2;
478 const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
479 if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
480 & (repIndex2 > dictStartIndex))
481 && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
482 const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
483 size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
484 U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
485 ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
486 hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
487 hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
488 ip += repLength2;
489 anchor = ip;
490 continue;
491 }
492 break;
493 } } }
494
495 /* save reps for next block */
496 rep[0] = offset_1;
497 rep[1] = offset_2;
498
499 /* Return the last literals size */
500 return (size_t)(iend - anchor);
> 501 }502
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v6 3/3] lib: zstd: Upgrade to latest upstream zstd version 1.4.6
Quoted 4 lines · kernel test robot
All warnings (new ones prefixed by >>):
lib/zstd/compress/zstd_double_fast.c: In function 'ZSTD_compressBlock_doubleFast_extDict_generic':Quoted 1 line
Quoted 1 line
lib/zstd/compress/zstd_double_fast.c:501:1: warning: the frame size of 3724 bytes is larger than 1280 bytes [-Wframe-larger-than=]
Frame size 3724?
Quoted 2 lines
lib/zstd/compress/zstd_double_fast.c: In function 'ZSTD_compressBlock_doubleFast':
lib/zstd/compress/zstd_double_fast.c:336:1: warning: the frame size of 3792 bytes is larger than 1280 bytes [-Wframe-larger-than=]
3792
Quoted 2 lines
lib/zstd/compress/zstd_double_fast.c: In function 'ZSTD_compressBlock_doubleFast_dictMatchState':
lib/zstd/compress/zstd_double_fast.c:356:1: warning: the frame size of 3808 bytes is larger than 1280 bytes [-Wframe-larger-than=]
3808
Quoted 2 lines
lib/zstd/compress/zstd_fast.c: In function 'ZSTD_compressBlock_fast_extDict_generic':Quoted 1 line
Quoted 1 line
lib/zstd/compress/zstd_fast.c:476:1: warning: the frame size of 2736 bytes is larger than 1280 bytes [-Wframe-larger-than=]
2736
Quoted 2 lines
lib/zstd/compress/zstd_fast.c: In function 'ZSTD_compressBlock_fast':
lib/zstd/compress/zstd_fast.c:204:1: warning: the frame size of 1508 bytes is larger than 1280 bytes [-Wframe-larger-than=]
1508
Quoted 2 lines
lib/zstd/compress/zstd_fast.c: In function 'ZSTD_compressBlock_fast_dictMatchState':
lib/zstd/compress/zstd_fast.c:372:1: warning: the frame size of 1540 bytes is larger than 1280 bytes [-Wframe-larger-than=]
1540
For userspace code it's nothing but in kernel it's a lot for a single function. The largest number is almost one page, there were days where this would be one half of the whole stack space. We can't waste precious resources like that. Taking the userspace code as-is does not seem to work.