Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8266589: (fs) Improve performance of Files.copy() on macOS using copyfile(3) #3890

Closed
wants to merge 2 commits into from

Conversation

bplb
Copy link
Member

@bplb bplb commented May 5, 2021

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.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8266589: (fs) Improve performance of Files.copy() on macOS using copyfile(3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3890

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented May 5, 2021

👋 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 5, 2021
@openjdk
Copy link

openjdk bot commented May 5, 2021

@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 5, 2021
@mlbridge
Copy link

mlbridge bot commented May 5, 2021

Webrevs

}
return COPYFILE_CONTINUE;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

I should have been clearer. L58 splits the conditions on two lines with the second line indented 4 spaces so it looks like the 3rd condition is in the block. I think you should re-format it to make it easier to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

This could be made into one line, no split, or three lines. Otherwise an additional if would be needed.

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.

I see the re-examination of the callback means that COPYFILE_ERR is handled now. Good!

@openjdk
Copy link

openjdk bot commented May 7, 2021

@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:

8266589: (fs) Improve performance of Files.copy() on macOS using copyfile(3)

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 90 new commits pushed to the master branch:

  • ebb68d2: 8049700: Deprecate obsolete classes and methods in javax/swing/plaf/basic
  • 3a474d9: 8265612: revise the help info for jmap histo command
  • c97f56c: 8266172: -Wstringop-overflow happens in vmError.cpp
  • 43ad24f: 8265465: jcmd VM.cds should keep already dumped archive when exception happens
  • 66191ff: 8266193: BasicJMapTest does not include testHistoParallel methods
  • 36e5ad6: 8263236: runtime/os/TestTracePageSizes.java fails on old kernels
  • 0ca86da: 8266002: vmTestbase/nsk/jvmti/ClassPrepare/classprep001 should skip events for unexpected classes
  • 52f1db6: 8262002: java/lang/instrument/VerifyLocalVariableTableOnRetransformTest.sh failed with "TestCaseScaffoldException: DummyClassWithLVT did not match .class file"
  • 04f7112: 8266293: Key protection using PBEWithMD5AndDES fails with "java.security.InvalidAlgorithmParameterException: Salt must be 8 bytes long"
  • a90b33a: 8266573: Make sure blackholes are tagged for all JVMCI paths
  • ... and 80 more: https://git.openjdk.java.net/jdk/compare/0544a732a44309bf7cbb44846dd9320c6096de17...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 7, 2021
@bplb
Copy link
Member Author

bplb commented May 7, 2021

/integrate

@openjdk openjdk bot closed this May 7, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 7, 2021
@openjdk
Copy link

openjdk bot commented May 7, 2021

@bplb Since your change was applied there have been 103 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Pushed as commit b5b3119.

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

@bplb bplb deleted the macos-copyfile-8266589 branch May 7, 2021 19:12
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
2 participants