Commit 7826afea authored by Jon Coppeard's avatar Jon Coppeard
Browse files

Bug 1569560 - Add tuning parameters for new malloc counter r=sfink

This adds two new parameters.  The growth fator is set to 1.5 and the base to 42MB.  Trail and error showed that this latter value ended up triggering GCs roughtly in line with the old malloc counter.  These values make the initial malloc threshold ~64MB.

Differential Revision: https://phabricator.services.mozilla.com/D39730

--HG--
extra : moz-landing-system : lando
parent eb901df8
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -330,7 +330,7 @@ typedef enum JSGCParamKey {
   */
  JSGC_MIN_NURSERY_BYTES = 31,

  /*
  /**
   * The minimum time to allow between triggering last ditch GCs in seconds.
   *
   * Default: 60 seconds
@@ -338,7 +338,7 @@ typedef enum JSGCParamKey {
   */
  JSGC_MIN_LAST_DITCH_GC_PERIOD = 32,

  /*
  /**
   * The delay (in heapsize kilobytes) between slices of an incremental GC.
   *
   * Default: ZoneAllocDelayBytes
@@ -351,6 +351,20 @@ typedef enum JSGCParamKey {
   * read-only.
   */
  JSGC_NURSERY_BYTES = 34,

  /**
   * Retained size base value for calculating malloc heap threshold.
   *
   * Default: MallocThresholdBase
   */
  JSGC_MALLOC_THRESHOLD_BASE = 35,

  /**
   * Growth factor for calculating malloc heap threshold.
   *
   * Default: MallocGrowthFactor
   */
  JSGC_MALLOC_GROWTH_FACTOR = 36,
} JSGCParamKey;

/*
+3 −1
Original line number Diff line number Diff line
@@ -527,7 +527,9 @@ static bool MinorGC(JSContext* cx, unsigned argc, Value* vp) {
    JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION_PERCENT, true)           \
  _("pretenureThreshold", JSGC_PRETENURE_THRESHOLD, true)                    \
  _("pretenureGroupThreshold", JSGC_PRETENURE_GROUP_THRESHOLD, true)         \
  _("zoneAllocDelayKB", JSGC_ZONE_ALLOC_DELAY_KB, true)
  _("zoneAllocDelayKB", JSGC_ZONE_ALLOC_DELAY_KB, true)                      \
  _("mallocThresholdBase", JSGC_MALLOC_THRESHOLD_BASE, true)                 \
  _("mallocGrowthFactor", JSGC_MALLOC_GROWTH_FACTOR, true)

static const struct ParamInfo {
  const char* name;
+32 −4
Original line number Diff line number Diff line
@@ -370,6 +370,12 @@ static const float PretenureGroupThreshold = 3000;
/* JSGC_MIN_LAST_DITCH_GC_PERIOD */
static const auto MinLastDitchGCPeriod = 60;  // in seconds

/* JSGC_MALLOC_THRESHOLD_BASE */
static const size_t MallocThresholdBase = 42 * 1024 * 1024;

/* JSGC_MALLOC_GROWTH_FACTOR */
static const float MallocGrowthFactor = 1.5f;

}  // namespace TuningDefaults
}  // namespace gc
}  // namespace js
@@ -1603,6 +1609,17 @@ bool GCSchedulingTunables::setParameter(JSGCParamKey key, uint32_t value,
    case JSGC_ZONE_ALLOC_DELAY_KB:
      zoneAllocDelayBytes_ = value * 1024;
      break;
    case JSGC_MALLOC_THRESHOLD_BASE:
      mallocThresholdBase_ = value * 1024 * 1024;
      break;
    case JSGC_MALLOC_GROWTH_FACTOR: {
      float newGrowth = value / 100.0f;
      if (newGrowth < MinHeapGrowthFactor || newGrowth > MaxHeapGrowthFactor) {
        return false;
      }
      mallocGrowthFactor_ = newGrowth;
      break;
    }
    default:
      MOZ_CRASH("Unknown GC parameter.");
  }
@@ -1697,7 +1714,9 @@ GCSchedulingTunables::GCSchedulingTunables()
      pretenureThreshold_(TuningDefaults::PretenureThreshold),
      pretenureGroupThreshold_(TuningDefaults::PretenureGroupThreshold),
      minLastDitchGCPeriod_(
          TimeDuration::FromSeconds(TuningDefaults::MinLastDitchGCPeriod)) {}
          TimeDuration::FromSeconds(TuningDefaults::MinLastDitchGCPeriod)),
      mallocThresholdBase_(TuningDefaults::MallocThresholdBase),
      mallocGrowthFactor_(TuningDefaults::MallocGrowthFactor) {}

