Enabling ZFS compression
As you remember, I decided to try ZFS on Ubuntu 20.04 last month. It’s a small server with no production load, just about powerful enough for small experiments.
Today I’m going to show you one another performance impacting setting: ZFS compression.
Compression in ZFS is a pretty neat feature: it compresses your files on the fly and therefore lets you store more data using limited storage.
At any time time you can request ZFS compression stats per ZFS pool or volume and it will show you exactly how much space you’re saving.
For example, I get to store more than 3 times more journald logs on an ZFS compressed volume compared to a standard filesystem (look at the compressration value):
Obviously, the biggest benefit of ZFS compression is that you can save quite a bit of space. May large files on your server or desktop are probably going to compress very well, so why waste the space?
Here are some of the files that will be perfect for the ZFS compression scenario:
Like all good things, ZFS compression comes with a cost - specifically, with extra CPU cycles needed to compress and uncompress ZFS data. My take on this is that on desktop system ZFS compression is definitely a great idea - you’re rarely maxing out CPU to the extend that ZFS compression would be noticeable, but benefits of optimising precious SSD storage space are great.
On smaller systems like some of my embedded servers I use for remote RSyslog, this may be a deal breaker: the amount of logs coming in may be high enough to spike CPU usage beyond the comfort level.
Get ZFS parameters for your pool or volume and grep for the compress word:
If there’s no compression enabled for your volume, you’ll see a different picture:
There are multiple compression algos available for ZFS:
We’ll use the most common option, lz4 for now:
Disabling ZFS compression is quite easy:
One super important thing: when you’re enabling or disabling ZFS compression, you’re not actually changing any data on the ZFS filesystems. You’re changing the behaviour of ZFS going forward, meaning any future data will be subject to your settings, but your current data will stay as is.
I’m mentioning it because someday you’ll come across a similar scenario: ZFS compression is disabled, but compression ration is higher than 1.00x - this means data was compressed at some point in the past, and then ZFS compression was disabled:
That’s all I wanted to share with you today. Hope you’re finding ZFS interesting - let me know if you have any questions!