Wednesday 25 November 2009

ZFS Deduplication

People who don't want to wait for Solaris Express Community Edition b129 or OpenSolaris dev repository to be updated to b129 (b128 is not going to be released) can easily try ZFS deduplication now.

Blindingly Fast Upgrade (BFU) archives for build 128 are available here now. These archives are used mainly by the developers but we can use them easily for testing as well. Please note that your OpenSolaris installation is not going to be consistent after BFU'ing from the pkg(1)'s point of view. It is likely that pkg image-update will not be able to upgrade such system in the future. Be prepared to re-install your system. I usually try new archives in unimportant VirtualBox/VMware VMs. Here are the commands I have used to upgrade my test VM running OpenSolaris b127 to b128 (as root):

wget http://dlc.sun.com/osol/on/downloads/b128/SUNWonbld.i386.tar.bz2
wget http://dlc.sun.com/osol/on/downloads/b128/on-bfu-nightly-osol-nd.i386.tar.bz2

gtar jxf SUNWonbld.i386.tar.bz2
pkgadd -d onbld SUNWonbld
gtar jxf on-bfu-nightly-osol-nd.i386.tar.bz2

export FASTFS=/opt/onbld/bin/i386/fastfs
export BFULD=/opt/onbld/bin/i386/bfuld
export GZIPBIN=/usr/bin/gzip
export PATH=/opt/onbld/bin:/opt/onbld/bin/i386:$PATH

bfu `pwd`/archives-nightly-osol-nd/i386

/opt/onbld/bin/acr

Reboot the machine. Newly booted system will have deduplication support. To try ZFS deduplication you can either create new pool (that's what I did) or upgrade 'rpool' zpool's format:

zpool upgrade rpool

Let's enable deduplication:

zfs set dedup=on tank

And run some tests:

# for i in 0 1 2 3 4 5 6 7 8 9; do zfs create tank/fs$i; done
# for i in 0 1 2 3 4 5 6 7 8 9; do gtar jxf /root/on-bfu-nightly-osol-nd.i386.tar.bz2 -C /tank/fs$i; done

# zfs list -r tank
NAME USED AVAIL REFER MOUNTPOINT
tank 3.90G 77.8G 33K /tank
tank/fs0 399M 77.8G 399M /tank/fs0
tank/fs1 399M 77.8G 399M /tank/fs1
tank/fs2 399M 77.8G 399M /tank/fs2
tank/fs3 399M 77.8G 399M /tank/fs3
tank/fs4 399M 77.8G 399M /tank/fs4
tank/fs5 399M 77.8G 399M /tank/fs5
tank/fs6 399M 77.8G 399M /tank/fs6
tank/fs7 399M 77.8G 399M /tank/fs7
tank/fs8 399M 77.8G 399M /tank/fs8
tank/fs9 399M 77.8G 399M /tank/fs9

# zpool list tank
NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT
tank 79.5G 404M 79.1G 0% 10.00x ONLINE -

Tarball extracted ten times and only 404MB of disk space allocated. 10x deduplication ratio. Nice. This gets even more interesting after enabling compression:

# zfs get dedup,compression tank
NAME PROPERTY VALUE SOURCE
tank dedup on local
tank compression on local

# zfs list -r tank
NAME USED AVAIL REFER MOUNTPOINT
tank 2.28G 78.0G 33K /tank
tank/fs0 234M 78.0G 234M /tank/fs0
tank/fs1 234M 78.0G 234M /tank/fs1
tank/fs2 234M 78.0G 234M /tank/fs2
tank/fs3 234M 78.0G 234M /tank/fs3
tank/fs4 234M 78.0G 234M /tank/fs4
tank/fs5 234M 78.0G 234M /tank/fs5
tank/fs6 234M 78.0G 234M /tank/fs6
tank/fs7 234M 78.0G 234M /tank/fs7
tank/fs8 234M 78.0G 234M /tank/fs8
tank/fs9 234M 78.0G 234M /tank/fs9

# zpool list tank
NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT
tank 79.5G 239M 79.3G 0% 10.00x ONLINE -

239MB allocated. Excellent!