ZFS basics: enable or disable compression

Enabling ZFS compression 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.

What is 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):

newvol  compressratio         3.29x                  -
newvol  compression           lz4                    local
newvol  refcompressratio      3.29x                  -

Why use ZFS compression?

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:

  • ISO images for new OS releases (don’t know about you, but I download them almost daily)
  • VM images for VirtualBox, KVM or any other solution
  • Docker container images
  • Large volumes of application or server logs

Why disable compression?

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.

How To Check ZFS compression

Get ZFS parameters for your pool or volume and grep for the compress word:

root@server:/var/log/journal # zfs get all newvol | grep compress
newvol  compressratio         3.29x                  -
newvol  compression           lz4                    local
newvol  refcompressratio      3.29x                  -

If there’s no compression enabled for your volume, you’ll see a different picture:

root@server:/var/log/journal # zfs get all newvol | grep compress
newvol  compressratio         1.00x                  -
newvol  compression           off                    local
newvol  refcompressratio      1.00x                  -

How To Enable ZFS compression

There are multiple compression algos available for ZFS:

        compression     YES      YES   on | off | lzjb | gzip | gzip-[1-9] | zle | lz4

We’ll use the most common option, lz4 for now:

root@server:~ # zfs set compression=lz4 newvol

How To Disable ZFS Compression

Disabling ZFS compression is quite easy:

root@server:~ # zfs set compression=off newvol

ZFS Compression Works Only for Future Data

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:

root@server:/var/log/journal # zfs get all newvol | grep compress
newvol  compressratio         3.29x                  -
newvol  compression           off                    local
newvol  refcompressratio      3.29x                  -

That’s all I wanted to share with you today. Hope you’re finding ZFS interesting - let me know if you have any questions!

See Also




Contact Me

Follow me on Facebook, Twitter or Telegram:
Recommended
I learn with Educative: Educative
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!
Recent Articles
03 Sep 2024

macOS Sequoia 15.0

02 Sep 2024

Video: Has This Worked Before?

24 Mar 2024

Homelab: Mac Pro 2013 32GB

Recent Tweets