Bug 160160 - [Threaded Compositor] Crashes and deadlocks in single web process mode
Summary: [Threaded Compositor] Crashes and deadlocks in single web process mode
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks: 154066
  Show dependency treegraph
 
Reported: 2016-07-25 03:14 PDT by Carlos Garcia Campos
Modified: 2016-07-26 06:28 PDT (History)
3 users (show)

See Also:


Attachments
Patch (18.35 KB, patch)
2016-07-25 03:24 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Updated patch (18.37 KB, patch)
2016-07-25 03:37 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
New patch (21.10 KB, patch)
2016-07-25 04:54 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
New patch (19.68 KB, patch)
2016-07-25 07:47 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Another approach (18.67 KB, patch)
2016-07-26 02:54 PDT, Carlos Garcia Campos
zan: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2016-07-25 03:14:15 PDT
Every WebPage has its own threaded compositor that runs its own compositing thread. That means that when there's more than one WebPage in the same process, we are running OpenGL stuff in different secondary threads. That's causing crashes and deadlocks in X and graphics drivers. We should ensure there's a single compositing thread per process. This is what is causing unit test WebKit2.WKPageGetScaleFactorNotZero to time out since we switched to the threaded compositor. That test is creating two pages in the same web process, and most of the times the web process crashes or deadlocks causing the test to never finish and time out.
Comment 1 Carlos Garcia Campos 2016-07-25 03:24:37 PDT
Created attachment 284470 [details]
Patch
Comment 2 Carlos Garcia Campos 2016-07-25 03:37:37 PDT
Created attachment 284472 [details]
Updated patch

I forgot to detach the scene on invalidate.
Comment 3 Carlos Garcia Campos 2016-07-25 04:54:34 PDT
Created attachment 284476 [details]
New patch

I've realized of an issue with the previous patch, the sync tasks should be sync for the threaded compositor, not for the compositing run loop. After moving the performSync method to the ThreadedCompositor class the CompositingRunLoop class became a very simple RunLoop wrapper with similar code to what a WorkQueue is. so this patch removes CompositingRunLoop in favor of using a global WorkQueue.
Comment 4 WebKit Commit Bot 2016-07-25 04:55:43 PDT
Attachment 284476 [details] did not pass style-queue:


ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:93:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:71:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 2 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Zan Dobersek 2016-07-25 05:48:12 PDT
Any additional information on why this is occurring in the first place? 

I don't think CompositingRunLoop should be removed, instead it should be made a singleton for now, and later it could be turned into a thread pool.
Comment 6 Carlos Garcia Campos 2016-07-25 06:23:29 PDT
(In reply to comment #5)
> Any additional information on why this is occurring in the first place? 

I don't think we can use X and most of the graphics drivers from different processes.

> I don't think CompositingRunLoop should be removed, instead it should be
> made a singleton for now, and later it could be turned into a thread pool.

That's what my previous patch did, converted it into a singleton, but after moving the performSync to the threaded compositor the class became just a wrapper around RunLoop in a separate thread which is what WorkQueue does in the end.
Comment 7 Carlos Garcia Campos 2016-07-25 06:24:55 PDT
I would do it the other way around, let's bring it back if it's really possible to use multiple threads at some point, because I don't think that's going to happen.
Comment 8 Zan Dobersek 2016-07-25 06:40:13 PDT
(In reply to comment #7)
> I would do it the other way around, let's bring it back if it's really
> possible to use multiple threads at some point, because I don't think that's
> going to happen.

It's possible with non-X11 setups.
Comment 9 Zan Dobersek 2016-07-25 06:41:32 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > Any additional information on why this is occurring in the first place? 
> 
> I don't think we can use X and most of the graphics drivers from different
> processes.
> 

I don't understand this.
Comment 10 Carlos Garcia Campos 2016-07-25 06:45:06 PDT
(In reply to comment #9)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > Any additional information on why this is occurring in the first place? 
> > 
> > I don't think we can use X and most of the graphics drivers from different
> > processes.
> > 
> 
> I don't understand this.

That I think we will never be able to use multiple threads, because X and graphics drivers don't really support it. But if you say it's supported by non X platforms, I'll go back to previous approach keeping the CompositingRunLoop because I need this fixed.
Comment 11 Carlos Garcia Campos 2016-07-25 07:47:04 PDT
Created attachment 284483 [details]
New patch

Bring back the compositing run loop class, making it a thread pool with a limit of 1 thread by default.
Comment 12 WebKit Commit Bot 2016-07-25 07:48:44 PDT
Attachment 284483 [details] did not pass style-queue:


ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:65:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:92:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h:50:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:69:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 4 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Carlos Garcia Campos 2016-07-26 02:54:48 PDT
Created attachment 284569 [details]
Another approach

Updated the patch after talking to Zan using a slightly different approach.
Comment 14 WebKit Commit Bot 2016-07-26 02:57:07 PDT
Attachment 284569 [details] did not pass style-queue:


ERROR: Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:49:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 15 Zan Dobersek 2016-07-26 06:01:56 PDT
Comment on attachment 284569 [details]
Another approach

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

Looks good, thanks for reiterating on this.

> Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:94
> +    WorkQueue& getOrCreateWorkQueueForContext(void* context)
> +    {
> +        auto addResult = m_workQueueMap.add(context, nullptr);
> +        if (addResult.isNewEntry) {
> +            if (m_threadCount >= m_threadCountLimit) {
> +                RELEASE_ASSERT(m_sharedWorkQueue);
> +                addResult.iterator->value = m_sharedWorkQueue;
> +            } else {
> +                addResult.iterator->value = WorkQueue::create("org.webkit.ThreadedCompositorWorkQueue");
> +                if (!m_threadCount)
> +                    m_sharedWorkQueue = addResult.iterator->value;
> +                m_threadCount++;
> +            }
> +        }

This is OK for now, and it works for a single-thread limit. But for configurations where more (but not unlimited) threads could be used, one option would be to use a HashSet here and disperse the contexts across the available threads. But that's for the future.
Comment 16 Carlos Garcia Campos 2016-07-26 06:28:00 PDT
Committed r203718: <http://trac.webkit.org/changeset/203718>