Fast copies with Solaris 11.4

Oracle 11.4 got two new functions called reflink and reflinkat. It’s seems to be a rather small change, but it has quite some importance. The man page explains:

The  reflink()  function  creates the file named by path2 with the contents of the file named by path1. The reflink() function does not  read or  write  the  underlying  data blocks. The path1 argument points to a path name naming an existing file. The path2 argument points to a  path name naming the new directory entry to be created

This creates a copy of the file without actually reading and writing it. However both files are independent afterwards. You can write into a file without changing this copy. So it’s not just a symbolic link or something like that. Think of it like a ZFS snapshot, just file level. Important to know: It only works this way when both files are in the same ZFS pool.

Okay, how do you use this function? Well, you don’t have to write your own application, easiest way is to use cp -z. At first i try a normal copy. It’s the second run.

root@batou:/testpool/limited# time cp testfile testfile2

real    0m2,362s
user    0m0,003s
sys     0m1,295s

Now we add the -z option.

root@batou:/testpool/limited# time cp -z testfile testfile3

real    0m6,386s
user    0m0,001s
sys     0m0,221s

What .. it takes longer? Fast copy? Well, this command does a lot in the background in order to enable future speedups. Because when you try it a second time, the number looks differently.

root@batou:/testpool/limited# time cp -z testfile testfile4

real    0m0,098s
user    0m0,001s
sys     0m0,020s

Significantly faster. So … where you can use this feature. It’s not for copying a file a single time, as the first copy is slower. However if you copy large VMs contained in your deployment process quite often , this is an extremely fast way to clone you environments, saving disk space and compute/io resources on the way. Another example would be coping large database files for example to create developer environments.

Do you want to learn more? - reflink (3c)