RFR: 8316156: (ch) Channels.newOutputStream(ch).write(bigByteArray) allocates a lot of direct memory [v4]

Paul Wagland duke at openjdk.org
Tue Sep 19 09:41:41 UTC 2023


On Fri, 15 Sep 2023 06:38:53 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8316156: Read at most DEFAULT_BUFFER_SIZE bytes
>
> src/java.base/share/classes/sun/nio/ch/ChannelInputStream.java line 71:
> 
>> 69:             return 0;
>> 70: 
>> 71:         bb.limit(pos + Integer.min(rem, Streams.DEFAULT_BUFFER_SIZE));
> 
> I assume we would end up with a MAX_BUFFER_SIZE that is something like 128k, like we ended up in NioSocketImpl for the same reason. In order words, it's different to the chunk size that is DEFAULT_BUFFER_SIZE today.

FWIW, getting back to the reason that this was created in the first place, namely that it is possible to limit `MaxDirectBufferSize`, ideally this limit could be dependent on how much is actually available in the system. `Bits` doesn't currently have any way to expose that. In the scenario that I was dealing with, I had 28M of direct buffer, but the system was trying to allocate (roughly) 62M, and that didn't work. So limiting to 128K would still work perfectly in that scenario.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15733#discussion_r1327087661


More information about the nio-dev mailing list