When possible, clone files on Linux and FreeBSD.#1736
Conversation
This change adds support for file cloning on Linux and FreeBSD where supported by the underlying OS and filesystem. I don't have a great story for unit testing here as if either call fails, we'll fall back to block-based copying which, in the general case, will appear to the caller like a successful copy. Furthermore, our CI systems aren't configured with file systems that support file cloning anyway. Resolves #1727.
|
@swift-ci test |
|
@michael-yuji Mind taking a look? |
| #else | ||
| // Compiled against an older unistd.h, but presumably running on FreeBSD 15.0 | ||
| // or newer. SEE: https://github.com/freebsd/freebsd-src/blob/main/sys/sys/unistd.h | ||
| return 0x00800000; |
There was a problem hiding this comment.
We're building toolchains against FreeBSD 14.3's SDK right now, so the constant isn't defined yet.
|
Re. testing - is it possible to easily check in a unit test whether or not cloning is supported and whether or not two files are clones? I suspect the latter might be feasible but the former is probably non trivial, and if none of our CI environments have file systems that actually support this then the point is probably moot. Were you able to test locally on Linux and FreeBSD that it correctly creates a clone when running in an environment that supports it just to confirm we've tested it somewhere? |
|
I've tested the equivalent code in Swift Testing on local VMs. I'm not certain how to go about doing that for Foundation but maybe it's straightforward to do it as a package dependency? |
|
Verified in a VM that Note |
|
I can't figure out how to check reflinked extents on FreeBSD but the call succeeds at least. It's documented to fail with |
|
@swift-ci test |
jmschonfeld
left a comment
There was a problem hiding this comment.
Looks good overall, one organizational comment
|
@swift-ci test |
|
@swift-ci test |
michael-yuji
left a comment
There was a problem hiding this comment.
lgtm, I'm yet able to test it locally, but things looks right to me
Resolves #1727.
This change adds support for file cloning on Linux and FreeBSD where supported by the underlying OS and filesystem.
Motivation:
Cloning is generally faster than block-based or bit-by-bit copying, so if a platform supports it we should try to leverage it to improve overall I/O performance.
Modifications:
Added calls to the relevant API on Linux and FreeBSD. FreeBSD's API is new in 15.0, so there's a version check.
Result:
Ideally, faster file copies on these platforms!
Testing:
I don't have a great story for unit testing here as if either call fails, we'll fall back to block-based copying which, in the general case, will appear to the caller like a successful copy. Furthermore, our CI systems aren't configured with file systems that support file cloning anyway. I'm open to suggestions!