Skip to content

Commit 5737b45

Browse files
aamcommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
[vm/gc] Update initial TLAB size calculation.
First TLAB size is adjusted to account for the new space survivors. Change-Id: I6eb4305a14c00173626069b66b01906f8ba49612 Reviewed-on: https://dart-review.googlesource.com/c/91703 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Aprelev <aam@google.com>
1 parent 37a1f79 commit 5737b45

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

runtime/vm/heap/heap.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ uword Heap::AllocateNew(intptr_t size) {
9191
return addr;
9292
}
9393

94-
intptr_t tlab_size = CalculateTLABSize();
94+
intptr_t tlab_size = GetTLABSize();
9595
if ((tlab_size > 0) && (size > tlab_size)) {
9696
return AllocateOld(size, HeapPage::kData);
9797
}
@@ -101,8 +101,11 @@ uword Heap::AllocateNew(intptr_t size) {
101101
uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
102102
if (tlab_top != 0) {
103103
addr = new_space_.TryAllocateInTLAB(thread, size);
104-
ASSERT(addr != 0);
105-
return addr;
104+
if (addr != 0) { // but "leftover" TLAB could end smaller than tlab_size
105+
return addr;
106+
}
107+
// Abandon "leftover" TLAB as well so we can start from scratch.
108+
AbandonRemainingTLAB(thread);
106109
}
107110
}
108111

@@ -112,7 +115,7 @@ uword Heap::AllocateNew(intptr_t size) {
112115
// from a different thread and will be racing to allocate the requested
113116
// memory with other threads being released after the collection.
114117
CollectGarbage(kNew);
115-
tlab_size = CalculateTLABSize();
118+
116119
uword tlab_top = new_space_.TryAllocateNewTLAB(thread, tlab_size);
117120
if (tlab_top != 0) {
118121
addr = new_space_.TryAllocateInTLAB(thread, size);

runtime/vm/heap/heap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class Heap {
285285

286286
static const intptr_t kNewAllocatableSize = 256 * KB;
287287

288-
intptr_t CalculateTLABSize() {
288+
intptr_t GetTLABSize() {
289289
// Inspired by V8 tlab size. More than threshold for old space allocation,
290290
// less then minimal(initial) new semi-space.
291291
const intptr_t size = 512 * KB;

runtime/vm/heap/scavenger.cc

+9
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,15 @@ uword Scavenger::TryAllocateNewTLAB(Thread* thread, intptr_t size) {
926926
uword result = top_;
927927
intptr_t remaining = end_ - top_;
928928
if (remaining < size) {
929+
// Grab whatever is remaining
930+
size = remaining;
931+
} else {
932+
// Reduce TLAB size so we land at even TLAB size for future TLABs.
933+
intptr_t survived_size = UsedInWords() * kWordSize;
934+
size -= survived_size % size;
935+
}
936+
size = Utils::RoundDown(size, kObjectAlignment);
937+
if (size == 0) {
929938
return 0;
930939
}
931940
ASSERT(to_->Contains(result));

0 commit comments

Comments
 (0)