ZFS Compression: Difference between revisions

From Lustre Wiki
Jump to navigation Jump to search
m (sentence needed a 'the')
mNo edit summary
Line 1: Line 1:
ZFS supports transparent compression of data at the block level for datasets. Enabling compression can improve storage efficiency by decreasing the amount of data written to disk and improve read performance for large files, as less data needs to be read from disk.
ZFS supports transparent compression of data at the block level for datasets. Enabling compression can improve storage efficiency by decreasing the amount of data written to disk and improve read performance for large files, as less data needs to be read from disk.  The tradeoff is that compression consumes additional CPU resources on the Lustre server that imports a zfs dataset with compression enabled.


If desired, compression will need to be enabled individually for all relevant OSTs.
Compression is typically most beneficial for OSTs since this is where most of the filesystem data is stored.  Enabling compression for MDTs is safe, but there may not be as much benefit since most of the data on an MDT is file metadata which ZFS often compresses by default.  If you are using Data on MDT (DoM), then there may be a benefit to using compression since some file data is stored on the MDT.  The decision to enable or disable compression on OSTs will need to be evaluated by each site depending on their specific needs and performance requirements.  Since compression can be enabled/disabled without affecting exising data, it is easy to test both scenarios without the risk of data loss.
   
   
== Check ZFS compression ==


== Check ZFS compression ==
To check if compression is enabled for an OST, run:
   
   
<pre>zfs get compression <OST/dataset/here></pre>
<pre>zfs get compression <OST_dataset></pre>
 
Example output will look something like this:
 
[root@oss1][~]# zfs get compression lustre-OST0000
NAME          PROPERTY    VALUE          SOURCE
lustre-OST0000  compression  off            local
   
   
== Set ZFS compression ==
== Set ZFS compression ==


<pre>zfs set compression=on <OST/dataset/here></pre>
To enable compression, run:
 
<pre>zfs set compression=on <OST_dataset></pre>
   
   
turns on compression with the default algorithm (lz4 since ZFS version 0.6.5). You can chose values other than "on" for the compression algorithm, see 'man zfsprops' for details.
This turns on compression with the default algorithm (lz4 since ZFS version 0.6.5). Other compression algorithms are available, and a list of supported algorithms can be found by looking at the '''zfsprops''' man page.  To use a different algorithm, replace the '''compression=on''' option with '''compression=<algorithm>'''.  The '''lz4''' algorithm is likely the best choice for now. It has been tested extensively, and provides very good compression balanced with performance. It also implements an early abort feature<ref>https://github.com/openzfs/zfs/blob/e0bf43d64ed01285321bf6c3a308f699c5483efc/module/zfs/lz4_zfs.c#L520</ref>, meaning it stops trying to compress if initial compression results do not meet a threshold, so performance with incompressible data isn't degraded.
   
   
To use a different algorithm, use for example "compression=zstd" instead of "on".
== Check Compression Ratio ==
 
To check compression performance, the compression ratio can be queried on the Lustre server:


'''lz4''' is likely the best choice now. It has been tested extensively, and provides very good compression balanced with performance. It implements an early abort feature<ref>https://github.com/openzfs/zfs/blob/e0bf43d64ed01285321bf6c3a308f699c5483efc/module/zfs/lz4_zfs.c#L520</ref>, meaning it stops trying to compress if initial compression results do not meet a threshold, so performance with incompressible data isn't degraded.
<pre>zfs get compressratio <OST_dataset></pre>
== Check compression ratio ==


On OSS:  
From a user's perspective, the logical size and on-disk size of a file can be determined by running the following commands from a Lustre client:
<pre>zfs get compressratio <OST/dataset/here></pre>


On client machines:
# Check logical usage
<pre>du --apparent-size -h <file/dir></pre> will show logical usage of a file (in human readable units), whereas <pre>du -h <file></pre> will show actual usage on disk (in human readable units).
du --apparent-size -h <file>
# Check on-disk usage
du -h <file>


[[Category:ZFS]][[Category:Howto]]
[[Category:ZFS]][[Category:Howto]]

Revision as of 11:08, 30 April 2026

ZFS supports transparent compression of data at the block level for datasets. Enabling compression can improve storage efficiency by decreasing the amount of data written to disk and improve read performance for large files, as less data needs to be read from disk. The tradeoff is that compression consumes additional CPU resources on the Lustre server that imports a zfs dataset with compression enabled.

Compression is typically most beneficial for OSTs since this is where most of the filesystem data is stored. Enabling compression for MDTs is safe, but there may not be as much benefit since most of the data on an MDT is file metadata which ZFS often compresses by default. If you are using Data on MDT (DoM), then there may be a benefit to using compression since some file data is stored on the MDT. The decision to enable or disable compression on OSTs will need to be evaluated by each site depending on their specific needs and performance requirements. Since compression can be enabled/disabled without affecting exising data, it is easy to test both scenarios without the risk of data loss.

Check ZFS compression

To check if compression is enabled for an OST, run:

zfs get compression <OST_dataset>

Example output will look something like this:

[root@oss1][~]# zfs get compression lustre-OST0000
NAME           PROPERTY     VALUE           SOURCE
lustre-OST0000  compression  off             local

Set ZFS compression

To enable compression, run:

zfs set compression=on <OST_dataset>

This turns on compression with the default algorithm (lz4 since ZFS version 0.6.5). Other compression algorithms are available, and a list of supported algorithms can be found by looking at the zfsprops man page. To use a different algorithm, replace the compression=on option with compression=<algorithm>. The lz4 algorithm is likely the best choice for now. It has been tested extensively, and provides very good compression balanced with performance. It also implements an early abort feature[1], meaning it stops trying to compress if initial compression results do not meet a threshold, so performance with incompressible data isn't degraded.

Check Compression Ratio

To check compression performance, the compression ratio can be queried on the Lustre server:

zfs get compressratio <OST_dataset>

From a user's perspective, the logical size and on-disk size of a file can be determined by running the following commands from a Lustre client:

# Check logical usage
du --apparent-size -h <file>

# Check on-disk usage
du -h <file>