void GCRuntime::resetParameter(JSGCParamKey key, AutoLockGC& lock) {
  MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt));
@@ -1797,8 +1816,11 @@ void GCSchedulingTunables::resetParameter(JSGCParamKey key,
      minLastDitchGCPeriod_ =
          TimeDuration::FromSeconds(TuningDefaults::MinLastDitchGCPeriod);
      break;
    case JSGC_ZONE_ALLOC_DELAY_KB:
      zoneAllocDelayBytes_ = TuningDefaults::ZoneAllocDelayBytes;
    case JSGC_MALLOC_THRESHOLD_BASE:
      mallocThresholdBase_ = TuningDefaults::MallocThresholdBase;
      break;
    case JSGC_MALLOC_GROWTH_FACTOR:
      mallocGrowthFactor_ = TuningDefaults::MallocGrowthFactor;
      break;
    default:
      MOZ_CRASH("Unknown GC parameter.");
@@ -1881,6 +1903,10 @@ uint32_t GCRuntime::getParameter(JSGCParamKey key, const AutoLockGC& lock) {
      return tunables.minLastDitchGCPeriod().ToSeconds();
    case JSGC_ZONE_ALLOC_DELAY_KB:
      return tunables.zoneAllocDelayBytes() / 1024;
    case JSGC_MALLOC_THRESHOLD_BASE:
      return tunables.mallocThresholdBase() / 1024 / 1024;
    case JSGC_MALLOC_GROWTH_FACTOR:
      return uint32_t(tunables.mallocGrowthFactor() * 100);
    default:
      MOZ_CRASH("Unknown parameter key");
  }
@@ -2164,8 +2190,10 @@ size_t ZoneMallocThreshold::computeZoneTriggerBytes(float growthFactor,
}

void ZoneMallocThreshold::updateAfterGC(size_t lastBytes, size_t baseBytes,
                                        float growthFactor,
                                        const AutoLockGC& lock) {
  gcTriggerBytes_ = computeZoneTriggerBytes(2.0, lastBytes, baseBytes, lock);
  gcTriggerBytes_ =
      computeZoneTriggerBytes(growthFactor, lastBytes, baseBytes, lock);
}

MemoryCounter::MemoryCounter()
+18 −1
Original line number Diff line number Diff line
@@ -475,6 +475,20 @@ class GCSchedulingTunables {
   */
  MainThreadData<mozilla::TimeDuration> minLastDitchGCPeriod_;

  /*
   * JSGC_MALLOC_THRESHOLD_BASE
   *
   * The base value used to compute the GC trigger for malloc allocated memory.
   */
  MainThreadOrGCTaskData<size_t> mallocThresholdBase_;

  /*
   * JSGC_MALLOC_GROWTH_FACTOR
   *
   * Malloc memory growth factor.
   */
  MainThreadOrGCTaskData<float> mallocGrowthFactor_;

 public:
  GCSchedulingTunables();

@@ -525,6 +539,9 @@ class GCSchedulingTunables {
    return minLastDitchGCPeriod_;
  }

  size_t mallocThresholdBase() const { return mallocThresholdBase_; }
  float mallocGrowthFactor() const { return mallocGrowthFactor_; }

  MOZ_MUST_USE bool setParameter(JSGCParamKey key, uint32_t value,
                                 const AutoLockGC& lock);
  void resetParameter(JSGCParamKey key, const AutoLockGC& lock);
@@ -729,7 +746,7 @@ class ZoneHeapThreshold : public ZoneThreshold {
// GC based on malloc data.
class ZoneMallocThreshold : public ZoneThreshold {
 public:
  void updateAfterGC(size_t lastBytes, size_t baseBytes,
  void updateAfterGC(size_t lastBytes, size_t baseBytes, float growthFactor,
                     const AutoLockGC& lock);

 private:
+2 −1
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ void js::ZoneAllocator::updateGCThresholds(GCRuntime& gc,
  threshold.updateAfterGC(zoneSize.retainedBytes(), invocationKind, gc.tunables,
                          gc.schedulingState, lock);
  gcMallocThreshold.updateAfterGC(gcMallocBytes.retainedBytes(),
                                  gc.tunables.maxMallocBytes(), lock);
                                  gc.tunables.mallocThresholdBase(),
                                  gc.tunables.mallocGrowthFactor(), lock);
}

js::gc::TriggerKind js::ZoneAllocator::shouldTriggerGCForTooMuchMalloc() {
Loading