RFR: 8303934: (fc) Use splice in FileChannel::transferFrom when the source is a pipe (Linux)

Brian Burkhalter bpb at openjdk.org
Fri Mar 10 00:43:04 UTC 2023


On Fri, 10 Mar 2023 00:35:38 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> On Linux, perform `transferFrom()` via the `splice(2)` system call when the source `ReadableByteChannel` is a `Pipe.SourceChannel` (`sun.nio.ch.SourceChannelImpl`).

The Linux `splice()` system call copies data in kernel address space between two file descriptors without copying the data to user address space. At present the execution pathway for transferring from a pipe source is the arbitrary channel pathway which is the slowest. Using `splice()` for this case increases throughput by more than 30%. This is the increase measured using this simple benchmark (excerpt) for a buffer of capacity 8192:


    ByteBuffer buf;
    Pipe pipe;
    FileChannel fc;

    @Benchmark
    public long transferFromPipe() throws IOException {
        pipe.sink().write(buf);
        buf.rewind();
        return fc.transferFrom(pipe.source(), 0, SIZE);
    }

As the benchmark measurement includes writing to the pipe sink, the increase in throughput should actually be larger than that measured.

Test tiers 1-3 pass on all platforms.

The modifications to the AIX and Windows source files are format cleanup only.

-------------

PR: https://git.openjdk.org/jdk/pull/12965


More information about the nio-dev mailing list