RFR: 8274113: (fc) Tune FileChannel.transferFrom()
Brian Burkhalter
bpb at openjdk.java.net
Tue May 10 23:12:20 UTC 2022
On Tue, 10 May 2022 23:05:19 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> This request proposes to change `FileChannel.transferFrom()` to add a fast path on Linux and a threshold for mapped transfers on all platforms.
To `transferFrom()` a direct transfer path is added by the method `transferFromDirectly()` for the case where the source `ReadableByteChannel` is a `FileChannel`. If a native fast transfer function is available, then it will be used for the transfer between `FileChannel`s. Currently the only such platform function is `copy_file_range()` on Linux. If no such function is available, this path will be attempted only once. This direct path was measured to improve throughput by from 25% to 300%.
A threshold is added for all platforms such that a mapped transfer is attempted only when the number of bytes to transfer is greater than the threshold. Below this threshold a read-write copy is performed.
The test `Transfers.java` is modified *not* to require that `transferFrom()` return a value equal to its `count` parameter which is not required by the specification:
```Fewer than the requested number of bytes will be transferred [...]```
Instead, `transferFrom()` is called in a loop until the cumulative number of bytes equals the expected value or an error occurs.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8644
More information about the nio-dev
mailing list