Bug 164049

Summary: [GTK] Dramatic increase on memory usage since 2.14.x
Product: WebKit Reporter: Andres Gomez Garcia <agomez>
Component: WebKitGTKAssignee: Miguel Gomez <magomez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, agomez, aperez, bfulgham, bugs-noreply, clopez, commit-queue, dino, kondapallykalyan, magomez, mcatanzaro, mike, noam, ossy, pvollan
Priority: P2    
Version: WebKit Nightly Build   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Andres Gomez Garcia 2016-10-27 01:48:47 PDT
This discussion started in ephy's ML by Michael Gratton, but opening a bug for reference:
https://mail.gnome.org/archives/epiphany-list/2016-October/msg00016.html
 
Hey all,

I feel like Epiphany's/WebKitGTK's memory use has substantially 
increased with 3.22/2.14, under X11 on Ubuntu at least.

My current Epiphany session has ~70 tabs over two windows. If I quit 
and restart it, such that only two of those tabs have actually loaded 
any content, then the total memory consumption is ~7GB (as reported by 
gnome-system-monitor total free before and after launching Ephy). This 
seems to be a substantial increase over earlier versions.

Breaking that down, I am seeing the following approx Memory (from 
g-s-m):
 - Epiphany: 100M
 - Network + DB processes: 40M
 - Single web process for loaded tabs: 250M (+ 10M XServer memory)
 - Single web process for not-yet-loaded tabs: 55M (+ 10M XServer 
memory)

While that doesn't add up to ~7GB, adding up the RSS sizes as reported 
by `ps aux` does.

Switching to a single-shared-process gives 6.4G used after launch, with 
similar numbers for the aux processes, and the following for the single 
web process:

 - Shared web process: 2.1G (+ 550Mb XServer memory)

This is in comparison to the honourable competition, both of which use 
~1G after opening 70 blank tabs.

Is this to be expected? What's the best way to try to find out where 
all this memory is going?

//Mike
Comment 1 Andres Gomez Garcia 2016-10-27 01:49:16 PDT
I can confirm that this is also my experience.
Comment 2 Miguel Gomez 2016-11-22 02:43:38 PST
As we enabled the Threaded Compositor by default, we are intensively using OpenGL for rendering and this has triggered the problem. We found that the extra memory consumption comes from the Intel Mesa driver, which is using the sofware rasterizer to perform OpenGL operations.

In order to fix this we need to change the way we create the OpenGL contexts: we need to request a concrete version where the Intel driver doesn't use the software rasterizer (3.2 core profile), and then we need to update the OpenGL operations to be coherent with that OpenGL version.

I'll attach a patch that changes the context creation, requesting a OpenGL 3.2 Core version, and fixes some gl operations when we are using that version. It also tweaks the ANGLE shader translator to output the appropriate code for the version (GLSL 1.50).
Comment 3 Miguel Gomez 2016-11-22 03:06:31 PST
Created attachment 295334 [details]
Patch
Comment 4 Carlos Garcia Campos 2016-11-22 03:21:46 PST
Comment on attachment 295334 [details]
Patch

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

Thanks for working on this. I only have a few comments, I'll leave the actual review to Zan.

