New issue
Advanced search Search tips

Issue 621191 link

Starred by 2 users

Issue metadata

Status: Duplicate
Merged: issue 524258
Owner: ----
Closed: Jun 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocking:
issue 620852



Sign in to add a comment

Investigating shrinking SSLClientSocket read/write buffers

Project Member Reported by mmenke@chromium.org, Jun 17 2016

Issue description

From traces, these look to be one of net's largest contributors to idle memory consumption on Android.  Visit a couple sites, and these buffers can easily hit 1.5+ MB combined, even ignoring other objects owned by the sockets.  The issue isn't so much their size when in use, but the fact that their size always contributes to memory use, even when Chrome is idle, and we can keep a lot of idle sockets around.

Ideally, we'd just free the buffers when not in use, but the BIO API doesn't exactly make it clear how to do that.

It's also worth thinking about more aggressively closing idle sockets, but I'll file another bug for that.
 
 Issue #524258  has some discussion here. Specifically this comment:
https://bugs.chromium.org/p/chromium/issues/detail?id=524258#c5

Freeing the buffers when not in use is possible but would require much more invasive work. I've been meaning to get BIO pair out of there and replace it with a custom BIO that wraps a StreamSocket and converts between what OpenSSL wants and what StreamSocket provides. Then that thing could internally be clever and drop buffers. (And we could remove the ugly "zero-copy" BIO pair complexity that was added at some point. That all makes this too hard to reason about.)

I think shrinking the buffers is also in itself a pretty reasonable and easy thing to do. Certainly it's an easier change code-wise.

I very strongly suspect that, as things have changed significantly over time, the SPDY thing is no longer an issue, but whoever's looking into this should probably dig into that incident and convince themselves that this is now fine.

Comment 2 by mmenke@chromium.org, Jun 17 2016

Have a link to the incident?  I had assumed I could trace back when the buffer size limit was set, but it was added when adding the BIO pair thing, and before that...the limit lays deep within the depths of the hazardous BIO code (Which, frankly, scares me, and I'd rather not dig into).

Comment 3 by mmenke@chromium.org, Jun 17 2016

Oh, nevermind, that other issue has a link.
Yeah, the BIO pair code is awful, and it got even worse after this crazy "zero copy" thing was added (it should have done a custom BIO in C++).

https://bugs.chromium.org/p/chromium/issues/detail?id=524258#c5 has the history here.
The crazy "zero copy" thing was added from Opera seeing memcpy's in tracing. Just wanting to make sure we're remembering why the fence ( http://www.chesterton.org/taking-a-fence-down/ ) was placed there.

If I were thinking on the purely pragmatic side, we'd treat it similar to kernel socket buffers - we start at size X, we grow to size Y, and we shrink when idle, repeating the process.

The complexity of the growth strategy may be not worth it - I'd totally buy releasing the sockets after some T period idle, and make the allocator reallocate when a new request comes in.
Right, the problem is not that it avoided the copy. It's that it was implemented by making BIO pair more complicated rather than doing a custom BIO. A custom BIO could be done in C++ and would be aware of StreamSocket::{Read,Write}'s needs. That's the way to go w.r.t. dropping the buffers when the socket is idle.

Comment 7 by mmenke@chromium.org, Jun 17 2016

Mergedinto: 524258
Status: Duplicate (was: Untriaged)
Marking as a dupe of the other one.

Sign in to add a comment