Bug 194594 - [PSON] Introduce a WebContent Process cache
Summary: [PSON] Introduce a WebContent Process cache
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-02-13 08:53 PST by Chris Dumez
Modified: 2019-02-15 01:11 PST (History)
7 users (show)

See Also:


Attachments
Patch (106.35 KB, patch)
2019-02-13 16:02 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (106.38 KB, patch)
2019-02-13 16:06 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (106.55 KB, patch)
2019-02-13 19:49 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (108.70 KB, patch)
2019-02-14 09:04 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (109.25 KB, patch)
2019-02-14 09:24 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2019-02-13 08:53:42 PST
Introduce a WebContent Process cache to avoid launching new processes too frequently and reduce the power impact of PSON.
Comment 1 Chris Dumez 2019-02-13 08:54:11 PST
<rdar://problem/46793397>
Comment 2 Chris Dumez 2019-02-13 16:02:23 PST
Created attachment 361952 [details]
Patch
Comment 3 Chris Dumez 2019-02-13 16:06:16 PST
Created attachment 361953 [details]
Patch
Comment 4 Chris Dumez 2019-02-13 19:49:23 PST
Created attachment 361986 [details]
Patch
Comment 5 Geoffrey Garen 2019-02-13 21:35:21 PST
Comment on attachment 361986 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=361986&action=review

r=me

> Source/WebKit/UIProcess/WebProcessCache.cpp:121
> +void WebProcessCache::setApplicationIsActive(bool value)

value => isActive

> Source/WebKit/UIProcess/WebProcessCache.h:48
> +    unsigned maximumSize() { return m_maximumSize; }

We usually call this capacity.

> Source/WebKit/UIProcess/WebProcessPool.cpp:1337
>  void WebProcessPool::handleMemoryPressureWarning(Critical)
>  {
> +    RELEASE_LOG(PerformanceLogging, "%p - WebProcessPool::handleMemoryPressureWarning", this);
> +
> +    m_webProcessCache->clear();

Does the process suspension code run the low memory warning in the web process?

Relatedly, maybe the web process should listen to the low memory warning, in case it gets the warning before the UI process does.

> Source/WebKit/UIProcess/WebProcessPool.cpp:2301
> +    // FIXME: If the SuspendedPage is for this page, then we need to destroy the suspended page as we do not support having
> +    // multiple WebPages with the same ID in a given WebProcess currently (https://bugs.webkit.org/show_bug.cgi?id=191166).
> +    if (&(*it)->page() == &page)
> +        m_suspendedPages.remove(it);
>  

Do we need the same check when we retrieve a process from the web process cache?
Comment 6 Chris Dumez 2019-02-14 06:33:26 PST
Comment on attachment 361986 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=361986&action=review

>> Source/WebKit/UIProcess/WebProcessPool.cpp:1337
>> +    m_webProcessCache->clear();
> 
> Does the process suspension code run the low memory warning in the web process?
> 
> Relatedly, maybe the web process should listen to the low memory warning, in case it gets the warning before the UI process does.

The processes suspension code does simulate a memory warning in the WebProcress on iOS. There is no process suspension on macOS and this cache will be macOS only I believe.

It is a good point that the WebProcess’s memory pressure handler should likely cause the process the exit if it is in the cache. I will look into this.

>> Source/WebKit/UIProcess/WebProcessPool.cpp:2301
>>  
> 
> Do we need the same check when we retrieve a process from the web process cache?

No, processes in the cache cannot have any pages or suspended pages, they only enter the cache when they are about to exit because they are no longer used for anything.
Comment 7 Geoffrey Garen 2019-02-14 07:44:57 PST
Yeah, I think the cache should be mac only.
Comment 8 Chris Dumez 2019-02-14 07:53:34 PST
Comment on attachment 361986 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=361986&action=review

>> Source/WebKit/UIProcess/WebProcessCache.cpp:121
>> +void WebProcessCache::setApplicationIsActive(bool value)
> 
> value => isActive

Ok

>> Source/WebKit/UIProcess/WebProcessCache.h:48
>> +    unsigned maximumSize() { return m_maximumSize; }
> 
> We usually call this capacity.

Ok but for the record I prefer maximumSize because I feel it is clearer. Vector has the concept of capacity and it has nothing to do with maximum size.

>>> Source/WebKit/UIProcess/WebProcessPool.cpp:1337
>>> +    m_webProcessCache->clear();
>> 
>> Does the process suspension code run the low memory warning in the web process?
>> 
>> Relatedly, maybe the web process should listen to the low memory warning, in case it gets the warning before the UI process does.
> 
> The processes suspension code does simulate a memory warning in the WebProcress on iOS. There is no process suspension on macOS and this cache will be macOS only I believe.
> 
> It is a good point that the WebProcess’s memory pressure handler should likely cause the process the exit if it is in the cache. I will look into this.

Note that we could simulate a memory pressure warning when entering the cache to try and slim the process as much as possible. However, doing so could impact performance as some valuable caches would be gone when trying to reuse the process. This could impact power and PLT. For this reason, I have not implemented it in this patch.
Comment 9 Chris Dumez 2019-02-14 09:04:20 PST
Created attachment 362022 [details]
Patch
Comment 10 Brady Eidson 2019-02-14 09:21:35 PST
Comment on attachment 362022 [details]
Patch

👍
Comment 11 Chris Dumez 2019-02-14 09:22:00 PST
(In reply to Brady Eidson from comment #10)
> Comment on attachment 362022 [details]
> Patch
> 
> 👍

Thanks for looking as well.
Comment 12 Chris Dumez 2019-02-14 09:22:25 PST
I will try and figure out why the GTK bot is unhappy now :/
Comment 13 Chris Dumez 2019-02-14 09:24:19 PST
Created attachment 362026 [details]
Patch
Comment 14 WebKit Commit Bot 2019-02-14 11:06:18 PST
Comment on attachment 362026 [details]
Patch

Clearing flags on attachment: 362026

Committed r241556: <https://trac.webkit.org/changeset/241556>
Comment 15 WebKit Commit Bot 2019-02-14 11:06:20 PST
All reviewed patches have been landed.  Closing bug.
Comment 16 Geoffrey Garen 2019-02-14 11:16:47 PST
Probably the right move is to land without the pressure warning when entering the cache, and then separately a/b test a change to add a pressure warning. 

It’s a good point that a cache’s capacity limits its size, whereas a vector’s capacity does not. One thing that was unclear to me about “maximum size” was that I first read it as “the maximum size I have ever been” rather than “the maximum size I am allowed to reach”. STL vectors have a max size — but that means the max size that any vector could be, and it’s not adjustable for a given vector. I do think people often refer to caches as having a capacity. e.g. http://kb.mozillazine.org/Browser.cache.memory.capacity. I’ve gotten used to size as “how many elements I have” and capacity as “how many elements I could have before triggering some action (grow, evict, ring buffer, crash, whatever)”. Maybe we should circulate with other folks and see what the communal preference is.