Skip to content

Conversation

@bplb
Copy link
Member

@bplb bplb commented May 10, 2022

This request proposes to change FileChannel.transferFrom() to add a fast path on Linux and a threshold for mapped transfers on all platforms.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (1 review required, with at least 1 reviewer)

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8644/head:pull/8644
$ git checkout pull/8644

Update a local copy of the PR:
$ git checkout pull/8644
$ git pull https://git.openjdk.java.net/jdk pull/8644/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8644

View PR using the GUI difftool:
$ git pr show -t 8644

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8644.diff

@bplb
Copy link
Member Author

bplb commented May 10, 2022

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 FileChannels. 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.

@bridgekeeper
Copy link

bridgekeeper bot commented May 10, 2022

👋 Welcome back bpb! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 10, 2022
@openjdk
Copy link

openjdk bot commented May 10, 2022

@bplb The following label will be automatically applied to this pull request:

  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the nio nio-dev@openjdk.org label May 10, 2022
@mlbridge
Copy link

mlbridge bot commented May 10, 2022

Webrevs

@bplb bplb force-pushed the FileChannel-transferFrom-8274113 branch from 4ea9b94 to df436ab Compare May 10, 2022 23:28
Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this looks good. It would be useful to add some performance data to the PR to demonstrate the improvement.

@openjdk
Copy link

openjdk bot commented May 11, 2022

@bplb This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8274113: (fc) Tune FileChannel.transferFrom()

Reviewed-by: alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 80 new commits pushed to the master branch:

  • cc7560e: 8286287: Reading file as UTF-16 causes Error which "shouldn't happen"
  • 82aa045: 8286015: JFR: Remove jfr.save.generated.asm
  • 1904e9d: 8286423: Destroy password protection in the example code in KeyStore
  • e4439ca: 8284283: javac crashes when several transitive supertypes are missing
  • 752ad1c: 8286422: Add OIDs for RC2 and Blowfish
  • 36bdd25: 8286573: Remove the unnecessary method Attr#attribTopLevel and its usage
  • dea6e88: 8284680: sun.font.FontConfigManager.getFontConfig() leaks charset
  • 40f43c6: 8286601: Mac Aarch: Excessive warnings to be ignored for build jdk
  • be97b4b: 8278348: [macos12] javax/swing/JTree/4908142/bug4908142.java fails in macos12
  • ff17f49: 8284888: [macos] javax/swing/JInternalFrame/8146321/JInternalFrameIconTest.java failed with "NimbusLookAndFeel] : ERROR: icon and imageIcon not same."
  • ... and 70 more: https://git.openjdk.java.net/jdk/compare/97a983526b41d26fcd1caa162a089690119874b0...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 11, 2022
@bplb
Copy link
Member Author

bplb commented May 11, 2022

Overall I think this looks good. It would be useful to add some performance data to the PR to demonstrate the improvement.

Throughput on macOS showing the change due to the mapped transfer threshold:

Before (mapped transfer)

Benchmark                  (length)   Mode  Cnt      Score     Error  Units
TransferFrom.transferFrom      8000  thrpt   10  83171.694 ± 394.409  ops/s
TransferFrom.transferFrom     12000  thrpt   10  78985.812 ± 405.395  ops/s
TransferFrom.transferFrom     14000  thrpt   10  74194.782 ± 387.265  ops/s
TransferFrom.transferFrom     16000  thrpt   10  74117.711 ± 301.495  ops/s
TransferFrom.transferFrom     17000  thrpt   10  70074.672 ± 562.279  ops/s
TransferFrom.transferFrom     18000  thrpt   10  69862.113 ± 348.783  ops/s
TransferFrom.transferFrom     19000  thrpt   10  69742.800 ± 264.864  ops/s
TransferFrom.transferFrom     20000  thrpt   10  69017.441 ± 208.591  ops/s
TransferFrom.transferFrom     22000  thrpt   10  65326.088 ± 281.195  ops/s
TransferFrom.transferFrom     24000  thrpt   10  64996.134 ± 254.554  ops/s

