Bug 128261

Summary: GC timer should intelligently choose between EdenCollections and FullCollections
Product: WebKit Reporter: Mark Hahnenberg <mhahnenberg>
Component: JavaScriptCoreAssignee: Mark Hahnenberg <mhahnenberg>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, bunhere, commit-queue, gyuyoung.kim, rakuco, sergio, webkit-ews
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 130488    
Bug Blocks:    
Attachments:
Description Flags
straw man
none
straw man 2
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch ggaren: review+

Description Mark Hahnenberg 2014-02-05 10:58:03 PST
Most of the GCs while browsing the web are due to the GC timer. Currently the GC timer always does FullCollections. To reduce the impact of the GC timer on the system we should add some logic to intelligently schedule both EdenCollections and FullCollections.
Comment 1 Mark Hahnenberg 2014-03-13 10:53:46 PDT
Created attachment 226599 [details]
straw man
Comment 2 Early Warning System Bot 2014-03-13 10:55:15 PDT
Attachment 226599 [details] did not pass style-queue:


ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Mark Hahnenberg 2014-03-13 11:07:54 PDT
Created attachment 226600 [details]
straw man 2
Comment 4 Geoffrey Garen 2014-03-13 12:28:34 PDT
Comment on attachment 226600 [details]
straw man 2

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

r=me

Please test PLT before landing this.

Plus a few fixups below.

> Source/JavaScriptCore/heap/GCActivityCallback.cpp:-97
>      if (heap->isPagedOut(startTime + pagingTimeOut)) {
> -        heap->activityCallback()->cancel();

EdenCollection probably should not do the isPagedOut check.

I think isPagedOut touches the whole heap, so that's not great for Eden.

Also, EdenCollection is more likely to find free space than FullCollection, so I think it should be less conservative about whether collection is "worth it".

> Source/JavaScriptCore/heap/GCActivityCallback.cpp:112
> +    heap->setShouldDoFullCollection(true);
>      heap->collect();

I think it would be a slightly better abstraction to pass a collection type to collect(), rather than setting a data member. Perhaps the Heap implements things internally in terms of a data member, but clients need not know that detail.

> Source/JavaScriptCore/heap/Heap.cpp:281
> +    , m_fullActivityCallback(GCActivityCallback::createFullTimer(this))
> +    , m_edenActivityCallback(GCActivityCallback::createEdenTimer(this))

If GenGC is disabled, both pointers should point to the same callback, and it should be a full callback. That way, we can still A/B test GenGC on vs off.

> Source/JavaScriptCore/heap/Heap.cpp:340
> -    if (m_activityCallback)
> -        m_activityCallback->didAllocate(m_bytesAllocatedThisCycle + m_bytesAbandonedThisCycle);
> +    if (m_fullActivityCallback)
> +        m_fullActivityCallback->didAllocate(m_sizeAfterLastCollect + m_bytesAbandonedThisCycle);

This is pretty aggro. The first abandoned object graph reports that it abandoned the whole heap! I think you want this instead:

    m_sizeAfterLastCollect - m_sizeAfterLastFullCollect + m_bytesAllocatedThisCycle + m_bytesAbandonedThisCycle

That way, we only report our growth since the last full collect. 

Also: You should rename m_bytesAbandonedThisCycle to m_bytesAbandonedSinceLastFullCollect, and change it so that it only resets to 0 during a full collect. Our theory of abandoned object graphs is that they should hasten full collections, so we should not reset the abandoned counter during eden collections.

For example, if I navigate between three websites, and do three eden collections, I still want to do a full collection soon.
Comment 5 Mark Hahnenberg 2014-03-18 12:29:01 PDT
Created attachment 227087 [details]
Patch
Comment 6 Mark Hahnenberg 2014-03-18 14:26:09 PDT
Created attachment 227107 [details]
Patch
Comment 7 Mark Hahnenberg 2014-03-18 14:49:45 PDT
Created attachment 227114 [details]
Patch
Comment 8 Mark Hahnenberg 2014-03-18 15:06:46 PDT
Created attachment 227117 [details]
Patch
Comment 9 Mark Hahnenberg 2014-03-18 16:04:53 PDT
Created attachment 227125 [details]
Patch
Comment 10 Mark Hahnenberg 2014-03-18 16:24:01 PDT
Created attachment 227128 [details]
Patch
Comment 11 Mark Hahnenberg 2014-03-18 17:48:08 PDT
Created attachment 227138 [details]
Patch
Comment 12 Mark Hahnenberg 2014-03-18 18:37:56 PDT
Created attachment 227142 [details]
Patch
Comment 13 Geoffrey Garen 2014-03-19 13:30:58 PDT
Comment on attachment 227142 [details]
Patch

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

r=me

> Source/JavaScriptCore/heap/EdenGCActivityCallback.cpp:57
> +    return double(sizeBefore - sizeAfter) / double(sizeBefore);

static_cast<double> is more our style.
Comment 14 Mark Hahnenberg 2014-03-19 15:22:22 PDT
Committed r165926: <http://trac.webkit.org/changeset/165926>
Comment 15 WebKit Commit Bot 2014-03-19 17:15:53 PDT
Re-opened since this is blocked by bug 130488
Comment 16 Andy Estes 2014-03-19 17:19:58 PDT
This broke linking WebCore on iOS:

Undefined symbols for architecture x86_64:
  "__ZN3JSC22FullGCActivityCallback12doCollectionEv", referenced from:
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22FullGCActivityCallback11gcTimeSliceEm", referenced from:
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC18GCActivityCallback11willCollectEv", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22FullGCActivityCallback12lastGCLengthEv", referenced from:
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22FullGCActivityCallback9deathRateEv", referenced from:
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "_wkQueryDecoderAvailability", referenced from:
     -exported_symbol[s_list] command line option
  "__ZN3JSC18GCActivityCallback6doWorkEv", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22EdenGCActivityCallback12doCollectionEv", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC18GCActivityCallback6cancelEv", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22EdenGCActivityCallback9deathRateEv", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC18GCActivityCallback11didAllocateEm", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
      __ZTVN7WebCore29WebSafeFullGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22EdenGCActivityCallback12lastGCLengthEv", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
  "__ZN3JSC22EdenGCActivityCallback11gcTimeSliceEm", referenced from:
      __ZTVN7WebCore29WebSafeEdenGCActivityCallbackE in JSDOMWindowBase.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 17 Mark Hahnenberg 2014-03-19 18:56:54 PDT
Committed r165940: <http://trac.webkit.org/changeset/165940>