Bug 224556 - Exit the GPUProcess when under memory pressure if it is not being used
Summary: Exit the GPUProcess when under memory pressure if it is not being used
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: 224461 224505 224513 224516 224566 224623
Blocks:
  Show dependency treegraph
 
Reported: 2021-04-14 09:59 PDT by Chris Dumez
Modified: 2021-04-19 12:21 PDT (History)
16 users (show)

See Also:


Attachments
Patch (34.25 KB, patch)
2021-04-14 10:06 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (34.28 KB, patch)
2021-04-14 12:30 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (34.39 KB, patch)
2021-04-14 12:35 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (34.73 KB, patch)
2021-04-14 14:11 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (34.74 KB, patch)
2021-04-15 16:45 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (49.83 KB, patch)
2021-04-16 08:24 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (52.67 KB, patch)
2021-04-16 10:09 PDT, 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 2021-04-14 09:59:44 PDT
Exit the GPUProcess when under memory pressure if it is not being used. This will help us save memory, especially until we are able to enable "DOM Rendering in GPUProcess".
Comment 1 Chris Dumez 2021-04-14 10:06:29 PDT
Created attachment 425995 [details]
Patch
Comment 2 Chris Dumez 2021-04-14 10:06:52 PDT
I am currently perf-testing this patch on PLT5 and PLUM3.
Comment 3 Geoffrey Garen 2021-04-14 12:12:17 PDT
EWS seems angry:

    TestWebKitAPI.GPUProcess.ExitsUnderMemoryPressureCanvasCase
        Child process terminated with signal 6: Abort trap
    TestWebKitAPI.GPUProcess.ExitsUnderMemoryPressureVideoCase
        Failed to find media engine.
        Failed to find media engine.
        Child process terminated with signal 6: Abort trap
    TestWebKitAPI.GPUProcess.ExitsUnderMemoryPressureWebAudioCase
        Child process terminated with signal 6: Abort trap
Comment 4 Chris Dumez 2021-04-14 12:12:49 PDT
(In reply to Geoffrey Garen from comment #3)
> EWS seems angry:
> 
>     TestWebKitAPI.GPUProcess.ExitsUnderMemoryPressureCanvasCase
>         Child process terminated with signal 6: Abort trap
>     TestWebKitAPI.GPUProcess.ExitsUnderMemoryPressureVideoCase
>         Failed to find media engine.
>         Failed to find media engine.
>         Child process terminated with signal 6: Abort trap
>     TestWebKitAPI.GPUProcess.ExitsUnderMemoryPressureWebAudioCase
>         Child process terminated with signal 6: Abort trap

Yes, investigating.
Comment 5 Ryosuke Niwa 2021-04-14 12:23:36 PDT
Comment on attachment 425995 [details]
Patch

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

> Source/WebKit/GPUProcess/GPUProcess.cpp:133
> +    }
> +    return true;

Please rate limit this with time too although it could be done in a separate patch.
We probably shouldn't killing GPU process no more than once every 5-10s.
Comment 6 Chris Dumez 2021-04-14 12:25:26 PDT
(In reply to Ryosuke Niwa from comment #5)
> Comment on attachment 425995 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=425995&action=review
> 
> > Source/WebKit/GPUProcess/GPUProcess.cpp:133
> > +    }
> > +    return true;
> 
> Please rate limit this with time too although it could be done in a separate
> patch.
> We probably shouldn't killing GPU process no more than once every 5-10s.

Yes, I understand the concern. I am not doing this yet because it is going to be tricky to do this right and avoid making the tests flaky or causing the process not to exit in PLUM3. I am still pondering whether to do this in this patch or in a follow-up. I definitely want to do initial perf testing without this though.
Comment 7 Chris Dumez 2021-04-14 12:30:18 PDT
Created attachment 426031 [details]
Patch
Comment 8 Chris Dumez 2021-04-14 12:35:34 PDT
Created attachment 426033 [details]
Patch
Comment 9 Chris Dumez 2021-04-14 14:11:14 PDT
Created attachment 426043 [details]
Patch
Comment 10 Chris Dumez 2021-04-15 16:45:07 PDT
Created attachment 426153 [details]
Patch
Comment 11 Chris Dumez 2021-04-15 17:01:47 PDT
The perf results look promising (Nice PLUM3 progression, no PLT5 regression). However, I am getting flaky GPUProcess crashes on ios-EWS (with no crash trace :/). I will investigate locally.
Comment 12 Chris Dumez 2021-04-15 17:20:18 PDT
Looks like the iOS EWS crashes are not really true. It is true to this code in WKTR:
void TestController::gpuProcessDidCrash(WKProcessID processID)
{
    fprintf(stderr, "#CRASHED - GPUProcess (pid %ld)\n", static_cast<long>(processID));
    if (m_shouldExitWhenWebProcessCrashes)
        exit(1);
}


Every time the GPUProcess exits on memory pressure while running the tests, WKTR reports it as a crash even though it is a clean exit.
Comment 13 Chris Dumez 2021-04-15 19:26:04 PDT
A/B Testing results:

PLUM3-iPhone - Arithmetic mean
Comparision by Mean	5.26% better (significant with 98% probability)
Comparision by Individual	5.26% better (significant with 98% probability)

PLUM3-iPad - Arithmetic mean
Comparision by Mean	2.55% better (significant with 98% probability)
Comparision by Individual	2.55% better (significant with 98% probability)

PLT5-iPad - null
Comparision by Mean	0.63% worse (insignificant)
Comparision by Individual	0.63% worse (insignificant)

PLT5-iPhone - null
Comparision by Mean	0.03% better (insignificant)
Comparision by Individual	0.03% better (insignificant)

Looks good!

I know how to address the fake crash reports on ios-EWS (We need to tell the gpuProcessCrashed client delegate only in the case of a true crash, not a clean idle exit). I will try and finish the patch tomorrow.
Comment 14 Chris Dumez 2021-04-16 08:24:56 PDT
Created attachment 426230 [details]
Patch
Comment 15 Chris Dumez 2021-04-16 08:25:23 PDT
(In reply to Chris Dumez from comment #14)
> Created attachment 426230 [details]
> Patch

Should take care of those iOS-EWS failures.
Comment 16 Darin Adler 2021-04-16 10:03:42 PDT
Comment on attachment 426230 [details]
Patch

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

> Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:293
> +#if HAVE(AVASSETWRITERDELEGATE)

Would you be willing to consider just writing this out as:

    #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)

instead of nesting it?
Comment 17 Chris Dumez 2021-04-16 10:04:22 PDT
(In reply to Darin Adler from comment #16)
> Comment on attachment 426230 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=426230&action=review
> 
> > Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:293
> > +#if HAVE(AVASSETWRITERDELEGATE)
> 
> Would you be willing to consider just writing this out as:
> 
>     #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM) &&
> HAVE(AVASSETWRITERDELEGATE)
> 
> instead of nesting it?

Sure. I was just following the pattern in the header. I'll update.
Comment 18 Chris Dumez 2021-04-16 10:09:49 PDT
Created attachment 426243 [details]
Patch
Comment 19 Radar WebKit Bug Importer 2021-04-16 11:07:36 PDT
<rdar://problem/76768542>
Comment 20 EWS 2021-04-16 11:41:32 PDT
Committed r276148 (236641@main): <https://commits.webkit.org/236641@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 426243 [details].
Comment 21 Chris Dumez 2021-04-16 17:19:48 PDT
There is still code that (re-)launches the GPUProcess too eagerly. I will follow-up and fix them via related bugs.