Bug 145672 - [WK2][iOS] Limit the number of vnodes used by the WebContent processes
Summary: [WK2][iOS] Limit the number of vnodes used by the WebContent processes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-06-04 16:20 PDT by Chris Dumez
Modified: 2015-06-06 17:47 PDT (History)
10 users (show)

See Also:


Attachments
Patch (23.57 KB, patch)
2015-06-04 22:02 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (25.26 KB, patch)
2015-06-05 10:23 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 2015-06-04 16:20:02 PDT
Limit the number of VNodes used by the WebContent processes to reduce the chance of getting killed due to running out of VNodes.

We sometimes see the WebContent process use up to 50% of the system's vnode-limit on some tests, which seems excessive. Most VNodes are due to CachedResources which are mmap'd from the WebKit disk cache and kept alive due to caches such as the Memory Cache / PageCache.

Radar: <rdar://problem/21126637>
Comment 1 Chris Dumez 2015-06-04 22:02:38 PDT
Created attachment 254341 [details]
Patch
Comment 2 Antti Koivisto 2015-06-05 06:13:55 PDT
Comment on attachment 254341 [details]
Patch

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

> Source/WebCore/platform/VNodeTracker.cpp:68
> +    Critical critical = vnodeCount > m_hardVNodeLimit ? Critical::Yes : Critical::No;

Bit suprising that we have type named Critical in WebCore global namespace.

Could just say auto.

> Source/WebCore/platform/VNodeTracker.cpp:76
> +    static const std::chrono::duration<double> minimumWarningInterval = std::chrono::seconds { 30 };

Why std::chrono::duration<double>? auto should work fine.

> Source/WebCore/platform/VNodeTracker.h:37
> +typedef std::function<void(Critical)> VNodePressureHandler;

Maybe move this to VNodeTracker namespace as well. (as VNodeTracker::PressureHandler)

> Source/WebCore/platform/VNodeTracker.h:43
> +    enum VNodeTokenType { };
> +    typedef RefCounter::Token<VNodeTokenType> VNodeToken;

These could be just TokenType and Token. "VNode" is redundant in VNodeTracker scope.

> Source/WebCore/platform/VNodeTracker.h:48
> +    void setVNodePressureHandler(VNodePressureHandler);
> +    VNodeToken vnodeToken();

Redudand vnodes in function names.

> Source/WebCore/platform/cf/SharedBufferCF.cpp:40
>  SharedBuffer::SharedBuffer(CFDataRef cfData)
>      : m_buffer(adoptRef(new DataBuffer))
>      , m_cfData(cfData)
> +    , m_vnodeToken(VNodeTracker::singleton().vnodeToken())
>  {
>  }

Do all clients for this actually use file backed buffers?

> Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm:197
> +#if PLATFORM(IOS)
> +    // Track the number of vnodes we are using on iOS and make sure we only use a
> +    // reasonable amount because limits are fairly low on iOS devices and we can
> +    // get killed when reaching the limit.
> +    VNodeTracker::singleton().setVNodePressureHandler([] (Critical critical) {
> +        MemoryPressureHandler::singleton().releaseMemory(critical);
> +    });
> +#endif

Could just wipe out resources actually using vnodes. But I suppose this is fine.
Comment 3 Chris Dumez 2015-06-05 10:04:25 PDT
Comment on attachment 254341 [details]
Patch

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

>> Source/WebCore/platform/cf/SharedBufferCF.cpp:40
>>  }
> 
> Do all clients for this actually use file backed buffers?

Not all of them but most of them (especially the ones that are long-lived). We likely overestimate the number of vnodes a bit but I think this is a good enough estimation. We could add an "isFileBacked" argument so that the client could provide the information but I am not convinced it is worth the extra complexity.
Comment 4 Chris Dumez 2015-06-05 10:23:42 PDT
Created attachment 254361 [details]
Patch
Comment 5 WebKit Commit Bot 2015-06-05 16:20:35 PDT
Comment on attachment 254361 [details]
Patch

Clearing flags on attachment: 254361

Committed r185273: <http://trac.webkit.org/changeset/185273>
Comment 6 WebKit Commit Bot 2015-06-05 16:20:51 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Chris Dumez 2015-06-06 17:47:09 PDT
(In reply to comment #7)
> This patch broke
> https://build.webkit.org/builders/
> Apple%20Mavericks%20Debug%20WK2%20%28Tests%29/builds/12260/steps/run-api-
> tests/logs/stdio
> 
> Fixed here: https://trac.webkit.org/changeset/185285

Thanks Zalan!