5 #include "src/heap/heap-controller.h" 6 #include "src/isolate-inl.h" 50 double MemoryController::GrowingFactor(
double gc_speed,
double mutator_speed,
52 DCHECK_LE(min_growing_factor_, max_factor);
53 DCHECK_GE(max_growing_factor_, max_factor);
54 if (gc_speed == 0 || mutator_speed == 0)
return max_factor;
56 const double speed_ratio = gc_speed / mutator_speed;
58 const double a = speed_ratio * (1 - target_mutator_utilization_);
59 const double b = speed_ratio * (1 - target_mutator_utilization_) -
60 target_mutator_utilization_;
63 double factor = (a < b * max_factor) ? a / b : max_factor;
64 factor = Min(factor, max_factor);
65 factor = Max(factor, min_growing_factor_);
69 size_t MemoryController::CalculateAllocationLimit(
70 size_t curr_size,
size_t max_size,
double max_factor,
double gc_speed,
71 double mutator_speed,
size_t new_space_capacity,
72 Heap::HeapGrowingMode growing_mode) {
73 double factor = GrowingFactor(gc_speed, mutator_speed, max_factor);
75 if (FLAG_trace_gc_verbose) {
76 heap_->isolate()->PrintWithTimestamp(
77 "%s factor %.1f based on mu=%.3f, speed_ratio=%.f " 78 "(gc=%.f, mutator=%.f)\n",
79 ControllerName(), factor, target_mutator_utilization_,
80 gc_speed / mutator_speed, gc_speed, mutator_speed);
83 if (growing_mode == Heap::HeapGrowingMode::kConservative ||
84 growing_mode == Heap::HeapGrowingMode::kSlow) {
85 factor = Min(factor, conservative_growing_factor_);
88 if (growing_mode == Heap::HeapGrowingMode::kMinimal) {
89 factor = min_growing_factor_;
92 if (FLAG_heap_growing_percent > 0) {
93 factor = 1.0 + FLAG_heap_growing_percent / 100.0;
96 CHECK_LT(1.0, factor);
97 CHECK_LT(0, curr_size);
98 uint64_t limit =
static_cast<uint64_t
>(curr_size * factor);
99 limit = Max(limit, static_cast<uint64_t>(curr_size) +
100 MinimumAllocationLimitGrowingStep(growing_mode));
101 limit += new_space_capacity;
102 uint64_t halfway_to_the_max =
103 (
static_cast<uint64_t
>(curr_size) + max_size) / 2;
104 size_t result =
static_cast<size_t>(Min(limit, halfway_to_the_max));
106 if (FLAG_trace_gc_verbose) {
107 heap_->isolate()->PrintWithTimestamp(
108 "%s Limit: old size: %" PRIuS
" KB, new limit: %" PRIuS
" KB (%.1f)\n",
109 ControllerName(), curr_size / KB, result / KB, factor);
115 size_t MemoryController::MinimumAllocationLimitGrowingStep(
116 Heap::HeapGrowingMode growing_mode) {
117 const size_t kRegularAllocationLimitGrowingStep = 8;
118 const size_t kLowMemoryAllocationLimitGrowingStep = 2;
119 size_t limit = (Page::kPageSize > MB ? Page::kPageSize : MB);
120 return limit * (growing_mode == Heap::HeapGrowingMode::kConservative
121 ? kLowMemoryAllocationLimitGrowingStep
122 : kRegularAllocationLimitGrowingStep);
125 double HeapController::MaxGrowingFactor(
size_t curr_max_size) {
126 const double min_small_factor = 1.3;
127 const double max_small_factor = 2.0;
128 const double high_factor = 4.0;
130 size_t max_size_in_mb = curr_max_size / MB;
131 max_size_in_mb = Max(max_size_in_mb, kMinSize);
135 if (max_size_in_mb >= kMaxSize) {
139 DCHECK_GE(max_size_in_mb, kMinSize);
140 DCHECK_LT(max_size_in_mb, kMaxSize);
143 double factor = (max_size_in_mb - kMinSize) *
144 (max_small_factor - min_small_factor) /
145 (kMaxSize - kMinSize) +