> Source/WebCore/platform/graphics/GLContext.cpp:170
> +    if (!m_version) {
> +        GC3Dint mayor = 0;
> +        GC3Dint minor = 0;
> +        ::glGetIntegerv(GL_MAJOR_VERSION, &mayor);
> +        ::glGetIntegerv(GL_MINOR_VERSION, &minor);
> +        m_version = mayor * 100 + minor * 10;

mayor -> major

I think we could initialize this always in the constructor since this will probably always be called, and then we can make this a simpler const getter.

> Source/WebCore/platform/graphics/glx/GLContextGLX.cpp:63
> +#if !PLATFORM(GTK)
> +    return false;
> +#endif

I don't think this should be GTK specific. This code is only used by GTK+ in any case, so we don't need any platform ifdef.

> Source/WebCore/platform/graphics/glx/GLContextGLX.cpp:87
> +    int nConfigs = 0;

Use numConfigs or configsCount
Comment 5 Miguel Gomez 2016-11-22 03:33:42 PST
Created attachment 295335 [details]
Patch
Comment 6 Miguel Gomez 2016-11-22 03:36:52 PST
> > Source/WebCore/platform/graphics/GLContext.cpp:170
> > +    if (!m_version) {
> > +        GC3Dint mayor = 0;
> > +        GC3Dint minor = 0;
> > +        ::glGetIntegerv(GL_MAJOR_VERSION, &mayor);
> > +        ::glGetIntegerv(GL_MINOR_VERSION, &minor);
> > +        m_version = mayor * 100 + minor * 10;
> 
> mayor -> major
> 
> I think we could initialize this always in the constructor since this will
> probably always be called, and then we can make this a simpler const getter.

I haven't changed the initialization in the new patch. The gl version cannot be initialized in the constructor because we need a current gl context set in order to call glGetIntegerv(), and the context is not current in the constructor yet.
Comment 7 Zan Dobersek 2016-11-25 01:44:02 PST
Comment on attachment 295335 [details]
Patch

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

> Source/WebCore/platform/graphics/GLContext.h:50
> +    uint version();

unsigned should be used, not uint.

> Source/WebCore/platform/graphics/GLContext.h:81
> +    uint m_version { 0 };

Same here.
Comment 8 Miguel Gomez 2016-11-25 05:49:04 PST
(In reply to comment #7)
> Comment on attachment 295335 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=295335&action=review
> 
> > Source/WebCore/platform/graphics/GLContext.h:50
> > +    uint version();
> 
> unsigned should be used, not uint.
> 
> > Source/WebCore/platform/graphics/GLContext.h:81
> > +    uint m_version { 0 };
> 
> Same here.

Ok, I'll fix those, rebase the patch and commit it.
Comment 9 Miguel Gomez 2016-11-28 03:15:31 PST
Created attachment 295484 [details]
Patch
Comment 10 WebKit Commit Bot 2016-11-28 07:00:59 PST
Comment on attachment 295484 [details]
Patch

Clearing flags on attachment: 295484

Committed r208997: <http://trac.webkit.org/changeset/208997>
Comment 11 WebKit Commit Bot 2016-11-28 07:01:04 PST
All reviewed patches have been landed.  Closing bug.
Comment 12 Csaba Osztrogonác 2016-11-28 11:11:34 PST
(In reply to comment #10)
> Comment on attachment 295484 [details]
> Patch
> 
> Clearing flags on attachment: 295484
> 
> Committed r208997: <http://trac.webkit.org/changeset/208997>

It broke the WinCairo build:
..\..\Source\WebCore\platform\graphics\GLContext.cpp(168): error C2039: 'glGetIntegerv': is not a member of '`global namespace''
..\..\Source\WebCore\platform\graphics\GLContext.cpp(168): error C2065: 'GL_MAJOR_VERSION': undeclared identifier
..\..\Source\WebCore\platform\graphics\GLContext.cpp(168): error C3861: 'glGetIntegerv': identifier not found
..\..\Source\WebCore\platform\graphics\GLContext.cpp(169): error C2039: 'glGetIntegerv': is not a member of '`global namespace''
..\..\Source\WebCore\platform\graphics\GLContext.cpp(169): error C2065: 'GL_MINOR_VERSION': undeclared identifier
..\..\Source\WebCore\platform\graphics\GLContext.cpp(169): error C3861: 'glGetIntegerv': identifier not found

cc-ing folks, who can be interested in fixing the WinCairo build.
Comment 13 Csaba Osztrogonác 2016-11-28 13:13:58 PST
(In reply to comment #10)
> Comment on attachment 295484 [details]
> Patch
> 
> Clearing flags on attachment: 295484
> 
> Committed r208997: <http://trac.webkit.org/changeset/208997>

And it broke performance testing, see https://build.webkit.org/builders/GTK%20Linux%2064-bit%20Release%20%28Perf%29/builds/7073 for details.
Comment 14 Miguel Gomez 2016-11-29 05:01:58 PST
If the WinCairo folks are interested in the added feature they can adapt the code. If not, I can add some platforms guards to avoid the build failure. Just tell me what you prefer.

Regarding the perf bot, I suspect it has the GLX_ARB_create_context extension, but it doesn't support OpenGL 3.2. From what I read, in this case glXCreateContextAttribsARB, besides returning a null context, can throw that GLXBadFBConfig error. That's not being checked in the patch.
Comment 15 Miguel Gomez 2016-12-01 06:53:04 PST
For the record, the perf bot failure is being handled in bug 165200.

Any comment about the WinCairo build issue? Should I just add the needed platform guards?
Comment 16 Michael Catanzaro 2016-12-01 07:04:57 PST
Yes, please add platform guards. It will probably be a while before anyone working on WinCairo tries to fix it otherwise.
Comment 17 Csaba Osztrogonác 2016-12-01 07:38:03 PST
Just out of curiosity, does WinCairo port have at least one full-time maintainer? 

There is a 3 day long build break and nobody has time/interest to comment it.
Why should the community maintain this port build if nobody cares about it?
(Who knows if it works at all? WinCairo port didn't have public tester bot ever.)
Comment 18 Michael Catanzaro 2016-12-01 08:32:18 PST
(In reply to comment #17)
> Just out of curiosity, does WinCairo port have at least one full-time
> maintainer? 

Of course not.

> There is a 3 day long build break and nobody has time/interest to comment it.
> Why should the community maintain this port build if nobody cares about it?
> (Who knows if it works at all? WinCairo port didn't have public tester bot
> ever.)

I really really do not want to suggest removing the WinCairo port, as it is the only way for non-Apple companies to use WebKit on Windows, but as none of the companies that depend on it seem to be interested in maintaining it... and especially since it is the only port without an EWS bot, so there's no way to know if we're breaking it or not... this should probably be discussed in webkit-dev@.
Comment 19 Alex Christensen 2016-12-01 15:23:30 PST
https://bugs.webkit.org/show_bug.cgi?id=165283
Comment 20 Alex Christensen 2016-12-01 15:24:22 PST
Ossy, some of us have been known to go on vacation for more than three days at a time.
Comment 21 Andres Gomez Garcia 2016-12-09 02:43:31 PST
Please, take a look to attachment 296649 [details]
Comment 22 Michael Catanzaro 2016-12-22 18:44:54 PST
(In reply to comment #17)
> Just out of curiosity, does WinCairo port have at least one full-time
> maintainer? 
> 
> There is a 3 day long build break and nobody has time/interest to comment it.
> Why should the community maintain this port build if nobody cares about it?
> (Who knows if it works at all? WinCairo port didn't have public tester bot
> ever.)

It also broke the GTK GLES build, nobody noticed for a month, see bug #166455. Guess we shouldn't be so hard on WinCairo. ;)

Carlos Lopez, do we have capacity to set up a GLES buildbot to check for this? Would anybody even notice if such a bot was broken, since it wouldn't be on EWS?
Comment 23 Carlos Alberto Lopez Perez 2016-12-23 04:57:37 PST
(In reply to comment #22)
> It also broke the GTK GLES build, nobody noticed for a month, see bug
> #166455. Guess we shouldn't be so hard on WinCairo. ;)
> 
> Carlos Lopez, do we have capacity to set up a GLES buildbot to check for
> this? 

I would like to set a bot that tries builds disabling/enabling options to see if some build configuration is broken.

Apart from that, setting an ARM buildbot with GLES can be a good idea.

> Would anybody even notice if such a bot was broken, since it wouldn't be on EWS?

They would notice after the fact, because the buildbot only tries already committed revisions.