Ignore:
Timestamp:
May 22, 2012, 12:17:57 PM (13 years ago)
Author:
[email protected]
Message:

GC allocation trigger should be tuned to system RAM
https://bugs.webkit.org/show_bug.cgi?id=87039

Reviewed by Darin Adler.

../JavaScriptCore:

This helps avoid OOM crashes on small platforms, and helps avoid "too much GC"
performance issues on big platforms.

  • heap/Heap.cpp:

(JSC::Heap::Heap):
(JSC::Heap::collect):

  • heap/Heap.h:

(Heap): GC balances between a fixed minimum and a proportional multiplier,
which are limited based on system RAM.

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::createContextGroup):
(JSC::JSGlobalData::create):
(JSC::JSGlobalData::createLeaked):

  • runtime/JSGlobalData.h:

(JSGlobalData): Renamed HeapSize to HeapType because the exact size is
influenced by the heap type, but not determined by it.

../WTF:

Added a helper function for measuring system RAM.

  • GNUmakefile.list.am:
  • WTF.gypi:
  • WTF.pro:
  • WTF.vcproj/WTF.vcproj:
  • WTF.xcodeproj/project.pbxproj:
  • wtf/AmountOfRAM.cpp: Added.

(WTF):
(WTF::computeAmountOfRAM):
(WTF::amountOfRAM):

  • wtf/AmountOfRAM.h: Added.

(WTF):

  • wtf/CMakeLists.txt:
  • wtf/StdLibExtras.h:

(WTF):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r117729 r118019  
    3636#include "WeakSetInlines.h"
    3737#include <algorithm>
     38#include <wtf/RAMSize.h>
    3839#include <wtf/CurrentTime.h>
    39 
    4040
    4141using namespace std;
     
    4646namespace {
    4747
    48 #if CPU(X86) || CPU(X86_64)
    49 static const size_t largeHeapSize = 16 * 1024 * 1024;
    50 #elif PLATFORM(IOS)
    51 static const size_t largeHeapSize = 8 * 1024 * 1024;
    52 #else
    53 static const size_t largeHeapSize = 512 * 1024;
    54 #endif
    55 static const size_t smallHeapSize = 512 * 1024;
     48static const size_t largeHeapSize = 32 * MB; // About 1.5X the average webpage.
     49static const size_t smallHeapSize = 1 * MB; // Matches the FastMalloc per-thread cache.
    5650
    5751#if ENABLE(GC_LOGGING)
     
    149143#endif
    150144
    151 static size_t heapSizeForHint(HeapSize heapSize)
    152 {
    153     if (heapSize == LargeHeap)
    154         return largeHeapSize;
    155     ASSERT(heapSize == SmallHeap);
     145static inline size_t minHeapSize(HeapType heapType, size_t ramSize)
     146{
     147    if (heapType == LargeHeap)
     148        return min(largeHeapSize, ramSize / 4);
    156149    return smallHeapSize;
     150}
     151
     152static inline size_t proportionalHeapSize(size_t heapSize, size_t ramSize)
     153{
     154    // Try to stay under 1/2 RAM size to leave room for the DOM, rendering, networking, etc.
     155    if (heapSize < ramSize / 4)
     156        return 2 * heapSize;
     157    if (heapSize < ramSize / 2)
     158        return 1.5 * heapSize;
     159    return 1.25 * heapSize;
    157160}
    158161
     
    231234} // anonymous namespace
    232235
    233 Heap::Heap(JSGlobalData* globalData, HeapSize heapSize)
    234     : m_heapSize(heapSize)
    235     , m_minBytesPerCycle(heapSizeForHint(heapSize))
     236Heap::Heap(JSGlobalData* globalData, HeapType heapType)
     237    : m_heapType(heapType)
     238    , m_ramSize(ramSize())
     239    , m_minBytesPerCycle(minHeapSize(m_heapType, m_ramSize))
    236240    , m_sizeAfterLastCollect(0)
    237241    , m_bytesAllocatedLimit(m_minBytesPerCycle)
     
    723727    }
    724728
    725     // To avoid pathological GC churn in large heaps, we set the new allocation
    726     // limit to be the current size of the heap. This heuristic
    727     // is a bit arbitrary. Using the current size of the heap after this
    728     // collection gives us a 2X multiplier, which is a 1:1 (heap size :
    729     // new bytes allocated) proportion, and seems to work well in benchmarks.
    730     size_t newSize = size();
     729    size_t currentHeapSize = size();
    731730    if (fullGC) {
    732         m_sizeAfterLastCollect = newSize;
    733         m_bytesAllocatedLimit = max(newSize, m_minBytesPerCycle);
     731        m_sizeAfterLastCollect = currentHeapSize;
     732
     733        // To avoid pathological GC churn in very small and very large heaps, we set
     734        // the new allocation limit based on the current size of the heap, with a
     735        // fixed minimum.
     736        size_t maxHeapSize = max(minHeapSize(m_heapType, m_ramSize), proportionalHeapSize(currentHeapSize, m_ramSize));
     737        m_bytesAllocatedLimit = maxHeapSize - currentHeapSize;
    734738    }
    735739    m_bytesAllocated = 0;
Note: See TracChangeset for help on using the changeset viewer.