Skip to content

Commit 2e4107c

Browse files
rmacnak-googleCommit Bot
authored and
Commit Bot
committed
[vm, gc] Apply incremental marking back-pressure in proportion to internal allocation size.
In particular, do not apply incremental marking back-pressure for external allocations. External allocations do not cause additional marking work. If a mutator thread performs a storm of external allocations, this should not cause it to effectively become a marking thread. TEST=ci Bug: #47492 Bug: flutter/flutter#106305 Change-Id: Icace57e73d695143f7e295924b61b9b1c04be121 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249403 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent d6215b7 commit 2e4107c

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

runtime/vm/heap/heap.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void Heap::CheckExternalGC(Thread* thread) {
193193
}
194194
CollectGarbage(thread, GCType::kMarkSweep, GCReason::kExternal);
195195
} else {
196-
CheckConcurrentMarking(thread, GCReason::kExternal);
196+
CheckConcurrentMarking(thread, GCReason::kExternal, 0);
197197
}
198198
}
199199

@@ -459,7 +459,7 @@ void Heap::CollectNewSpaceGarbage(Thread* thread,
459459
CollectOldSpaceGarbage(thread, GCType::kMarkSweep,
460460
GCReason::kPromotion);
461461
} else {
462-
CheckConcurrentMarking(thread, GCReason::kPromotion);
462+
CheckConcurrentMarking(thread, GCReason::kPromotion, 0);
463463
}
464464
}
465465
}
@@ -561,7 +561,9 @@ void Heap::CollectAllGarbage(GCReason reason, bool compact) {
561561
WaitForSweeperTasks(thread);
562562
}
563563

564-
void Heap::CheckConcurrentMarking(Thread* thread, GCReason reason) {
564+
void Heap::CheckConcurrentMarking(Thread* thread,
565+
GCReason reason,
566+
intptr_t size) {
565567
PageSpace::Phase phase;
566568
{
567569
MonitorLocker ml(old_space_.tasks_lock());
@@ -570,11 +572,9 @@ void Heap::CheckConcurrentMarking(Thread* thread, GCReason reason) {
570572

571573
switch (phase) {
572574
case PageSpace::kMarking:
573-
// TODO(rmacnak): Make the allocator of a large page mark size equals to
574-
// the large page?
575-
COMPILE_ASSERT(kOldPageSize == 512 * KB);
576-
COMPILE_ASSERT(kNewPageSize == 512 * KB);
577-
old_space_.IncrementalMarkWithSizeBudget(512 * KB);
575+
if (size != 0) {
576+
old_space_.IncrementalMarkWithSizeBudget(size);
577+
}
578578
return;
579579
case PageSpace::kSweepingLarge:
580580
case PageSpace::kSweepingRegular:

runtime/vm/heap/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Heap {
125125
void CollectAllGarbage(GCReason reason = GCReason::kFull,
126126
bool compact = false);
127127

128-
void CheckConcurrentMarking(Thread* thread, GCReason reason);
128+
void CheckConcurrentMarking(Thread* thread, GCReason reason, intptr_t size);
129129
void StartConcurrentMarking(Thread* thread, GCReason reason);
130130
void WaitForMarkerTasks(Thread* thread);
131131
void WaitForSweeperTasks(Thread* thread);

runtime/vm/heap/pages.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ uword PageSpace::TryAllocateInFreshPage(intptr_t size,
473473
if (growth_policy != kForceGrowth) {
474474
ASSERT(GrowthControlState());
475475
if (heap_ != nullptr) { // Some unit tests.
476-
heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace);
476+
heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace,
477+
kOldPageSize);
477478
}
478479
}
479480

@@ -514,7 +515,8 @@ uword PageSpace::TryAllocateInFreshLargePage(intptr_t size,
514515
if (growth_policy != kForceGrowth) {
515516
ASSERT(GrowthControlState());
516517
if (heap_ != nullptr) { // Some unit tests.
517-
heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace);
518+
heap_->CheckConcurrentMarking(Thread::Current(), GCReason::kOldSpace,
519+
size);
518520
}
519521
}
520522

runtime/vm/heap/safepoint.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ForceGrowthSafepointOperationScope::~ForceGrowthSafepointOperationScope() {
6565
if (heap->old_space()->ReachedHardThreshold()) {
6666
heap->CollectGarbage(T, GCType::kMarkSweep, GCReason::kOldSpace);
6767
} else {
68-
heap->CheckConcurrentMarking(T, GCReason::kOldSpace);
68+
heap->CheckConcurrentMarking(T, GCReason::kOldSpace, 0);
6969
}
7070
}
7171
}

runtime/vm/heap/scavenger.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ void Scavenger::TryAllocateNewTLAB(Thread* thread,
16801680

16811681
if (can_safepoint) {
16821682
ASSERT(thread->no_safepoint_scope_depth() == 0);
1683-
heap_->CheckConcurrentMarking(thread, GCReason::kNewSpace);
1683+
heap_->CheckConcurrentMarking(thread, GCReason::kNewSpace, kNewPageSize);
16841684
}
16851685

16861686
MutexLocker ml(&space_lock_);

0 commit comments

Comments
 (0)