unison
unison copied to clipboard
Do reflink (COW) copy if possible
This is an interesting experiment which, if deemed safe and working properly, can potentially offer huge gains in some situations.
This patch makes use of various OS and filesystem-specific syscalls to accelerate local file copies, making so-called reflink (COW) copies, if possible.
The following syscalls are tried:
clonefile(2)on macOS (version >= 10.12); supported on APFSioctl FICLONEon Linux (kernel >= 4.5); several filesystems are supported, at least BTRFS and XFS (alsoBTRFS_IOC_CLONEsince Linux 2.6.29(?) should work)copy_file_range(2)on Linux (kernel >= 4.5) and FreeBSD >= 13sendfile(2)on Linux (kernel >= 2.2) andsendfile(3ext)on Solaris
Fallback to read-write loop (the current copy function) is used if none of the above are available or supported by the filesystem.
The first three bullets provide special optimizations, while sendfile() is more of a question mark. It's supposedly more efficient due to not having to move data to userspace but I don't know if it results in any practical gains here.
Compilation on OS X < 10.12 is still possible but binaries produced by GHA CI will not be able to run on those versions. I don't know if it's going to be a problem for users.
Rebased, with minor fixes and improvements.
Included copy_file_range(2) support for FreeBSD >= 13.
FWIW, I think macOS < 10.13 is totally irrelevant now.