unison icon indicating copy to clipboard operation
unison copied to clipboard

Do reflink (COW) copy if possible

Open tleedjarv opened this issue 4 years ago • 3 comments

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 APFS
  • ioctl FICLONE on Linux (kernel >= 4.5); several filesystems are supported, at least BTRFS and XFS (also BTRFS_IOC_CLONE since Linux 2.6.29(?) should work)
  • copy_file_range(2) on Linux (kernel >= 4.5) and FreeBSD >= 13
  • sendfile(2) on Linux (kernel >= 2.2) and sendfile(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.

tleedjarv avatar Aug 20 '21 09:08 tleedjarv

Rebased, with minor fixes and improvements.

tleedjarv avatar Mar 20 '23 19:03 tleedjarv

Included copy_file_range(2) support for FreeBSD >= 13.

tleedjarv avatar Mar 23 '23 15:03 tleedjarv

FWIW, I think macOS < 10.13 is totally irrelevant now.

gdt avatar Apr 16 '23 13:04 gdt