# zfs default compression algorithm



## apkfdo (Jan 16, 2017)

I'm a bit confused as to what compression my system uses

From man zfs():

```
compression=on | off | lzjb | gzip | gzip-N | zle | lz4
         Controls the compression algorithm used for this dataset.  Setting
         compression to on indicates that the current default compression
         algorithm should be used.  The default balances compression and
         decompression speed, with compression ratio and is expected to work
         well on a wide variety of workloads.  Unlike all other settings for
         this property, on does not select a fixed compression type.  As new
         compression algorithms are added to ZFS and enabled on a pool, the
         default compression algorithm may change.  The current default
         compression algorthm is either lzjb or, if the lz4_compress feature
         is enabled, lz4.  The lzjb compression algorithm is optimized for
         performance while providing decent data compression. Setting
         compression to on uses the lzjb compression algorithm. The gzip
         compression algorithm uses the same compression as the gzip(1)
         command. You can specify the gzip level by using the value gzip-N
         where N is an integer from 1 (fastest) to 9 (best compression ratio).
         Currently, gzip is equivalent to gzip-6 (which is also the default
         for gzip(1)).  The zle compression algorithm compresses runs of
         zeros.
```

So it says: `Setting compression to on indicates that the current default compression algorithm should be used.`

A bit further down: `The current default compression algorthm is either lzjb or, if the lz4_compress feature is enabled, lz4.`

I'm not sure if this is the correct way to check but I did:

```
# zpool get all mypool | grep lz4
mypool  feature@lz4_compress           active                         local
```
I assume active=enabled

But then I read from the man page again a bit further down it says: `Setting compression to on uses the lzjb compression algorithm.`

Is this a contradiction in the man page, or am I missing something?


----------



## ASX (Jan 17, 2017)

If I'm not wrong LZ4 compression was added on later versions of ZFS, that's why the default may be different (basically depending on ZFS pool version).

Also, compression may be enabled on a per dataset basis, you may find useful `zfs get all | grep compression`


----------



## SirDice (Jan 17, 2017)

ASX said:


> Also, compression may be enabled on a per dataset basis, you may find useful `zfs get all | grep compression`


Yeah, you may want to enable it on certain datasets (/usr/ports for example) but not on others (/usr/ports/distfiles for example). It highly depends on the type of data that's stored in that dataset.

The /var/log directory is also a good one to compress. If you do use compression on the dataset turn off the compression of the 'old' log files in newsyslog.conf(5). A nice side effect is that all logs are available uncompressed and still take up very little storage space.


----------

