Skip to content

Commit d67fbe5

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm, gc] Base the growth policy on usage instead of capacity.
With concurrent sweeping, the amount of capacity freed by a major GC is not known at the time growth is evaluated. This consistently biases the policy into growing more than it would with an accurate capacity from stop-the-world sweeping. This is more interesting for larger heaps and when there is a tighter memory limit. For a very large dart2js compile Max Heap Capacity: 13.057 -> 11.861 GB Compile Time: 545 -> 472 seconds For dart2js self-compile Max Heap Capacity: 1.343 -> 1.385 GB Compile Time: 43.4 -> 43.5 seconds Bug: dart-lang/sdk#21364 Change-Id: If047e22a9cd9da6b34c8e499a39fde97427a69b9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133660 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
1 parent fccae66 commit d67fbe5

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

runtime/vm/heap/pages.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ bool PageSpaceController::NeedsGarbageCollection(SpaceUsage after) const {
13871387
#else
13881388
intptr_t headroom = heap_->new_space()->CapacityInWords();
13891389
#endif
1390-
return after.CombinedCapacityInWords() > (gc_threshold_in_words_ + headroom);
1390+
return after.CombinedUsedInWords() > (gc_threshold_in_words_ + headroom);
13911391
}
13921392

13931393
bool PageSpaceController::AlmostNeedsGarbageCollection(SpaceUsage after) const {
@@ -1397,7 +1397,7 @@ bool PageSpaceController::AlmostNeedsGarbageCollection(SpaceUsage after) const {
13971397
if (heap_growth_ratio_ == 100) {
13981398
return false;
13991399
}
1400-
return after.CombinedCapacityInWords() > gc_threshold_in_words_;
1400+
return after.CombinedUsedInWords() > gc_threshold_in_words_;
14011401
}
14021402

14031403
bool PageSpaceController::NeedsIdleGarbageCollection(SpaceUsage current) const {
@@ -1407,7 +1407,7 @@ bool PageSpaceController::NeedsIdleGarbageCollection(SpaceUsage current) const {
14071407
if (heap_growth_ratio_ == 100) {
14081408
return false;
14091409
}
1410-
return current.CombinedCapacityInWords() > idle_gc_threshold_in_words_;
1410+
return current.CombinedUsedInWords() > idle_gc_threshold_in_words_;
14111411
}
14121412

14131413
void PageSpaceController::EvaluateGarbageCollection(SpaceUsage before,
@@ -1446,9 +1446,9 @@ void PageSpaceController::EvaluateGarbageCollection(SpaceUsage before,
14461446
// Number of pages we can allocate and still be within the desired growth
14471447
// ratio.
14481448
const intptr_t grow_pages =
1449-
(static_cast<intptr_t>(after.CombinedCapacityInWords() /
1449+
(static_cast<intptr_t>(after.CombinedUsedInWords() /
14501450
desired_utilization_) -
1451-
(after.CombinedCapacityInWords())) /
1451+
(after.CombinedUsedInWords())) /
14521452
kPageSizeInWords;
14531453
if (garbage_ratio == 0) {
14541454
// No garbage in the previous cycle so it would be hard to compute a
@@ -1464,8 +1464,8 @@ void PageSpaceController::EvaluateGarbageCollection(SpaceUsage before,
14641464
intptr_t local_grow_heap = 0;
14651465
while (min < max) {
14661466
local_grow_heap = (max + min) / 2;
1467-
const intptr_t limit = after.CombinedCapacityInWords() +
1468-
(local_grow_heap * kPageSizeInWords);
1467+
const intptr_t limit =
1468+
after.CombinedUsedInWords() + (local_grow_heap * kPageSizeInWords);
14691469
const intptr_t allocated_before_next_gc =
14701470
limit - (after.CombinedUsedInWords());
14711471
const double estimated_garbage = k * allocated_before_next_gc;
@@ -1492,19 +1492,19 @@ void PageSpaceController::EvaluateGarbageCollection(SpaceUsage before,
14921492

14931493
// Limit shrinkage: allow growth by at least half the pages freed by GC.
14941494
const intptr_t freed_pages =
1495-
(before.CombinedCapacityInWords() - after.CombinedCapacityInWords()) /
1495+
(before.CombinedUsedInWords() - after.CombinedUsedInWords()) /
14961496
kPageSizeInWords;
14971497
grow_heap = Utils::Maximum(grow_heap, freed_pages / 2);
14981498
heap_->RecordData(PageSpace::kAllowedGrowth, grow_heap);
14991499
last_usage_ = after;
15001500

15011501
// Save final threshold compared before growing.
15021502
gc_threshold_in_words_ =
1503-
after.CombinedCapacityInWords() + (kPageSizeInWords * grow_heap);
1503+
after.CombinedUsedInWords() + (kPageSizeInWords * grow_heap);
15041504

15051505
// Set a tight idle threshold.
15061506
idle_gc_threshold_in_words_ =
1507-
after.CombinedCapacityInWords() + 2 * kPageSizeInWords;
1507+
after.CombinedUsedInWords() + (2 * kPageSizeInWords);
15081508

15091509
RecordUpdate(before, after, "gc");
15101510
}
@@ -1513,9 +1513,9 @@ void PageSpaceController::EvaluateAfterLoading(SpaceUsage after) {
15131513
// Number of pages we can allocate and still be within the desired growth
15141514
// ratio.
15151515
intptr_t growth_in_pages =
1516-
(static_cast<intptr_t>(after.CombinedCapacityInWords() /
1516+
(static_cast<intptr_t>(after.CombinedUsedInWords() /
15171517
desired_utilization_) -
1518-
(after.CombinedCapacityInWords())) /
1518+
(after.CombinedUsedInWords())) /
15191519
kPageSizeInWords;
15201520

15211521
// Apply growth cap.
@@ -1524,11 +1524,11 @@ void PageSpaceController::EvaluateAfterLoading(SpaceUsage after) {
15241524

15251525
// Save final threshold compared before growing.
15261526
gc_threshold_in_words_ =
1527-
after.CombinedCapacityInWords() + (kPageSizeInWords * growth_in_pages);
1527+
after.CombinedUsedInWords() + (kPageSizeInWords * growth_in_pages);
15281528

15291529
// Set a tight idle threshold.
15301530
idle_gc_threshold_in_words_ =
1531-
after.CombinedCapacityInWords() + 2 * kPageSizeInWords;
1531+
after.CombinedUsedInWords() + (2 * kPageSizeInWords);
15321532

15331533
RecordUpdate(after, after, "loaded");
15341534
}
@@ -1540,10 +1540,10 @@ void PageSpaceController::RecordUpdate(SpaceUsage before,
15401540
TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), "UpdateGrowthLimit");
15411541
tbes.SetNumArguments(5);
15421542
tbes.CopyArgument(0, "Reason", reason);
1543-
tbes.FormatArgument(1, "Before.CombinedCapacity (kB)", "%" Pd "",
1544-
RoundWordsToKB(before.CombinedCapacityInWords()));
1545-
tbes.FormatArgument(2, "After.CombinedCapacity (kB)", "%" Pd "",
1546-
RoundWordsToKB(after.CombinedCapacityInWords()));
1543+
tbes.FormatArgument(1, "Before.CombinedUsed (kB)", "%" Pd "",
1544+
RoundWordsToKB(before.CombinedUsedInWords()));
1545+
tbes.FormatArgument(2, "After.CombinedUsed (kB)", "%" Pd "",
1546+
RoundWordsToKB(after.CombinedUsedInWords()));
15471547
tbes.FormatArgument(3, "Threshold (kB)", "%" Pd "",
15481548
RoundWordsToKB(gc_threshold_in_words_));
15491549
tbes.FormatArgument(4, "Idle Threshold (kB)", "%" Pd "",

0 commit comments

Comments
 (0)