Introduce ZSTD compression to ZFS
github.com
github.com
W.r.t. to ZSTD: The usual thing is to provide a zlib compatible API, which ZSTD does ( https://github.com/facebook/zstd/tree/dev/zlibWrapper ). But the ZSTD zlib compatibility layer causes lower performance, so it is better to use it directly. Maybe all future compression algorithms can provide a ZSTD compatible API, so we have to do less work in the future?
Could it? That doesn't sound very portable, and ZFS works on FreeBSD too.
Frequently Asked Questions
“Q: Why is it so many lines of code, I can't review all of that...
A: Most of this code is the ZSTD library, which has not been altered.”
One reason this needs testing because this is a file system. If it breaks, it can lose you much more data than the file being worked on.
There also may be serious performance degradation on hardware or configurations the developers didn’t look at.
There also is some new code added to call the zstd library.
Because filesystems need to store compression metadata and compressor settings differently than individual archive streams do. Because of the way ZFS stores configuration like this, in the previous version of these patches, they had to choose a subset of the available compression levels when adding zstd support.
Different compressors and decompressors also have different state sizes for different settings. Allocating, reusing, and discarding buffers for compression/decompression state in a sensible way inside an operating system kernel is not trivial.
For something that is write-once read-many-times, like a filesystem, a good compression algorithm might be more interesting in the future. lz4 is more targeted at write-once read-once, like file transfers for example
From a quick read, ZSTD looks more about saving space while keeping reasonable speeds, both at write and read.
And I'd assume there are other algorithms that focus only on size, trading speed for it.
- If you mean that the same archive will be distributed to many peers, such as is the case in package distribution, then in practice archives will be read only once by each process, so one "slow" compression will translate into significant gains in added decompression speed. That's the reason Archlinux switched to zstd for its packages (https://www.archlinux.org/news/now-using-zstandard-instead-o...)
- If you mean that the same archive will be read multiple times by the same machine, I don't really know what kind of scenario that is; I'd deflate the archive into its initial representation once and then let processes access that folder directly. Note that zstd claims that it isn't that much slower in decompression than competitors, even if you always use compressed archives the difference will be minimal
zstd was built more or less to "replace" all formats that favor compression over speed. From their benchmarks (which means what it means) whatever the compression/speed ratio you want, zstd is going to be better than all of them, with a hard exception on extremely fast speed that is still the kingdom of lz4.
From my understanding (but please correct me if I am wrong), LZ4 will decompress them significantly faster than ZSTD even if the latter compresses more.
In other words, the decompression speed is measured on the decompressed data, right?
If your disks are faster than your decompression algorithm when that algorithm is running alongside the rest of your workload (generally not the case) then it can make sense to use the faster decompressor (lz4). In my understanding of the tradeoffs of zstd though, having used it recently in an application, chances are you have a free hardware thread that can saturate your disk without affecting your compute workload.
But perhaps for your data files that you don't open often, ZSTD is best because you save space on the SSD.
That depends on how concurrent boot is, and how fast your CPU and memory are. It may be true on a Celeron, but maybe not on a ThreadRipper.
Furthermore, if you look at the performance testing, the sequential read performance was almost always better with zstd than with lz4, in ZFS; and the zstd-fast mode was about as fast as the lz4 mode in sequential writes. This may be a matter of their specific integration of lz4, but nonetheless it pays to look at the actual numbers before drawing conclusions.
Edit: Arch Linux switched from xz to ZSTD for their package manager and somebody compared both: https://sysdfree.wordpress.com/2020/01/04/293/
The Arch Linux developers state that they expect an 0.8% you increase in package size but an 1300% speedup in decompression. Not too shabby.
I'm running Arch on my personal system and it's really noticable, especially when I create by own packages, compression doesn't take longer than compiling anymore.
However in all cases zstd is much faster for decompression. It just happens that getting the best compression ratio in a not insane amount of time is still the better tradeoff for us.
2015- Jagiellonian University, Institute of Computer Science, assistant professor,
2013-2014 Purdue University, NSF Center for Science of Information, Postdoctoral researcher (webpage),
2006-2012 Jagiellonian University, Cracow, PhD in Theoretical Physics (thesis)
2004-2010 Jagiellonian University, Cracow, PhD in Theoretical Computer Science (thesis)
2001-2006 Jagiellonian University, Cracow, MSc in Theoretical Physics (thesis)
2000-2005 Jagiellonian University, Cracow, MSc in Theoretical Mathematics (thesis)
1999-2004 Jagiellonian University, Cracow, MSc in Computer Science (thesis)
zstd is more likely to represent an obsolescence of gzip. It surpasses gzip pretty much always.
I don't know if ZFS supports variable compression levels (maybe per dataset), but Btrfs ZSTD support uses a mount option, e.g. mount -o compress=zstd:[1-15]
Thus it's possible to use a higher level (high compression ratio, slower speed, more CPU and RAM) for e.g. an initial archive. And later use a lower level (or even no compression) when doing updates. Writes use the compression algorithm and level set at mount time; and it's possible to change it while remaining mounted, using -o remount.
> Thus it's possible to use a higher level (high compression ratio, slower speed, more CPU and RAM) for e.g. an initial archive. And later use a lower level (or even no compression) when doing updates.
yup. works the same in ZFS. you can change the compression setting any time you like, for future writes.