Bug 220663 - [GPUProcess] Mark IOSurface backing for ImageBufferBackends as owned by the WebProcess
Summary: [GPUProcess] Mark IOSurface backing for ImageBufferBackends as owned by the W...
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: 2021-01-15 12:08 PST by Chris Dumez
Modified: 2021-01-20 09:32 PST (History)
10 users (show)

See Also:


Attachments
Patch (5.92 KB, patch)
2021-01-15 12:11 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.29 KB, patch)
2021-01-15 12:42 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (4.33 KB, patch)
2021-01-15 12:53 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (5.16 KB, patch)
2021-01-15 13:13 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (14.30 KB, patch)
2021-01-15 17:52 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (14.31 KB, patch)
2021-01-19 09:03 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (22.01 KB, patch)
2021-01-19 09:58 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (23.89 KB, patch)
2021-01-19 10:04 PST, Chris Dumez
ggaren: review+
Details | Formatted Diff | Diff
Patch (5.16 KB, patch)
2021-01-19 14:06 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 2021-01-15 12:08:18 PST
Claim ownership of IOSurface backing for ImageBufferBackends in the WebProcess. If we don't do this, all IOSurface memory gets attributed to the GPUProcess, making it a prime candidate for jetsam.
We need to attribute memory usage to the WebProcesses being served by the GPUProcess as much as possible and this is a step in this direction.
Comment 1 Chris Dumez 2021-01-15 12:11:47 PST
Created attachment 417719 [details]
Patch
Comment 2 Tim Horton 2021-01-15 12:16:29 PST
Comment on attachment 417719 [details]
Patch

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

> Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:52
> +    if (result != kIOReturnSuccess)

This should be in ImageBufferShareableMappedIOSurfaceBackend, and /only/ in ImageBufferShareableMappedIOSurfaceBackend. ImageBufferShareableIOSurfaceBackend (the unmapped variant) by definition must not IOSurfaceLookupFromMachPort.
Comment 3 jared 2021-01-15 12:18:21 PST Comment hidden (spam)
Comment 4 Chris Dumez 2021-01-15 12:19:30 PST
(In reply to Tim Horton from comment #2)
> Comment on attachment 417719 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=417719&action=review
> 
> > Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:52
> > +    if (result != kIOReturnSuccess)
> 
> This should be in ImageBufferShareableMappedIOSurfaceBackend, and /only/ in
> ImageBufferShareableMappedIOSurfaceBackend.
> ImageBufferShareableIOSurfaceBackend (the unmapped variant) by definition
> must not IOSurfaceLookupFromMachPort.

This means that with DOM rendering enabled, we will not have a short term fix for view tiles. I understand that in the long term, we want to stop using IOSurface in the WebProcess. However, in the short term, my proposal was to do this (which works for now).
Comment 5 Tim Horton 2021-01-15 12:28:17 PST
Comment on attachment 417719 [details]
Patch

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

>>> Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:52
>>> +    if (result != kIOReturnSuccess)
>> 
>> This should be in ImageBufferShareableMappedIOSurfaceBackend, and /only/ in ImageBufferShareableMappedIOSurfaceBackend. ImageBufferShareableIOSurfaceBackend (the unmapped variant) by definition must not IOSurfaceLookupFromMachPort.
> 
> This means that with DOM rendering enabled, we will not have a short term fix for view tiles. I understand that in the long term, we want to stop using IOSurface in the WebProcess. However, in the short term, my proposal was to do this (which works for now).

Like I said on Slack (but will write here for wider audience), if you want to do this, you should just make DOM use the mapped backend (temporarily) instead of making the non-mapped case map the surfaces :)
Comment 6 Chris Dumez 2021-01-15 12:42:49 PST
Created attachment 417722 [details]
Patch
Comment 7 Chris Dumez 2021-01-15 12:53:18 PST
Created attachment 417723 [details]
Patch
Comment 8 Chris Dumez 2021-01-15 13:13:14 PST
Created attachment 417727 [details]
Patch
Comment 9 Chris Dumez 2021-01-15 17:52:17 PST
Created attachment 417752 [details]
WIP Patch

Ok, I have it working from the GPUProcess this time (no need for IOSurface calls in the WebProcess at all). Much better solution for the long term.

I still need to do some clean up: It may look nicer to transfer the ownership in RemoteRenderingBackend::createImageBuffer() or somewhere else that has access to both the PID and IOSurface, instead of doing it in RemoteRenderingBackend::didCreateImageBufferBackend().
Doing it in RemoteRenderingBackend::didCreateImageBufferBackend() is convenient but it needs I need to look up the IOSurface from the handle again.
Comment 10 Chris Dumez 2021-01-19 09:03:38 PST
Created attachment 417879 [details]
WIP Patch
Comment 11 Chris Dumez 2021-01-19 09:58:01 PST
Created attachment 417883 [details]
Patch
Comment 12 Chris Dumez 2021-01-19 10:04:29 PST
Created attachment 417884 [details]
Patch
Comment 13 Geoffrey Garen 2021-01-19 11:29:10 PST
Comment on attachment 417884 [details]
Patch

r=me
Comment 14 Geoffrey Garen 2021-01-19 11:38:38 PST
Comment on attachment 417884 [details]
Patch

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

> Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.GPU.sb:910
> +(allow mach-priv-task-port)

We probably need to find a way to reduce the scope of sandbox change here. This is relatively high privilege thing.
Comment 15 Geoffrey Garen 2021-01-19 13:45:38 PST
Comment on attachment 417727 [details]
Patch

r=me
Comment 16 Chris Dumez 2021-01-19 13:49:05 PST
One API test failure on open source api bot:

TestWebKitAPI.GPUProcess.CanvasBasicCrashHandling
        dyld: lazy symbol binding failed: Symbol not found: _IOSurfaceSetOwnership
          Referenced from: /Volumes/Data/worker/API-Tests-iOS-Simulator-EWS/build/WebKitBuild/Release-iphonesimulator/WebKit.framework/WebKit
          Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/IOSurface.framework/IOSurface
        
        dyld: Symbol not found: _IOSurfaceSetOwnership
          Referenced from: /Volumes/Data/worker/API-Tests-iOS-Simulator-EWS/build/WebKitBuild/Release-iphonesimulator/WebKit.framework/WebKit
          Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/IOSurface.framework/IOSurface
Comment 17 Chris Dumez 2021-01-19 14:06:51 PST
Created attachment 417912 [details]
Patch
Comment 18 EWS 2021-01-19 16:07:44 PST
Committed r271627: <https://trac.webkit.org/changeset/271627>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417912 [details].
Comment 19 Radar WebKit Bug Importer 2021-01-19 16:08:14 PST
<rdar://problem/73378219>