RFR: 8266589: (fs) Improve performance of Files.copy() on macOS using copyfile(3)
Brian Burkhalter
bpb at openjdk.java.net
Thu May 6 16:15:52 UTC 2021
On Thu, 6 May 2021 13:19:18 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Please consider this request to use `fcopyfile(3)` to copy files via `java.nio.file.Files(Path,Path,CopyOption...)` on macOS. This change would improve the throughput of `Files.copy()` as shown in these results:
>>
>> **Copy via 8192 byte buffers**
>>
>>
>> Benchmark (size) Mode Cnt Score Error Units
>> FilesCopy.copy 10240 thrpt 5 5432.671 ± 137.114 ops/s
>> FilesCopy.copy 51200 thrpt 5 3959.145 ± 157.467 ops/s
>> FilesCopy.copy 102400 thrpt 5 2931.325 ± 109.200 ops/s
>> FilesCopy.copy 512000 thrpt 5 655.550 ± 39.919 ops/s
>> FilesCopy.copy 1048568 thrpt 5 375.127 ± 10.111 ops/s
>> FilesCopy.copy 10485760 thrpt 5 64.048 ± 5.740 ops/s
>> FilesCopy.copy 104857600 thrpt 5 6.893 ± 0.415 ops/s
>> FilesCopy.copy 1073741824 thrpt 5 0.717 ± 0.026 ops/s
>>
>>
>> **Copy via fcopyfile**
>>
>>
>> Benchmark (size) Mode Cnt Score Error Units
>> FilesCopy.copy 10240 thrpt 5 5070.255 ± 817.419 ops/s
>> FilesCopy.copy 51200 thrpt 5 4469.218 ± 65.634 ops/s
>> FilesCopy.copy 102400 thrpt 5 3997.718 ± 301.440 ops/s
>> FilesCopy.copy 512000 thrpt 5 2064.223 ± 68.893 ops/s
>> FilesCopy.copy 1048568 thrpt 5 817.743 ± 83.076 ops/s
>> FilesCopy.copy 10485760 thrpt 5 145.799 ± 3.674 ops/s
>> FilesCopy.copy 104857600 thrpt 5 24.706 ± 14.178 ops/s
>> FilesCopy.copy 1073741824 thrpt 5 1.386 ± 0.073 ops/s
>>
>>
>> The smallest size tested shows a small degradation in throughput, but this could be rectified if desired by adding an empirically determined size threshold under which user-space buffers would be used instead of `fcopyfile()`.
>>
>> A small change is also made to the Linux `sendfile()` portion to use the largest permitted `count` value if the copy is uninterruptible, i.e., `cancel == NULL`.
>
> src/java.base/unix/native/libnio/fs/UnixCopyFile.c line 65:
>
>> 63: return COPYFILE_CONTINUE;
>> 64: }
>> 65: #endif
>
> I wasn't aware of this fcopyfile but it seems to be a good match. At some point I think we will have to split up UnixCopyFile to make it easier to maintain the different implementations. That might be the opportunity to do more than COPYFILE_DATA, meaning we could get it to copy the meta data too.
>
> I think we should try to re-format the callback a bit to make it easier to distinguish the conditions in the if-statement from the body. I probably should re-format the declaration too to get it a more more consistent/readable.
I agree that it would be good to split it up but as part of a yet to be filed issue.
Would you please elaborate on reformatting the callback? Thanks.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3890
More information about the nio-dev
mailing list