After (read-write transfer up to 16K length)

Benchmark                  (length)   Mode  Cnt       Score      Error  Units
TransferFrom.transferFrom      8000  thrpt   10  178033.028 ± 1048.081  ops/s
TransferFrom.transferFrom     12000  thrpt   10   99595.963 ± 1044.993  ops/s
TransferFrom.transferFrom     14000  thrpt   10   97869.683 ±  548.820  ops/s
TransferFrom.transferFrom     16000  thrpt   10   94392.964 ±  827.057  ops/s
TransferFrom.transferFrom     17000  thrpt   10   67670.339 ±  735.683  ops/s
TransferFrom.transferFrom     18000  thrpt   10   68161.273 ±  384.360  ops/s
TransferFrom.transferFrom     19000  thrpt   10   68453.820 ±  632.199  ops/s
TransferFrom.transferFrom     20000  thrpt   10   68701.903 ± 1042.648  ops/s
TransferFrom.transferFrom     22000  thrpt   10   65713.451 ±  497.990  ops/s
TransferFrom.transferFrom     24000  thrpt   10   66525.251 ± 1017.672  ops/s

The threshold could probably be a little higher but is left at 16K for consistency with transferTo().

Throughput on Linux showing the change due to direct transfer:

Before (mapped transfer)

Benchmark                  (length)   Mode  Cnt      Score      Error  Units
TransferFrom.transferFrom     16384  thrpt    5  95885.876 ± 1153.982  ops/s
TransferFrom.transferFrom    131072  thrpt    5  30699.784 ±  653.334  ops/s
TransferFrom.transferFrom   1000000  thrpt    5   6840.268 ±  162.586  ops/s

After (copy_file_range())

Benchmark                  (length)   Mode  Cnt       Score      Error  Units
TransferFrom.transferFrom     16384  thrpt    5  236198.847 ± 2070.598  ops/s
TransferFrom.transferFrom    131072  thrpt    5   59197.335 ± 1596.413  ops/s
TransferFrom.transferFrom   1000000  thrpt    5    8135.444 ±  758.260  ops/s

@bplb
Copy link
Member Author

bplb commented May 12, 2022

/integrate

@openjdk
Copy link

openjdk bot commented May 12, 2022

Going to push as commit 986d87d.
Since your change was applied there have been 89 commits pushed to the master branch:

  • 61cb4b7: 8285951: Replace Algorithms.eatMemory(...) with WB.fullGC() in vmTestbase_vm_gc_ref tests
  • 5ff1d22: 8286386: Address possibly lossy conversions in java.net.http
  • 7118343: 8278262: JFR: TestPrintXML can't handle missing timestamps
  • 74eee28: 8286560: Remove user parameter from jdk.internal.perf.Perf.attach()
  • 160944b: 8286615: Small refactor to SerializedLambda
  • 17c5278: 8286378: Address possibly lossy conversions in java.base
  • 0a6832b: 8286617: Improve parameter names in javax.lang.model utility visitors
  • 2c5d136: 8282191: Implementation of Foreign Function & Memory API (Preview)
  • 3be394e: 8275535: Retrying a failed authentication on multiple LDAP servers can lead to users blocked
  • cc7560e: 8286287: Reading file as UTF-16 causes Error which "shouldn't happen"
  • ... and 79 more: https://git.openjdk.java.net/jdk/compare/97a983526b41d26fcd1caa162a089690119874b0...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 12, 2022
@openjdk openjdk bot closed this May 12, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 12, 2022
@openjdk
Copy link

openjdk bot commented May 12, 2022

@bplb Pushed as commit 986d87d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@bplb bplb deleted the FileChannel-transferFrom-8274113 branch May 12, 2022 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated nio nio-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

2 participants