-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
6478546: FileInputStream.read() throws OutOfMemoryError when there is plenty available #14981
Conversation
… plenty available
The cost of native memory allocation appears to degrade the throughput of reads and writes of larger arrays. Above a certain size, allocating and looping over a smaller array was measured to achieve higher throughput. As |
👋 Welcome back bpb! A progress list of the required criteria for merging this PR into |
Webrevs
|
Mailing list message from Bernd on core-libs-dev: An HTML attachment was scrubbed... |
Mailing list message from Brian Burkhalter on core-libs-dev: I think the idea is to treat an IOException thrown by any but the first invocation of readBytes() as equivalent to end-of-file such as described for InputStream::read(byte[],int,int)<https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/io/InputStream.html#read(byte%5B%5D,int,int)> with respect to its invocation of InputStream::read()<https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/io/InputStream.html#read()>. On Jul 24, 2023, at 8:33 AM, Bernd <ecki at zusammenkunft.net<mailto:ecki at zusammenkunft.net>> wrote: If you return the short buffer (on IOException), does it need to cache the pending exception or can you just rely on the next read hitting that underlying exception again? (Is there an actual guarantee somewhere that the read position is not altered on IOExceptions or that you always get lending bytes before this report? (If so, does the native code do that as well?) -------------- next part -------------- |
I looked through the latest version (69941de). I think the main issue with this version is that it changes behavior of the read methods to work like "read fully", I don't think we should do that. To preserve long standing behavior it should attempt a second/subsequent read when the clamped buffer is filled. I think this is close to what you want (not tested, but you'll get the idea I think).
The changes in 69941de are also using nested blockers, this is benign, but if this code is change then they can be dropped from the callers. |
To me it looks more like |
I don't see where this is happening. |
The EOF handling in the above should be
or zero will be returned if EOF is encountered on the first read (I made the same mistake in code that was not checked in). |
Modified as suggested in 9264975. The limit is increased to 1.5 Mb where it was in native malloc clamping. This appears to prevent any throughput degradation. |
long comp = Blocker.begin(); | ||
try { | ||
do { | ||
int size = Math.min(remaining, 1572864); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.5Mb seems high, I think we really need micro that do real file I/O to help tune this.
@bplb This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Still need to derive a valid value for the maximum read/write size by benchmarks which are not just measuring the file system cache. |
@bplb This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@bplb This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
Limit native memory allocation and move write loop from the native layer into Java. This change should make the OOME reported in the issue much less likely.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14981/head:pull/14981
$ git checkout pull/14981
Update a local copy of the PR:
$ git checkout pull/14981
$ git pull https://git.openjdk.org/jdk.git pull/14981/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14981
View PR using the GUI difftool:
$ git pr show -t 14981
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14981.diff
Webrev
Link to Webrev Comment