1 # ZSTD-On-ZFS Library Manual
5 This subtree contains the ZSTD library used in ZFS. It is heavily cut-down by
6 dropping any unneeded files, and combined into a single file, but otherwise is
7 intentionally unmodified. Please do not alter the file containing the zstd
8 library, besides upgrading to a newer ZSTD release.
12 * `zfs_zstd.c` is the actual `zzstd` kernel module.
13 * `lib/` contains the the unmodified, [_"amalgamated"_](https://github.com/facebook/zstd/blob/dev/contrib/single_file_libs/README.md)
14 version of the `Zstandard` library, generated from our template file
15 * `zstd-in.c` is our template file for generating the library
16 * `include/`: This directory contains supplemental includes for platform
17 compatibility, which are not expected to be used by ZFS elsewhere in the
18 future. Thus we keep them private to ZSTD.
22 To update ZSTD the following steps need to be taken:
24 1. Grab the latest release of [ZSTD](https://github.com/facebook/zstd/releases).
25 2. Update `module/zstd/zstd-in.c` if required. (see
26 `zstd/contrib/single_file_libs/zstd-in.c` in the zstd repository)
27 3. Generate the "single-file-library" and put it to `module/zstd/lib/`.
28 4. Copy the following files to `module/zstd/lib/`:
30 - `zstd/lib/common/zstd_errors.h`
32 This can be done using a few shell commands from inside the zfs repo:
37 url="https://github.com/facebook/zstd"
38 release="$(curl -s "${url}"/releases/latest | grep -oP '(?<=v)[\d\.]+')"
39 zstd="/tmp/zstd-${release}/"
41 wget -O /tmp/zstd.tar.gz \
42 "${url}/releases/download/v${release}/zstd-${release}.tar.gz"
43 tar -C /tmp -xzf /tmp/zstd.tar.gz
45 cp ${zstd}/lib/zstd.h module/zstd/lib/
46 cp ${zstd}/lib/zstd_errors.h module/zstd/lib/
47 ${zstd}/contrib/single_file_libs/combine.sh \
48 -r ${zstd}/lib -o module/zstd/lib/zstd.c module/zstd/zstd-in.c
51 Note: if the zstd library for zfs is updated to a newer version,
52 the macro list in include/zstd_compat_wrapper.h usually needs to be updated.
53 this can be done with some hand crafting of the output of the following
54 script: nm zstd.o | awk '{print "#define "$3 " zfs_" $3}' > macrotable
57 ## Altering ZSTD and breaking changes
59 If ZSTD made changes that break compatibility or you need to make breaking
60 changes to the way we handle ZSTD, it is required to maintain backwards
63 We already save the ZSTD version number within the block header to be used
64 to add future compatibility checks and/or fixes. However, currently it is
65 not actually used in such a way.