ZFS's zstd compression ratio is much less than /usr/bin/zstd #11293
-
System information
Describe the problem you're observingzstd compression within ZFS generates far less compression than /usr/bin/zstd for a single 1GB file test. Describe how to reproduce the problemCreate a compressible 1G file in /dev/shm and compare the results of running /usr/bin/lz4 and /usr/bin/zstd versus copying that file to ZFS filesystems with the same compression algorithms enabled.
so far so good with zstd outperforming lz4 within ZFS. However, while /usr/bin/lz4 reports similar compression to ZFS+lz4, /usr/bin/zstd outperforms ZFS+zstd by a significant amount (300% vs 17%)
What am I doing wrong? Include any warning/errors/backtraces from the system logs--> |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 1 reply
-
What is the compression block of the standalone zstd tool? Have you tries to set at least recordsize=1m for the datasets? |
Beta Was this translation helpful? Give feedback.
-
Changing /usr/bin/zstd block size from the default of "no split" to 16k makes very little difference,
However, setting recordsize=1m generates makes a significant difference and ZFS achieves essentially the same level of compression as /usr/bin/zstd (both with a default level of 3 as I understand the documentation),
Looks like I need to run some larger scale tests to tune the value of recordsize for my application. And I don't understand what /usr/bin/zstd -B does since I get the exact same compression for -B# for a few different values (including 1!), but it is different than not setting it at all,
|
Beta Was this translation helpful? Give feedback.
-
FWIW, here are the compression values for recordsize=256k
and recordsize=512k
and almost no compression for recordisize=64k
|
Beta Was this translation helpful? Give feedback.
-
It appears that zstd is much more sensitive to recordsize than lz4, e.g., lz4 with recordsize=1m makes very little difference over the default value of 128k
|
Beta Was this translation helpful? Give feedback.
-
Given the significant dependency of
Of course even better would be if ZFS would auto-tune for this. What is the downside of running ta raditional home directory dataset with |
Beta Was this translation helpful? Give feedback.
-
Large recordsize is good for files that are written and read sequentially or in respectively large chunks, but it is pretty bad for random access, especially random rewrite, causing read/write inflation and read-modify-write patterns. Files that are smaller than recordsize are stored as-is, so file size is not a big factor for recordsize, but obviously setting it above the typical file size makes no difference. |
Beta Was this translation helpful? Give feedback.
-
It very much depends on your specific test file. If you are choosing parameters for your home directory -- copy there your real home directory and see what happen. No any artificial test file give you the right answer, since it does not represent your specific case. |
Beta Was this translation helpful? Give feedback.
-
You could also have a look on this issue #10201 . Your test file might not satisfying ZFS' "criteria" for compression. |
Beta Was this translation helpful? Give feedback.
-
Some background info on ZSTD: The compression results of those two is not 1-to-1 comparable or at least will vary significantly depending on the recordsize set in ZFS. Why? Because compression logic gets more efficient the more data it has too compress. Due to above reasons, it's always best to compare compression algorithms through zfs. Because you can't ignore the effect of the ZFS codestack itself on compression.
LZ4 simply has a terrible upper compression limit. That kinda makes it hard to compare the effect of recordsize between the two, it's two totally different algorithms with totally difference compression curves (performance/ratio and recordsize/ratio).
Thats true, it's prefered to use some sort of highly compressible non-generated standardised testfile like enwik9. Also to enable others to repeat your tests, but also to ensure there isn't any correlation between your file generation script and the compressor. TLDR: |
Beta Was this translation helpful? Give feedback.
-
I also did some tests. Increasing the recordsize from 128K to 1M also increased the compressratio from 1.36x to 1.58x. |
Beta Was this translation helpful? Give feedback.
-
It would be nice if it was possible to zfs send recordsize=128k to zfs receive recordsize=1M for efficient disk backups, which I attempted to capture in #11313. |
Beta Was this translation helpful? Give feedback.
-
A detailed explanation that I've concluded to over 10 years ago: |
Beta Was this translation helpful? Give feedback.
Some background info on ZSTD:
Simply put: in normal ZSTD compression, zstd handles all aspects of compression. From cutting your file into blocks, compressing them and so forth.
With ZSTD on ZFS, Only the ZSTD compression function is run over the blocks that are generated by ZFS.
The compression results of those two is not 1-to-1 comparable or at least will vary significantly depending on the recordsize set in ZFS. Why? Because compression logic gets more efficient the more data it has too compress.
Due to above reasons, it's always best to compare compression algorithms through zfs. Because you can't ignore the effect of the ZFS codestack itself on compression.